use of org.molgenis.data.security.EntityTypeIdentity in project molgenis by molgenis.
the class PermissionSystemServiceImpl method giveUserWriteMetaPermissions.
@Override
public void giveUserWriteMetaPermissions(Collection<EntityType> entityTypes) {
Sid sid = SidUtils.createSid(getCurrentUsername());
runAsSystem(() -> {
CumulativePermission permission = getCumulativePermission(EntityTypePermission.WRITEMETA);
entityTypes.forEach(entityType -> {
MutableAcl acl = (MutableAcl) mutableAclService.readAclById(new EntityTypeIdentity(entityType));
acl.insertAce(acl.getEntries().size(), permission, sid, true);
mutableAclService.updateAcl(acl);
});
});
}
use of org.molgenis.data.security.EntityTypeIdentity in project molgenis by molgenis.
the class AnnotatorController method setMapOfAnnotators.
/**
* Sets a map of annotators, whether they can be used by the selected data set.
*
* @return mapOfAnnotators
*/
private Map<String, Map<String, Object>> setMapOfAnnotators(String dataSetName) {
Map<String, Map<String, Object>> mapOfAnnotators = new HashMap<>();
if (dataSetName != null) {
EntityType entityType = dataService.getEntityType(dataSetName);
for (RepositoryAnnotator annotator : annotationService.getAllAnnotators()) {
List<Attribute> outputAttrs = annotator.getOutputAttributes();
outputAttrs = getAtomicAttributesFromList(outputAttrs);
Map<String, Object> map = new HashMap<>();
map.put("description", annotator.getDescription());
map.put("canAnnotate", annotator.canAnnotate(entityType));
map.put("inputAttributes", createAttrsResponse(annotator.getRequiredAttributes()));
map.put("inputAttributeTypes", toMap(annotator.getRequiredAttributes()));
map.put("outputAttributes", createAttrsResponse(outputAttrs));
map.put("outputAttributeTypes", toMap(annotator.getOutputAttributes()));
String settingsEntityName = PACKAGE_SETTINGS + PACKAGE_SEPARATOR + annotator.getInfo().getCode();
map.put("showSettingsButton", permissionService.hasPermission(new EntityTypeIdentity(settingsEntityName), EntityTypePermission.WRITE));
mapOfAnnotators.put(annotator.getSimpleName(), map);
}
}
return mapOfAnnotators;
}
use of org.molgenis.data.security.EntityTypeIdentity in project molgenis by molgenis.
the class DataExplorerController method checkExistsAndPermission.
private void checkExistsAndPermission(@RequestParam(value = "entity", required = false) String selectedEntityName, StringBuilder message) {
boolean entityExists = dataService.hasRepository(selectedEntityName);
boolean hasEntityPermission = permissionService.hasPermission(new EntityTypeIdentity(selectedEntityName), EntityTypePermission.COUNT);
if (!(entityExists && hasEntityPermission)) {
if (selectedEntityName != null) {
message.append("Entity does not exist or you do not have permission on this entity");
if (!SecurityUtils.currentUserIsAuthenticated()) {
message.append(", log in to view more entities");
} else {
message.append(", please specify the fully qualified entity name");
}
}
}
}
use of org.molgenis.data.security.EntityTypeIdentity 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.data.security.EntityTypeIdentity in project molgenis by molgenis.
the class DataExplorerControllerTest method beforeTest.
@BeforeMethod
public void beforeTest() {
when(permissionService.hasPermission(new EntityTypeIdentity("yes"), EntityTypePermission.WRITEMETA)).thenReturn(true);
when(permissionService.hasPermission(new EntityTypeIdentity("no"), EntityTypePermission.WRITEMETA)).thenReturn(false);
when(idAttr.getDataType()).thenReturn(STRING);
when(entityType.getIdAttribute()).thenReturn(idAttr);
when(package_.getLabel()).thenReturn("pack");
when(package_.getId()).thenReturn("packId");
when(parentPackage.getLabel()).thenReturn("parent");
when(parentPackage.getId()).thenReturn("parentId");
when(package_.getParent()).thenReturn(parentPackage);
when(entityType.getPackage()).thenReturn(package_);
when(repository.findOneById(entityId)).thenReturn(entity);
when(dataService.getEntityType(entityTypeId)).thenReturn(entityType);
when(dataService.getRepository(entityTypeId)).thenReturn(repository);
when(dataExplorerSettings.getEntityReport(entityTypeId)).thenReturn("template");
when(dataExplorerSettings.getModStandaloneReports()).thenReturn(true);
when(freemarkerConfigurer.getConfiguration()).thenReturn(configuration);
Menu menu = mock(Menu.class);
when(menuReaderService.getMenu()).thenReturn(menu);
when(menu.findMenuItemPath(NAVIGATOR)).thenReturn(null);
when(localeResolver.resolveLocale(any())).thenReturn(Locale.ENGLISH);
mockMvc = MockMvcBuilders.standaloneSetup(controller).setMessageConverters(gsonHttpMessageConverter).build();
}
Aggregations