From 0fb053d11de4bb32242b6af9eb4779f57a3e07b7 Mon Sep 17 00:00:00 2001 From: ted Liefeld Date: Mon, 4 Dec 2023 13:01:02 -0800 Subject: [PATCH] GP-9549 allow a list of group names to be specified that users can share jobs with, even if they are not members --- .../genepattern/server/PermissionsHelper.java | 4 ++++ .../server/UserAccountManager.java | 21 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/org/genepattern/server/PermissionsHelper.java b/src/org/genepattern/server/PermissionsHelper.java index 0a0ab9f2e..6bad44c8b 100644 --- a/src/org/genepattern/server/PermissionsHelper.java +++ b/src/org/genepattern/server/PermissionsHelper.java @@ -133,6 +133,10 @@ private void initJobResultPermissions(IGroupMembershipPlugin groupMembership, Se //get all of the groups which aren't in group permissions Set groupsToAdd = new HashSet(); groupsToAdd.addAll(groups); + // get the list of groups its always available to share to + ArrayList alwaysShareTo = UserAccountManager.instance().getAlwaysShareableToUserGroups(); + groupsToAdd.addAll(alwaysShareTo); + for(GroupPermission gp : groupPermissions) { String groupId = gp.getGroupId(); groupsToAdd.remove(groupId); diff --git a/src/org/genepattern/server/UserAccountManager.java b/src/org/genepattern/server/UserAccountManager.java index d46a15b1c..72c2a4be1 100644 --- a/src/org/genepattern/server/UserAccountManager.java +++ b/src/org/genepattern/server/UserAccountManager.java @@ -6,6 +6,7 @@ import java.io.File; import java.security.NoSuchAlgorithmException; import java.sql.ResultSet; +import java.util.ArrayList; import java.util.Date; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -40,7 +41,8 @@ public class UserAccountManager { public static final String PROP_AUTHENTICATION_CLASS = "authentication.class"; public static final String PROP_GROUP_MEMBERSHIP_CLASS = "group.membership.class"; - + public static final String PROP_GROUPS_ALWAYS_SHAREABLE_TO = "groups.always.shareable.to"; + /** * The 'username.regex' is a regular expression which matches all valid usernames * and which must not match any invalid usernames. This pattern is used to validate @@ -83,6 +85,7 @@ private static class Singleton { private IAuthenticationPlugin authentication = null; private IGroupMembershipPlugin groupMembership = null; private UserGroups userGroups = null; + private ArrayList alwaysShareableUserGroups = null; //this property is optionally (when set) used in the default group membership class, UserGroups private File userGroupsXml=null; @@ -422,6 +425,11 @@ public UserGroups getUserGroups() { return userGroups; } + public ArrayList getAlwaysShareableToUserGroups(){ + return this.alwaysShareableUserGroups; + } + + /** * If necessary reload user and groups information by reloading the IAuthenticationPlugin and IGroupMembershipPlugins. * This supports one specific use-case: when GP default group membership is used, and an admin edits the configuration file, @@ -492,6 +500,17 @@ private void loadGroupMembership(final GpConfig gpConfig, String customGroupMemb this.userGroups = UserGroups.initFromConfig(gpConfig); } this.groupMembership = userGroups; + + String groupsAlwaysOnShareMenu = gpConfig.getGPProperty(GpContext.getServerContext(), PROP_GROUPS_ALWAYS_SHAREABLE_TO, null); + String[] shareableGroupNames = groupsAlwaysOnShareMenu.split(","); + ArrayList shareableGroupNamesList = new ArrayList(); + for (int i=0; i< shareableGroupNames.length; i++ ) { + String nom = shareableGroupNames[i].trim(); + if (nom.length() >0) { + shareableGroupNamesList.add(nom); + } + } + this.alwaysShareableUserGroups = shareableGroupNamesList; } else { try {