From d19eb32959d37c72a5f50e1ecc60e81f5d000dd9 Mon Sep 17 00:00:00 2001 From: Karthik Date: Mon, 3 Jul 2023 00:15:09 -0400 Subject: [PATCH] Changes related to download group --- .../cbio/portal/util/GlobalProperties.java | 38 +++++++++++++------ portal/src/main/webapp/config_service.jsp | 2 +- src/main/resources/portal.properties.EXAMPLE | 4 +- 3 files changed, 30 insertions(+), 14 deletions(-) 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..f9df86ed8af 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,26 @@ 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"; + default: return "show"; + } } } } 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