Skip to content

Commit 3ee4d16

Browse files
committed
New endpoint for all non-CRM roles for urn picker in access
1 parent 1c8ec30 commit 3ee4d16

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

server/src/main/java/invite/internal/InternalInviteController.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ public ResponseEntity<List<Role>> rolesByApplication(@Parameter(hidden = true) @
109109
return ResponseEntity.ok(roles);
110110
}
111111

112+
@GetMapping("/roles-summary")
113+
@PreAuthorize("hasAnyRole('ACCESS')")
114+
@Transactional(readOnly = true)
115+
@Hidden
116+
public ResponseEntity<List<Map<String, String>>> rolesSummary(@Parameter(hidden = true) @AuthenticationPrincipal RemoteUser remoteUser) {
117+
LOG.debug(String.format("/roles-summary for user %s", remoteUser.getName()));
118+
119+
List<Map<String, String>> roles = roleRepository.summary();
120+
return ResponseEntity.ok(roles);
121+
}
122+
112123
@GetMapping("/roles/{organizationGUID}/{manageId}")
113124
@PreAuthorize("hasRole('ACCESS')")
114125
@Transactional(readOnly = true)

server/src/main/java/invite/repository/RoleRepository.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ SELECT COUNT(r.id) FROM roles r WHERE r.organization_guid = ?1
8888
nativeQuery = true)
8989
List<Map<String, Object>> findApplications(List<Long> roleIdentifiers);
9090

91+
@Query(value = """
92+
SELECT r.name as name, r.description as description, r.urn as urn FROM roles r
93+
WHERE r.crm_role_id IS NULL
94+
""",
95+
nativeQuery = true)
96+
List<Map<String, String>> summary();
97+
9198
List<Role> findByApplicationUsagesApplicationManageId(String manageId);
9299

93100
List<Role> findByOrganizationGUIDAndApplicationUsagesApplicationManageId(String organizationGUID, String manageId);

server/src/test/java/invite/AbstractTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import invite.manage.EntityType;
99
import invite.manage.LocalManage;
1010
import invite.model.*;
11+
import invite.provision.scim.GroupURN;
1112
import invite.repository.*;
1213
import com.fasterxml.jackson.core.JsonProcessingException;
1314
import com.fasterxml.jackson.core.type.TypeReference;
@@ -117,6 +118,9 @@ public abstract class AbstractTest {
117118
@Value("${manage.staticManageDirectory}")
118119
private String staticManageDirectory;
119120

121+
@Value("${voot.group_urn_domain}")
122+
private String groupUrnPrefix;
123+
120124
@Autowired
121125
protected ObjectMapper objectMapper;
122126

@@ -688,6 +692,8 @@ private void doSeed() {
688692
research.setOrganizationGUID(ORGANISATION_GUID);
689693
wiki.setOrganizationGUID(ORGANISATION_GUID);
690694

695+
List.of(wiki, network, storage, research, calendar, mail)
696+
.forEach(role -> role.setUrn(GroupURN.urnFromRole(this.groupUrnPrefix, role)));
691697
doSave(this.roleRepository, wiki, network, storage, research, calendar, mail);
692698

693699
UserRole wikiManager =

server/src/test/java/invite/internal/InternalInviteControllerTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,5 +297,20 @@ void rolesPerOrganizationApplicationId() {
297297
assertEquals(2L, role.getUserRoleCount());
298298
}
299299

300+
@Test
301+
void rolesSummary() {
302+
List<Map<String, String>> roles = given()
303+
.when()
304+
.auth().preemptive().basic("access", "secret")
305+
.accept(ContentType.JSON)
306+
.contentType(ContentType.JSON)
307+
.get("/api/external/v1/internal/invite/roles-summary")
308+
.as(new TypeRef<>() {
309+
});
310+
311+
assertEquals(6, roles.size());
312+
List.of("name", "description","urn")
313+
.forEach(attr -> assertTrue(roles.stream().allMatch(role -> role.containsKey(attr))));
314+
}
300315

301316
}

0 commit comments

Comments
 (0)