}
@Test
- public void selectGroupUuidsWithPermissionOnProject_shouldReturnOnlyGroupsWithSpecifiedPermission() {
+ public void selectGroupUuidsWithPermissionOnEntity_shouldReturnOnlyGroupsWithSpecifiedPermission() {
GroupDto group1 = db.users().insertGroup();
GroupDto group2 = db.users().insertGroup();
GroupDto group3 = db.users().insertGroup();
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto otherProject = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPrivateProject().getProjectDto();
+ ProjectDto otherProject = db.components().insertPrivateProject().getProjectDto();
String anyPermission = "any_permission";
- db.users().insertProjectPermissionOnGroup(group1, anyPermission, project);
- db.users().insertProjectPermissionOnGroup(group2, "otherPermission", project);
- db.users().insertProjectPermissionOnGroup(group3, anyPermission, otherProject);
+ db.users().insertEntityPermissionOnGroup(group1, anyPermission, project);
+ db.users().insertEntityPermissionOnGroup(group2, "otherPermission", project);
+ db.users().insertEntityPermissionOnGroup(group3, anyPermission, otherProject);
- Set<String> results = underTest.selectGroupUuidsWithPermissionOnProject(dbSession, project.uuid(), anyPermission);
+ Set<String> results = underTest.selectGroupUuidsWithPermissionOnEntity(dbSession, project.getUuid(), anyPermission);
assertThat(results).containsOnly(group1.getUuid());
}
}
/**
- * Lists group uuids that have the selected permission on the specified project.
+ * Lists group uuids that have the selected permission on the specified entity.
*/
- public Set<String> selectGroupUuidsWithPermissionOnProject(DbSession session, String projectUuid, String permission) {
- return mapper(session).selectGroupUuidsWithPermissionOnProject(projectUuid, permission);
+ public Set<String> selectGroupUuidsWithPermissionOnEntity(DbSession session, String entityUuid, String permission) {
+ return mapper(session).selectGroupUuidsWithPermissionOnEntity(entityUuid, permission);
}
public void insert(DbSession dbSession, GroupPermissionDto groupPermissionDto, @Nullable EntityDto entityDto, @Nullable PermissionTemplateDto permissionTemplateDto) {
*/
Set<String> selectGroupUuidsWithPermissionOnEntityBut(@Param("entityUuid") String entityUuid, @Param("role") String permission);
- Set<String> selectGroupUuidsWithPermissionOnProject(@Param("projectUuid") String projectUuid, @Param("role") String permission);
+ Set<String> selectGroupUuidsWithPermissionOnEntity(@Param("entityUuid") String entityUuid, @Param("role") String permission);
int deleteByEntityUuid(@Param("entityUuid") String entityUuid);
)
</select>
- <select id="selectGroupUuidsWithPermissionOnProject" resultType="string">
+ <select id="selectGroupUuidsWithPermissionOnEntity" resultType="string">
select
distinct gr1.group_uuid
from
group_roles gr1
where
- gr1.component_uuid = #{projectUuid,jdbcType=VARCHAR}
+ gr1.entity_uuid = #{entityUuid,jdbcType=VARCHAR}
and gr1.group_uuid is not null
and gr1.role = #{role,jdbcType=VARCHAR}
</select>
@Test
public void wsAction_whenRemovingOwnBrowsePermissionAndHavePermissionFromOtherGroup_shouldRemovePermission() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPrivateProject().getProjectDto();
UserDto user = db.users().insertUser();
GroupDto projectAdminGroup = db.users().insertGroup();
GroupDto otherProjectAdminGroup = db.users().insertGroup();
- db.users().insertProjectPermissionOnGroup(projectAdminGroup, UserRole.USER, project);
- db.users().insertProjectPermissionOnGroup(projectAdminGroup, UserRole.ADMIN, project);
- db.users().insertProjectPermissionOnGroup(otherProjectAdminGroup, UserRole.USER, project);
- db.users().insertProjectPermissionOnGroup(otherProjectAdminGroup, UserRole.ADMIN, project);
+ db.users().insertEntityPermissionOnGroup(projectAdminGroup, UserRole.USER, project);
+ db.users().insertEntityPermissionOnGroup(projectAdminGroup, UserRole.ADMIN, project);
+ db.users().insertEntityPermissionOnGroup(otherProjectAdminGroup, UserRole.USER, project);
+ db.users().insertEntityPermissionOnGroup(otherProjectAdminGroup, UserRole.ADMIN, project);
userSession.logIn(user).setGroups(projectAdminGroup, otherProjectAdminGroup).addProjectPermission(UserRole.USER, project).addProjectPermission(UserRole.ADMIN, project);
newRequest()
- .setParam(PARAM_PROJECT_ID, project.uuid())
+ .setParam(PARAM_PROJECT_ID, project.getUuid())
.setParam(PARAM_GROUP_NAME, projectAdminGroup.getName())
.setParam(PARAM_PERMISSION, UserRole.USER)
.execute();
return user.getLogin().equals(userSession.getLogin());
}
- public void checkRemovingOwnBrowsePermissionOnPrivateProject(DbSession dbSession, UserSession userSession, @Nullable ComponentDto project, String permission,
+ public void checkRemovingOwnBrowsePermissionOnPrivateProject(DbSession dbSession, UserSession userSession, @Nullable EntityDto entityDto, String permission,
GroupUuidOrAnyone group) {
- if (userSession.isSystemAdministrator() || group.isAnyone() || !isUpdatingBrowsePermissionOnPrivateProject(permission, project)) {
+ if (userSession.isSystemAdministrator() || group.isAnyone() || !isUpdatingBrowsePermissionOnPrivateProject(permission, entityDto)) {
return;
}
- Set<String> groupUuidsWithPermission = dbClient.groupPermissionDao().selectGroupUuidsWithPermissionOnProject(dbSession, project.uuid(), UserRole.USER);
+ Set<String> groupUuidsWithPermission = dbClient.groupPermissionDao().selectGroupUuidsWithPermissionOnEntity(dbSession, entityDto.getUuid(), UserRole.USER);
boolean isUserInAnotherGroupWithPermissionForThisProject = userSession.getGroups().stream()
.map(GroupDto::getUuid)
.anyMatch(groupDtoUuid -> groupUuidsWithPermission.contains(groupDtoUuid) && !groupDtoUuid.equals(group.getUuid()));
}
}
- public void checkRemovingOwnBrowsePermissionOnPrivateProject(UserSession userSession, @Nullable ComponentDto project, String permission, UserId user) {
- if (isUpdatingBrowsePermissionOnPrivateProject(permission, project) && user.getLogin().equals(userSession.getLogin())) {
+ public void checkRemovingOwnBrowsePermissionOnPrivateProject(UserSession userSession, @Nullable EntityDto entityDto, String permission, UserId user) {
+ if (isUpdatingBrowsePermissionOnPrivateProject(permission, entityDto) && user.getLogin().equals(userSession.getLogin())) {
throw BadRequestException.create(ERROR_REMOVING_OWN_BROWSE_PERMISSION);
}
}
- public static boolean isUpdatingBrowsePermissionOnPrivateProject(String permission, @Nullable ComponentDto project) {
- return project != null && project.isPrivate() && permission.equals(UserRole.USER) ;
+ public static boolean isUpdatingBrowsePermissionOnPrivateProject(String permission, @Nullable EntityDto entityDto) {
+ return entityDto != null && entityDto.isPrivate() && permission.equals(UserRole.USER) ;
}
}