Skip to content
Snippets Groups Projects
Commit 2ccb2a7c authored by Piotr Gawron's avatar Piotr Gawron
Browse files

plugin structure contains column for publicly availbale plugins

parent 6eb5553e
No related branches found
No related tags found
2 merge requests!630WIP: Resolve "The privileges of a new user are not saved in some cases",!425Resolve "Plugin configuration in the admin panel"
......@@ -63,6 +63,12 @@ public class Plugin implements Serializable {
*/
private String version;
/**
* Is the plugin public.
*/
@Column(name = "is_public")
private boolean isPublic= false;
/**
* List of urls from which plugin can be downloaded.
*/
......@@ -110,4 +116,12 @@ public class Plugin implements Serializable {
public void setId(int id) {
this.id = id;
}
public boolean isPublic() {
return isPublic;
}
public void setPublic(boolean isPublic) {
this.isPublic = isPublic;
}
}
alter table plugin_table add column is_public boolean default false;
......@@ -35,16 +35,18 @@ public class PluginController extends BaseController {
@RequestParam(value = "hash") String hash, //
@RequestParam(value = "name") String name, //
@RequestParam(value = "version") String version, //
@RequestParam(value = "isPublic", defaultValue = "false") String isPublic, //
@RequestParam(value = "url", defaultValue = "") String url //
) throws SecurityException {
return pluginRest.createPlugin(token, hash, name, version, url);
return pluginRest.createPlugin(token, hash, name, version, url, isPublic);
}
@RequestMapping(value = "/plugins/", method = { RequestMethod.GET }, produces = { MediaType.APPLICATION_JSON_VALUE })
public List<Map<String, Object>> getPlugins(//
@RequestParam(value = "onlyPublic", defaultValue = "false") String onlyPublic, //
@CookieValue(value = Configuration.AUTH_TOKEN) String token //
) throws SecurityException {
return pluginRest.getPlugins(token);
return pluginRest.getPlugins(token, onlyPublic.equalsIgnoreCase("true"));
}
@RequestMapping(value = "/plugins/{hash}", method = { RequestMethod.GET }, produces = {
......@@ -56,7 +58,8 @@ public class PluginController extends BaseController {
return pluginRest.getPlugin(token, hash);
}
@RequestMapping(value = "/plugins/{hash}/data/users/{login}/{key}", method = { RequestMethod.POST }, produces = { MediaType.APPLICATION_JSON_VALUE })
@RequestMapping(value = "/plugins/{hash}/data/users/{login}/{key}", method = { RequestMethod.POST }, produces = {
MediaType.APPLICATION_JSON_VALUE })
public Map<String, Object> createPluginDataEntry(//
@CookieValue(value = Configuration.AUTH_TOKEN) String token, //
@PathVariable(value = "hash") String hash, //
......@@ -78,7 +81,8 @@ public class PluginController extends BaseController {
return pluginRest.getPluginDataEntry(token, hash, login, key);
}
@RequestMapping(value = "/plugins/{hash}/data/global/{key}", method = { RequestMethod.POST }, produces = { MediaType.APPLICATION_JSON_VALUE })
@RequestMapping(value = "/plugins/{hash}/data/global/{key}", method = { RequestMethod.POST }, produces = {
MediaType.APPLICATION_JSON_VALUE })
public Map<String, Object> createPluginDataEntry(//
@CookieValue(value = Configuration.AUTH_TOKEN) String token, //
@PathVariable(value = "hash") String hash, //
......
......@@ -27,7 +27,8 @@ public class PluginRestImpl extends BaseRestImpl {
@Autowired
private PluginDataEntryDao pluginDataEntryDao;
public Map<String, Object> createPlugin(String token, String hash, String name, String version, String url) {
public Map<String, Object> createPlugin(String token, String hash, String name, String version, String url,
String isPublic) {
Plugin plugin = pluginDao.getByHash(hash);
if (plugin != null) {
plugin.getUrls().add(url);
......@@ -37,6 +38,7 @@ public class PluginRestImpl extends BaseRestImpl {
plugin.setHash(hash);
plugin.setName(name);
plugin.setVersion(version);
plugin.setPublic(isPublic.equalsIgnoreCase("true"));
if (!url.isEmpty()) {
plugin.getUrls().add(url);
}
......@@ -50,6 +52,7 @@ public class PluginRestImpl extends BaseRestImpl {
result.put("hash", plugin.getHash());
result.put("name", plugin.getName());
result.put("version", plugin.getVersion());
result.put("isPublic", plugin.isPublic());
List<String> urls = new ArrayList<>();
urls.addAll(plugin.getUrls());
Collections.sort(urls);
......@@ -125,13 +128,15 @@ public class PluginRestImpl extends BaseRestImpl {
return pluginEntryToMap(entry);
}
public List<Map<String, Object>> getPlugins(String token) {
public List<Map<String, Object>> getPlugins(String token, boolean onlyPublic) {
List<Plugin> plugins = pluginDao.getAll();
plugins.sort(Plugin.ID_COMPARATOR);
List<Map<String, Object>> result = new ArrayList<>();
for (Plugin plugin : plugins) {
result.add(pluginToMap(plugin));
if ((onlyPublic && plugin.isPublic()) || !onlyPublic) {
result.add(pluginToMap(plugin));
}
}
return result;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment