use of org.molgenis.security.core.Permission in project molgenis by molgenis.
the class DataExplorerController method getModules.
/**
* Returns modules configuration for this entity based on current user permissions.
*/
@GetMapping("/modules")
@ResponseBody
public ModulesConfigResponse getModules(@RequestParam("entity") String entityTypeId) {
boolean modAggregates = dataExplorerSettings.getModAggregates();
boolean modAnnotators = dataExplorerSettings.getModAnnotators();
boolean modData = dataExplorerSettings.getModData();
boolean modReports = dataExplorerSettings.getModReports();
if (modAggregates) {
modAggregates = dataService.getCapabilities(entityTypeId).contains(RepositoryCapability.AGGREGATEABLE);
}
// set data explorer permission
Permission pluginPermission = null;
if (permissionService.hasPermission(new EntityTypeIdentity(entityTypeId), EntityTypePermission.WRITE))
pluginPermission = WRITE;
else if (permissionService.hasPermission(new EntityTypeIdentity(entityTypeId), EntityTypePermission.READ))
pluginPermission = READ;
else if (permissionService.hasPermission(new EntityTypeIdentity(entityTypeId), EntityTypePermission.COUNT))
pluginPermission = Permission.COUNT;
ModulesConfigResponse modulesConfig = new ModulesConfigResponse();
String aggregatesTitle = messageSource.getMessage("dataexplorer_aggregates_title", new Object[] {}, LocaleContextHolder.getLocale());
if (pluginPermission != null) {
switch(pluginPermission) {
case COUNT:
if (modAggregates) {
modulesConfig.add(new ModuleConfig("aggregates", aggregatesTitle, "grid-icon.png"));
}
break;
case READ:
case WRITE:
if (modData) {
modulesConfig.add(new ModuleConfig("data", "Data", "grid-icon.png"));
}
if (modAggregates) {
modulesConfig.add(new ModuleConfig("aggregates", aggregatesTitle, "aggregate-icon.png"));
}
if (modAnnotators && pluginPermission == WRITE) {
modulesConfig.add(new ModuleConfig("annotators", "Annotators", "annotator-icon.png"));
}
if (modReports) {
String modEntitiesReportName = dataExplorerSettings.getEntityReport(entityTypeId);
if (modEntitiesReportName != null) {
modulesConfig.add(new ModuleConfig("entitiesreport", modEntitiesReportName, "report-icon.png"));
}
}
break;
case NONE:
break;
default:
throw new UnexpectedEnumException(pluginPermission);
}
}
return modulesConfig;
}
use of org.molgenis.security.core.Permission in project molgenis by molgenis.
the class DataExplorerController method init.
/**
* Show the explorer page
*
* @return the view name
*/
@GetMapping
public String init(@RequestParam(value = "entity", required = false) String selectedEntityName, @RequestParam(value = "entityId", required = false) String selectedEntityId, Model model) {
StringBuilder message = new StringBuilder("");
final boolean currentUserIsSu = SecurityUtils.currentUserIsSu();
Map<String, EntityType> entitiesMeta = dataService.getMeta().getEntityTypes().filter(entityType -> !entityType.isAbstract()).filter(entityType -> currentUserIsSu || !EntityTypeUtils.isSystemEntity(entityType)).sorted(Comparator.comparing(EntityType::getLabel)).collect(Collectors.toMap(EntityType::getId, Function.identity(), (e1, e2) -> e2, LinkedHashMap::new));
model.addAttribute("entitiesMeta", entitiesMeta);
if (selectedEntityId != null && selectedEntityName == null) {
EntityType entityType = dataService.getMeta().getEntityType(selectedEntityId);
if (entityType == null) {
message.append("Entity does not exist or you do not have permission on this entity");
} else {
selectedEntityName = entityType.getId();
}
if (selectedEntityName != null) {
checkExistsAndPermission(selectedEntityName, message);
}
}
if (StringUtils.isNotEmpty(message.toString())) {
model.addAttribute("warningMessage", message.toString());
}
model.addAttribute("selectedEntityName", selectedEntityName);
model.addAttribute("isAdmin", currentUserIsSu);
boolean navigatorAvailable = menuReaderService.getMenu().findMenuItemPath(NAVIGATOR) != null;
model.addAttribute("showNavigatorLink", dataExplorerSettings.isShowNavigatorLink() && navigatorAvailable);
model.addAttribute("hasTrackingId", null != appSettings.getGoogleAnalyticsTrackingId());
model.addAttribute("hasMolgenisTrackingId", null != appSettings.getGoogleAnalyticsTrackingIdMolgenis());
return "view-dataexplorer";
}
Aggregations