diff --git a/.github/workflows/githubactions.yml b/.github/workflows/githubactions.yml index 948265dd03..128f860278 100644 --- a/.github/workflows/githubactions.yml +++ b/.github/workflows/githubactions.yml @@ -62,7 +62,15 @@ jobs: bash scripts/install-thrift.sh --no-cleanup - name: Build SW360 - run: mvn clean package --no-transfer-progress -P deploy -Dhelp-docs=true -Dbase.deploy.dir=. -Dliferay.deploy.dir=/home/runner/work/sw360/sw360/deploy -Dbackend.deploy.dir=/home/runner/work/sw360/sw360/webapps -Drest.deploy.dir=/home/runner/work/sw360/sw360/webapps -DRunComponentVisibilityRestrictionTest=false + run: mvn clean package --no-transfer-progress -P deploy -Dhelp-docs=true -Dbase.deploy.dir=. -Dliferay.deploy.dir=/home/runner/work/sw360/sw360/deploy -Dbackend.deploy.dir=/home/runner/work/sw360/sw360/webapps -Drest.deploy.dir=/home/runner/work/sw360/sw360/webapps -DRunComponentVisibilityRestrictionTest=false -DRunPrivateProjectAccessTest=false + + - name: Run PrivateProjectAccessTest + run: | + cd build-configuration + mvn install + cd .. + cd libraries/lib-datahandler + mvn test -Dtest=ProjectPermissionsVisibilityTest -DRunPrivateProjectAccessTest=true - name: Deploy Backend and Rest Server run: | @@ -77,3 +85,4 @@ jobs: run: | cd clients mvn clean install --no-transfer-progress -DRunRestIntegrationTest=true + diff --git a/backend/src-common/src/main/java/org/eclipse/sw360/datahandler/db/ProjectRepository.java b/backend/src-common/src/main/java/org/eclipse/sw360/datahandler/db/ProjectRepository.java index 5d5cccb22a..e4129f4a48 100644 --- a/backend/src-common/src/main/java/org/eclipse/sw360/datahandler/db/ProjectRepository.java +++ b/backend/src-common/src/main/java/org/eclipse/sw360/datahandler/db/ProjectRepository.java @@ -388,6 +388,7 @@ public Map> getAccessibleProjectsSummary(User user final Selector buAndModorator_visibility_Selector = eq("visbility", "BUISNESSUNIT_AND_MODERATORS"); final Selector userBuSelector = eq("businessUnit", userBU); + boolean isAdmin = PermissionUtils.isAdmin(user); boolean isClearingAdmin = PermissionUtils.isUserAtLeast(UserGroup.CLEARING_ADMIN, user); Selector isUserBelongToBuAndModerator = null; @@ -412,12 +413,16 @@ public Map> getAccessibleProjectsSummary(User user isUserBelongToBuAndModerator = and(buAndModorator_visibility_Selector, or(buSelectors)); Selector finalSelector = null; - if (isClearingAdmin) { - finalSelector = and(typeSelector, or(getAllPrivateProjects, everyone_visibility_Selector, - isUserBelongToMeAndModerator, buAndModorator_visibility_Selector)); + if (PermissionUtils.IS_ADMIN_PRIVATE_ACCESS_ENABLED && isAdmin) { + finalSelector = typeSelector; } else { - finalSelector = and(typeSelector, or(getAllPrivateProjects, everyone_visibility_Selector, - isUserBelongToMeAndModerator, isUserBelongToBuAndModerator)); + if (isClearingAdmin) { + finalSelector = and(typeSelector, or(getAllPrivateProjects, everyone_visibility_Selector, + isUserBelongToMeAndModerator, buAndModorator_visibility_Selector)); + } else { + finalSelector = and(typeSelector, or(getAllPrivateProjects, everyone_visibility_Selector, + isUserBelongToMeAndModerator, isUserBelongToBuAndModerator)); + } } QueryBuilder qb = new QueryBuilder(finalSelector); @@ -532,6 +537,7 @@ private Set getAccessibleProjectSummary(User user, Set searchId } public int getMyAccessibleProjectsCount(User user) { + boolean isAdmin = PermissionUtils.isAdmin(user); boolean isClearingAdmin = PermissionUtils.isUserAtLeast(UserGroup.CLEARING_ADMIN, user); Set BUs = new HashSet<>(); String primaryOrg = SW360Utils.getBUFromOrganisation(user.getDepartment()); @@ -552,6 +558,9 @@ public int getMyAccessibleProjectsCount(User user) { } keys[keys.length - 2] = user.getEmail(); keys[keys.length - 1] = "everyone"; + if (PermissionUtils.IS_ADMIN_PRIVATE_ACCESS_ENABLED && isAdmin) { + return getConnector().getDocumentCount(Project.class); + } if (isClearingAdmin) { String[] keyss = new String[3]; keyss[keyss.length - 3] = "bu"; diff --git a/libraries/lib-datahandler/src/main/java/org/eclipse/sw360/datahandler/permissions/PermissionUtils.java b/libraries/lib-datahandler/src/main/java/org/eclipse/sw360/datahandler/permissions/PermissionUtils.java index 1e921bec1b..07a09319a0 100644 --- a/libraries/lib-datahandler/src/main/java/org/eclipse/sw360/datahandler/permissions/PermissionUtils.java +++ b/libraries/lib-datahandler/src/main/java/org/eclipse/sw360/datahandler/permissions/PermissionUtils.java @@ -35,13 +35,16 @@ public class PermissionUtils { public static final String PROPERTIES_FILE_PATH = "/sw360.properties"; public static final boolean IS_COMPONENT_VISIBILITY_RESTRICTION_ENABLED; - + public static final boolean IS_ADMIN_PRIVATE_ACCESS_ENABLED; + static { Properties props = CommonUtils.loadProperties(DatabaseSettings.class, PROPERTIES_FILE_PATH); IS_COMPONENT_VISIBILITY_RESTRICTION_ENABLED = Boolean.parseBoolean( System.getProperty("RunComponentVisibilityRestrictionTest", props.getProperty("component.visibility.restriction.enabled", "false"))); + IS_ADMIN_PRIVATE_ACCESS_ENABLED = Boolean.parseBoolean( + System.getProperty("RunPrivateProjectAccessTest", props.getProperty("admin.private.project.access.enabled", "false"))); } - + public static boolean isNormalUser(User user) { return isInGroup(user, UserGroup.USER); } diff --git a/libraries/lib-datahandler/src/main/java/org/eclipse/sw360/datahandler/permissions/ProjectPermissions.java b/libraries/lib-datahandler/src/main/java/org/eclipse/sw360/datahandler/permissions/ProjectPermissions.java index 2681799ca5..1622bb4ace 100644 --- a/libraries/lib-datahandler/src/main/java/org/eclipse/sw360/datahandler/permissions/ProjectPermissions.java +++ b/libraries/lib-datahandler/src/main/java/org/eclipse/sw360/datahandler/permissions/ProjectPermissions.java @@ -89,11 +89,13 @@ public static Predicate isVisible(final User user) { visibility = Visibility.BUISNESSUNIT_AND_MODERATORS; // the current default } + boolean isPrivateAccessAllowed = PermissionUtils.IS_ADMIN_PRIVATE_ACCESS_ENABLED && isUserAtLeast(ADMIN, user); + switch (visibility) { case PRIVATE: - return user.getEmail().equals(input.getCreatedBy()); + return user.getEmail().equals(input.getCreatedBy()) || isPrivateAccessAllowed; case ME_AND_MODERATORS: { - return userIsEquivalentToModeratorInProject(input, user.getEmail()); + return userIsEquivalentToModeratorInProject(input, user.getEmail()) || isPrivateAccessAllowed; } case BUISNESSUNIT_AND_MODERATORS: { boolean isVisibleBasedOnPrimaryCondition = isUserInBU(input, user.getDepartment()) diff --git a/libraries/lib-datahandler/src/test/java/org/eclipse/sw360/datahandler/permissions/ProjectPermissionsVisibilityTest.java b/libraries/lib-datahandler/src/test/java/org/eclipse/sw360/datahandler/permissions/ProjectPermissionsVisibilityTest.java index 1ca0b1a3a0..bba1269d70 100644 --- a/libraries/lib-datahandler/src/test/java/org/eclipse/sw360/datahandler/permissions/ProjectPermissionsVisibilityTest.java +++ b/libraries/lib-datahandler/src/test/java/org/eclipse/sw360/datahandler/permissions/ProjectPermissionsVisibilityTest.java @@ -48,40 +48,77 @@ public class ProjectPermissionsVisibilityTest extends ScenarioTest