diff --git a/core/src/main/java/org/mskcc/cbio/portal/util/GlobalProperties.java b/core/src/main/java/org/mskcc/cbio/portal/util/GlobalProperties.java index ad5612c6721..ba311e72ad5 100644 --- a/core/src/main/java/org/mskcc/cbio/portal/util/GlobalProperties.java +++ b/core/src/main/java/org/mskcc/cbio/portal/util/GlobalProperties.java @@ -50,11 +50,13 @@ import java.util.List; import java.util.Properties; +import org.apache.commons.lang.StringUtils; import org.cbioportal.security.spring.authentication.PortalUserDetails; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.security.core.Authentication; +import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Component; import org.springframework.util.ResourceUtils; @@ -362,6 +364,10 @@ public static String parseUrl(String url) @Value("${frontend.url.runtime:}") public void setFrontendUrlRuntime(String property) { frontendUrlRuntime = property; } + private static String downloadGroup; + @Value("${download_group:}") // default is empty string + public void setDownloadGroup(String property) { downloadGroup = property; } + private static Logger LOG = LoggerFactory.getLogger(GlobalProperties.class); private static ConfigPropertyResolver portalProperties = new ConfigPropertyResolver(); private static Properties mavenProperties = initializeProperties(MAVEN_PROPERTIES_FILE_NAME); @@ -1264,18 +1270,30 @@ public static String getOncoKbToken() { } public static String getDownloadControl() { - String downloadControlOption = getProperty("skin.hide_download_controls"); - /* - skin.hide_download_controls return_value - true hide - false show - data data - null/empty show - */ - switch ((downloadControlOption != null) ? downloadControlOption.trim().toLowerCase() : "false") { - case "true" : return "hide"; - case "data" : return "data"; - default: return "show"; + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + + if (authentication != null && + StringUtils.isNotEmpty(downloadGroup) && + authentication.getAuthorities().contains(new SimpleGrantedAuthority(downloadGroup))) { + return "show"; + } else { + String downloadControlOption = getProperty("skin.hide_download_controls"); + /* + skin.hide_download_controls return_value + true hide + false show + data data + null/empty show + */ + switch ((downloadControlOption != null) ? downloadControlOption.trim().toLowerCase() : "false") { + case "true": + return "hide"; + case "data": + return "data"; + case "false": + default: + return "show"; + } } } } diff --git a/docs/deployment/customization/Customizing-your-instance-of-cBioPortal.md b/docs/deployment/customization/Customizing-your-instance-of-cBioPortal.md index b20f514cc23..7575ad63507 100644 --- a/docs/deployment/customization/Customizing-your-instance-of-cBioPortal.md +++ b/docs/deployment/customization/Customizing-your-instance-of-cBioPortal.md @@ -246,6 +246,13 @@ Below you can find the complete list of all the available skin properties. controls download options in UI. **true**: hides all download options. **false**: shows all download options. **data**: disable data download but not figure download false true / false / data + + + download_group + controls download options in UI for each user. If present and user is authenticated, this value is checked against user roles. +If the download_group is present in user groups then download options are shown in UI, else it fallback to **skin.hide_download_controls** + + text skin.show_settings_menu diff --git a/portal/src/main/webapp/config_service.jsp b/portal/src/main/webapp/config_service.jsp index 3dba7cba8c2..ab5bbf48c3e 100644 --- a/portal/src/main/webapp/config_service.jsp +++ b/portal/src/main/webapp/config_service.jsp @@ -202,7 +202,7 @@ obj.put("oncoKbTokenDefined", !StringUtils.isEmpty(GlobalProperties.getOncoKbToken())); obj.put("sessionServiceEnabled", !StringUtils.isEmpty(GlobalProperties.getSessionServiceUrl())); - + obj.put("skin_hide_download_controls", GlobalProperties.getDownloadControl()); out.println(obj.toJSONString()); diff --git a/src/main/resources/portal.properties.EXAMPLE b/src/main/resources/portal.properties.EXAMPLE index ce06c5554df..efae1b8c794 100644 --- a/src/main/resources/portal.properties.EXAMPLE +++ b/src/main/resources/portal.properties.EXAMPLE @@ -433,4 +433,6 @@ persistence.cache_type=no-cache # Set StudyDownloadLinkUrl # Allows download links within DataSets Tab (See Portal.Properties documentation for more info) -# study_download_url= \ No newline at end of file +# study_download_url= + +# download_group= \ No newline at end of file