Skip to content

Commit 866be4a

Browse files
author
rmmayo
committed
#3052 - adding role management for global badges. adding group admin support for global badges
1 parent 5f9c5ea commit 866be4a

File tree

7 files changed

+267
-10
lines changed

7 files changed

+267
-10
lines changed

service/src/main/java/skills/services/AccessSettingsStorageService.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ class AccessSettingsStorageService {
425425
}
426426

427427
UserRole addGlobalBadgeAdminUserRoleForUser(String userId, String globalBadgeId, RoleName roleName, String adminGroupId = null) {
428-
log.debug('Creating quiz id user-role for ID [{}] and role [{}] on quiz [{}]', userId, roleName, globalBadgeId, adminGroupId)
428+
log.debug('Creating global badge id user-role for ID [{}] and role [{}] on global badge [{}]', userId, roleName, globalBadgeId, adminGroupId)
429429
String userIdLower = userId?.toLowerCase()
430430
User user = userRepository.findByUserId(userIdLower)
431431
if (user) {

service/src/main/java/skills/services/GlobalBadgeRoleService.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class GlobalBadgeRoleService {
8383
if (addingAsLocalAdmin && userRoleRepo.isUserGlobalBadgeAdmin(userId, badgeId)) {
8484
throw new SkillException("User is already part of an Admin Group and cannot be added as a local admin. userId=[${userId}]", ErrorCode.AccessDenied)
8585
}
86-
accessSettingsStorageService.addGlobalBadgeAdminUserRoleForUser(userId, badgeResult.badgeId, RoleName.ROLE_GLOBAL_BADGE_ADMIN)
86+
accessSettingsStorageService.addGlobalBadgeAdminUserRoleForUser(userId, badgeResult.badgeId, RoleName.ROLE_GLOBAL_BADGE_ADMIN, adminGroupId)
8787

8888
UserAttrs userAttrs = userAttrsRepo.findByUserIdIgnoreCase(userId)
8989
String userIdForDisplay = userAttrs?.userIdForDisplay ?: userId

service/src/main/java/skills/services/adminGroup/AdminGroupRoleService.groovy

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import skills.controller.result.model.GlobalBadgeResult
2828
import skills.controller.result.model.ProjectResult
2929
import skills.controller.result.model.UserRoleRes
3030
import skills.services.AccessSettingsStorageService
31+
import skills.services.GlobalBadgeRoleService
3132
import skills.services.GlobalBadgesService
3233
import skills.services.admin.ProjAdminService
3334
import skills.services.admin.UserCommunityService
@@ -70,6 +71,9 @@ class AdminGroupRoleService {
7071
@Autowired
7172
GlobalBadgesService globalBadgesService
7273

74+
@Autowired
75+
GlobalBadgeRoleService globalBadgeRoleService
76+
7377
@Autowired
7478
UserNameService userNameService
7579

@@ -118,6 +122,10 @@ class AdminGroupRoleService {
118122
projectIds.each { projectId ->
119123
accessSettingsStorageService.addUserRole(userId, projectId, RoleName.ROLE_PROJECT_ADMIN, true, adminGroupDef.adminGroupId)
120124
}
125+
List<String> globalBadgeIds = userRoleRepo.findGlobalBadgeIdsByAdminGroupId(adminGroupDef.adminGroupId)
126+
globalBadgeIds.each { globalBadgeId ->
127+
globalBadgeRoleService.addGlobalBadgeAdminRole(userId, globalBadgeId, RoleName.ROLE_GLOBAL_BADGE_ADMIN, adminGroupDef.adminGroupId)
128+
}
121129
}
122130

123131
UserAttrs userAttrs = userAttrsRepo.findByUserIdIgnoreCase(userId)

service/src/main/java/skills/services/adminGroup/AdminGroupService.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ class AdminGroupService {
226226
userRoleRepository.findQuizIdsByAdminGroupId(adminGroupId).each { quizId ->
227227
adminGroupRoleService.removeQuizFromAdminGroup(adminGroupId, quizId)
228228
}
229+
userRoleRepository.findGlobalBadgeIdsByAdminGroupId(adminGroupId).each { badgeId ->
230+
adminGroupRoleService.removeGlobalBadgeFromAdminGroup(adminGroupId, badgeId)
231+
}
229232
adminGroupDefRepo.deleteByAdminGroupIdIgnoreCase(adminGroupDef.adminGroupId)
230233
log.debug("Deleted admin group with id [{}].", adminGroupId)
231234

service/src/main/java/skills/storage/repos/UserRoleRepo.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ interface UserRoleRepo extends CrudRepository<UserRole, Integer> {
9292
@Nullable
9393
List<UserRole> findAllByQuizIdIgnoreCase(String quizId)
9494

95+
@Nullable
96+
List<UserRole> findAllByGlobalBadgeIdIgnoreCase(String globalBadgeId)
97+
9598
@Query('''SELECT count(ur.id)
9699
from UserRole ur, UserAttrs ua
97100
where

0 commit comments

Comments
 (0)