});
}
+ /**
+ * Keep only authorized user that have the given permission on a given project.
+ * Please Note that if the permission is 'Anyone' is NOT taking into account by thie method.
+ */
public Collection<Long> keepAuthorizedUsersForRoleAndProject(final DbSession session, final Collection<Long> userIds, final String role, final long projectId) {
return DatabaseUtils.executeLargeInputs(userIds, new SelectUsersByPermissionAndProject(session.getMapper(AuthorizationMapper.class), role, projectId));
}
}
@Test
- public void keep_authorized_users_for_role_and_project_for_anonymous() {
+ public void keep_authorized_users_returns_empty_list_for_role_and_project_for_anonymous() {
dbTester.prepareDbUnit(getClass(), "keep_authorized_users_for_role_and_project_for_anonymous.xml");
assertThat(authorization.keepAuthorizedUsersForRoleAndProject(dbTester.getSession(),
// Only 100 and 101 has 'user' role on project
- newHashSet(100L, 101L, 102L), "user", PROJECT_ID)).containsOnly(100L, 101L);
+ newHashSet(100L, 101L, 102L), "user", PROJECT_ID)).isEmpty();
}
}
+++ /dev/null
-<dataset>
-
- <!-- users 100 and 101 have no direct grant access, but are in the group 200 that has the role "user" on the project 300 -->
- <user_roles id="1" user_id="100" resource_id="999" role="user"/>
- <user_roles id="2" user_id="101" resource_id="999" role="user"/>
- <user_roles id="3" user_id="102" resource_id="999" role="user"/>
-
- <groups_users user_id="100" group_id="200"/>
- <groups_users user_id="101" group_id="200"/>
- <groups_users user_id="102" group_id="201"/>
-
- <group_roles id="1" group_id="[null]" resource_id="300" role="user"/>
- <group_roles id="2" group_id="201" resource_id="400" role="user"/>
-
- <projects id="300" kee="pj-w-snapshot" uuid="DEFG" module_uuid="[null]"/>
- <projects id="400" kee="pj-wo-snapshot" uuid="EFGH" module_uuid="[null]"/>
-
-</dataset>
<dataset>
- <!-- Users 100 and 101 are 'user' on project 300 -->
- <user_roles id="1" user_id="100" resource_id="300" role="user"/>
- <user_roles id="2" user_id="101" resource_id="300" role="user"/>
- <user_roles id="3" user_id="102" resource_id="300" role="admin"/>
- <!-- User 100 is 'user' on project 400 -->
- <user_roles id="4" user_id="100" resource_id="400" role="user"/>
+ <!-- users 100 and 101 have no direct grant access, but are in the group 200 that has the role "user" on the project 300 -->
+ <user_roles id="1" user_id="100" resource_id="999" role="user"/>
+ <user_roles id="2" user_id="101" resource_id="999" role="user"/>
+ <user_roles id="3" user_id="102" resource_id="999" role="user"/>
<groups_users user_id="100" group_id="200"/>
- <group_roles id="1" group_id="200" resource_id="400" role="user"/>
+ <groups_users user_id="101" group_id="200"/>
+ <groups_users user_id="102" group_id="201"/>
+
+ <group_roles id="1" group_id="[null]" resource_id="300" role="user"/>
+ <group_roles id="2" group_id="201" resource_id="400" role="user"/>
<projects id="300" kee="pj-w-snapshot" uuid="DEFG" module_uuid="[null]"/>
<projects id="400" kee="pj-wo-snapshot" uuid="EFGH" module_uuid="[null]"/>
-
- <!-- user 100 has no direct grant access, but is in the group 200 that has the role "user"
- on the project 300 -->
- <!--<user_roles id="1" user_id="100" resource_id="999" role="user"/>-->
-
- <!--<groups_users user_id="100" group_id="200"/>-->
-
- <!--<group_roles id="1" group_id="200" resource_id="300" role="user"/>-->
- <!--<group_roles id="2" group_id="200" resource_id="400" role="user"/>-->
-
</dataset>