Search in sources :

Example 1 with Permission

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;
}
Also used : EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) UnexpectedEnumException(org.molgenis.util.UnexpectedEnumException) Permission(org.molgenis.security.core.Permission) EntityTypePermission(org.molgenis.data.security.EntityTypePermission)

Example 2 with Permission

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";
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) LocaleContextHolder(org.springframework.context.i18n.LocaleContextHolder) PluginController(org.molgenis.web.PluginController) URLDecoder(java.net.URLDecoder) MenuReaderService(org.molgenis.core.ui.menu.MenuReaderService) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) AnnotationJobExecutionMetaData(org.molgenis.data.annotation.web.meta.AnnotationJobExecutionMetaData) NegotiatorController(org.molgenis.dataexplorer.negotiator.NegotiatorController) JobExecutionMetaData(org.molgenis.jobs.model.JobExecutionMetaData) Model(org.springframework.ui.Model) JSONObject(org.json.JSONObject) Gson(com.google.gson.Gson) DataExplorerDownloadHandler(org.molgenis.dataexplorer.download.DataExplorerDownloadHandler) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) AttributeFactory(org.molgenis.data.meta.model.AttributeFactory) org.molgenis.data(org.molgenis.data) GenomeBrowserTrack(org.molgenis.genomebrowser.GenomeBrowserTrack) EntityTypeUtils(org.molgenis.data.support.EntityTypeUtils) EntityType(org.molgenis.data.meta.model.EntityType) Collectors(java.util.stream.Collectors) UnexpectedEnumException(org.molgenis.util.UnexpectedEnumException) UserPermissionEvaluator(org.molgenis.security.core.UserPermissionEvaluator) ParseException(freemarker.core.ParseException) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) FreeMarkerConfigurer(org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer) Permission(org.molgenis.security.core.Permission) java.util(java.util) LocalDateTime(java.time.LocalDateTime) QueryImpl(org.molgenis.data.support.QueryImpl) Controller(org.springframework.stereotype.Controller) EntityTypePermission(org.molgenis.data.security.EntityTypePermission) Function(java.util.function.Function) AppSettings(org.molgenis.settings.AppSettings) DownloadType(org.molgenis.dataexplorer.controller.DataRequest.DownloadType) ServletOutputStream(javax.servlet.ServletOutputStream) EntityUtils.getTypedValue(org.molgenis.data.util.EntityUtils.getTypedValue) URI(org.molgenis.dataexplorer.controller.DataExplorerController.URI) MessageSource(org.springframework.context.MessageSource) Logger(org.slf4j.Logger) READ(org.molgenis.security.core.Permission.READ) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) GenomeBrowserService(org.molgenis.genomebrowser.service.GenomeBrowserService) SecurityUtils(org.molgenis.security.core.utils.SecurityUtils) WRITE(org.molgenis.security.core.Permission.WRITE) DateTimeFormatter(java.time.format.DateTimeFormatter) ANNOTATION_JOB_EXECUTION(org.molgenis.data.annotation.web.meta.AnnotationJobExecutionMetaData.ANNOTATION_JOB_EXECUTION) Package(org.molgenis.data.meta.model.Package) DataExplorerSettings(org.molgenis.dataexplorer.settings.DataExplorerSettings) DOWNLOAD_TYPE_CSV(org.molgenis.dataexplorer.controller.DataRequest.DownloadType.DOWNLOAD_TYPE_CSV)

Aggregations

EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)2 EntityTypePermission (org.molgenis.data.security.EntityTypePermission)2 Permission (org.molgenis.security.core.Permission)2 UnexpectedEnumException (org.molgenis.util.UnexpectedEnumException)2 Gson (com.google.gson.Gson)1 ParseException (freemarker.core.ParseException)1 IOException (java.io.IOException)1 URLDecoder (java.net.URLDecoder)1 LocalDateTime (java.time.LocalDateTime)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 java.util (java.util)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 StringUtils (org.apache.commons.lang3.StringUtils)1 JSONObject (org.json.JSONObject)1 MenuReaderService (org.molgenis.core.ui.menu.MenuReaderService)1 org.molgenis.data (org.molgenis.data)1 AnnotationJobExecutionMetaData (org.molgenis.data.annotation.web.meta.AnnotationJobExecutionMetaData)1