Skip to content

Commit

Permalink
Merge pull request #10254 from kalletlak/feature/10248
Browse files Browse the repository at this point in the history
Set download button visibility in UI based on user role/group
  • Loading branch information
kalletlak authored Jul 19, 2023
2 parents a3794f7 + 16acfa7 commit 8f6534e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 14 deletions.
42 changes: 30 additions & 12 deletions core/src/main/java/org/mskcc/cbio/portal/util/GlobalProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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";
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,13 @@ Below you can find the complete list of all the available skin properties.
<td>controls download options in UI. **true**: hides all download options. **false**: shows all download options. **data**: disable data download but not figure download</td>
<td>false</td>
<td>true / false / data</td>
</tr>
<tr>
<td>download_group</td>
<td>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**</td>
<td></td>
<td>text</td>
</tr>
<tr>
<td>skin.show_settings_menu</td>
Expand Down
2 changes: 1 addition & 1 deletion portal/src/main/webapp/config_service.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/portal.properties.EXAMPLE
Original file line number Diff line number Diff line change
Expand Up @@ -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=
# study_download_url=

# download_group=

0 comments on commit 8f6534e

Please sign in to comment.