forked from blcham/record-manager
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[kbss-cvut/record-manager-ui#202] Implement Role group assignment
- Loading branch information
Showing
6 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/main/java/cz/cvut/kbss/study/util/RoleAssignmentUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package cz.cvut.kbss.study.util; | ||
|
||
import cz.cvut.kbss.study.model.Vocabulary; | ||
|
||
import java.util.*; | ||
|
||
public class RoleAssignmentUtil { | ||
|
||
public static final Set<String> OPERATOR_ADMIN_ROLES = new HashSet<>( | ||
Set.of( | ||
Vocabulary.s_c_administrator, | ||
Vocabulary.s_c_doctor, | ||
Vocabulary.s_c_edit_users, | ||
Vocabulary.s_c_publish_records, | ||
Vocabulary.s_c_reject_records, | ||
Vocabulary.s_c_view_organization_records, | ||
Vocabulary.s_c_edit_organization_records, | ||
Vocabulary.s_c_delete_organization_records, | ||
Vocabulary.s_c_complete_records, | ||
Vocabulary.s_c_import_codelists | ||
) | ||
); | ||
|
||
public static final Set<String> OPERATOR_USER_ROLES = new HashSet<>( | ||
Set.of( | ||
Vocabulary.s_c_complete_records | ||
) | ||
); | ||
|
||
public static final Set<String> SUPPLIER_ADMIN_ROLES = new HashSet<>( | ||
Set.of( | ||
Vocabulary.s_c_administrator, | ||
Vocabulary.s_c_doctor, | ||
Vocabulary.s_c_edit_users, | ||
Vocabulary.s_c_reject_records, | ||
Vocabulary.s_c_view_organization_records, | ||
Vocabulary.s_c_edit_organization_records, | ||
Vocabulary.s_c_delete_organization_records, | ||
Vocabulary.s_c_complete_records, | ||
Vocabulary.s_c_import_codelists, | ||
Vocabulary.s_c_edit_all_records, | ||
Vocabulary.s_c_delete_all_records, | ||
Vocabulary.s_c_view_all_records | ||
) | ||
); | ||
|
||
public static final Set<String> SUPPLIER_USER_ROLES = new HashSet<>( | ||
Set.of( | ||
Vocabulary.s_c_complete_records | ||
) | ||
); | ||
|
||
public static final Map<String, Set<String>> roleGroups = Map.of( | ||
Constants.OPERATOR_ADMIN, OPERATOR_ADMIN_ROLES, | ||
Constants.OPERATOR_USER, OPERATOR_USER_ROLES, | ||
Constants.SUPPLIER_ADMIN, SUPPLIER_ADMIN_ROLES, | ||
Constants.SUPPLIER_USER, SUPPLIER_USER_ROLES, | ||
Constants.EXTERNAL_USER, defaultRoles() | ||
); | ||
|
||
|
||
public static Set<String> assignRolesForGroup(String group) { | ||
if(group != null) | ||
return roleGroups.getOrDefault(group, defaultRoles()); | ||
return defaultRoles(); | ||
} | ||
|
||
/** | ||
* Default roles to be assigned if the group is not recognized. | ||
* | ||
* @return A set of default roles | ||
*/ | ||
private static Set<String> defaultRoles() { | ||
Set<String> defaultRoles = new HashSet<>(); | ||
defaultRoles.add(Vocabulary.s_c_doctor); | ||
return defaultRoles; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
import cz.cvut.kbss.study.security.model.UserDetails; | ||
import cz.cvut.kbss.study.service.ConfigReader; | ||
import cz.cvut.kbss.study.util.ConfigParam; | ||
import cz.cvut.kbss.study.util.Constants; | ||
import cz.cvut.kbss.study.util.IdentificationUtils; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
|
@@ -66,6 +67,7 @@ public void setUp() { | |
Institution institution = Generator.generateInstitution(); | ||
institution.setKey(IdentificationUtils.generateKey()); | ||
this.user = Generator.getUser(USERNAME, PASSWORD, "John", "Johnie", "[email protected]", institution); | ||
this.user.setRoleGroup(Constants.OPERATOR_ADMIN); | ||
user.generateUri(); | ||
} | ||
|
||
|