mirror of
https://github.com/valitydev/org-manager.git
synced 2024-11-06 00:15:23 +00:00
fix review
This commit is contained in:
parent
99163e5d65
commit
7ff8a0275b
@ -25,23 +25,23 @@ public class BouncerContextConverter {
|
||||
.collect(Collectors.toSet()));
|
||||
}
|
||||
|
||||
public Organization toOrganization(OrganizationEntity e,
|
||||
public Organization toOrganization(OrganizationEntity entity,
|
||||
Set<MemberRoleEntity> roles) {
|
||||
return new Organization()
|
||||
.setId(e.getId())
|
||||
.setOwner(new Entity().setId(e.getOwner()))
|
||||
.setId(entity.getId())
|
||||
.setOwner(new Entity().setId(entity.getOwner()))
|
||||
.setRoles(CollectionUtils.isEmpty(roles) ? null :
|
||||
roles.stream()
|
||||
.filter(memberRoleEntity -> memberRoleEntity.getOrganizationId().equals(e.getId()))
|
||||
.filter(memberRoleEntity -> memberRoleEntity.getOrganizationId().equals(entity.getId()))
|
||||
.map(this::toOrgRole)
|
||||
.collect(Collectors.toSet()));
|
||||
}
|
||||
|
||||
public OrgRole toOrgRole(MemberRoleEntity e) {
|
||||
public OrgRole toOrgRole(MemberRoleEntity entity) {
|
||||
return new OrgRole()
|
||||
.setId(e.getRoleId())
|
||||
.setId(entity.getRoleId())
|
||||
.setScope(new OrgRoleScope()
|
||||
.setShop(new Entity().setId(e.getResourceId())));
|
||||
.setShop(new Entity().setId(entity.getResourceId())));
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ class BouncerContextConverterTest {
|
||||
|
||||
@Test
|
||||
void shouldConvertToOrgRole() {
|
||||
// Given
|
||||
MemberRoleEntity entity = MemberRoleEntity.builder()
|
||||
.id("id")
|
||||
.roleId("Administrator")
|
||||
@ -38,10 +37,8 @@ class BouncerContextConverterTest {
|
||||
.organizationId("org")
|
||||
.build();
|
||||
|
||||
// When
|
||||
OrgRole role = converter.toOrgRole(entity);
|
||||
|
||||
// Then
|
||||
OrgRole expected = new OrgRole()
|
||||
.setId(RoleId.ADMINISTRATOR.getValue())
|
||||
.setScope(new OrgRoleScope()
|
||||
@ -55,7 +52,9 @@ class BouncerContextConverterTest {
|
||||
OrganizationEntity organizationEntity = TestObjectFactory.buildOrganization();
|
||||
MemberEntity memberEntity = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
||||
memberEntity.setOrganizations(Set.of(organizationEntity));
|
||||
|
||||
User user = converter.toUser(memberEntity);
|
||||
|
||||
assertEquals(memberEntity.getId(), user.getId());
|
||||
assertEquals(memberEntity.getEmail(), user.getEmail());
|
||||
assertEquals(memberEntity.getOrganizations().size(), user.getOrgs().size());
|
||||
@ -66,6 +65,7 @@ class BouncerContextConverterTest {
|
||||
OrganizationEntity organizationEntity = TestObjectFactory.buildOrganization();
|
||||
|
||||
var organization = converter.toOrganization(organizationEntity, Collections.emptySet());
|
||||
|
||||
assertEquals(organizationEntity.getId(), organization.getId());
|
||||
assertEquals(organizationEntity.getOwner(), organization.getOwner().getId());
|
||||
assertNull(organization.getRoles());
|
||||
@ -78,6 +78,7 @@ class BouncerContextConverterTest {
|
||||
TestObjectFactory.buildMemberRole(RoleId.ADMINISTRATOR, TestObjectFactory.randomString());
|
||||
|
||||
var organization = converter.toOrganization(organizationEntity, Set.of(memberRoleEntity));
|
||||
|
||||
assertEquals(organizationEntity.getId(), organization.getId());
|
||||
assertEquals(organizationEntity.getOwner(), organization.getOwner().getId());
|
||||
assertTrue(organization.getRoles().isEmpty());
|
||||
@ -90,6 +91,7 @@ class BouncerContextConverterTest {
|
||||
TestObjectFactory.buildMemberRole(RoleId.ADMINISTRATOR, organizationEntity.getId());
|
||||
|
||||
var organization = converter.toOrganization(organizationEntity, Set.of(memberRoleEntity));
|
||||
|
||||
assertEquals(organizationEntity.getId(), organization.getId());
|
||||
assertEquals(organizationEntity.getOwner(), organization.getOwner().getId());
|
||||
assertEquals(memberRoleEntity.getRoleId(), organization.getRoles().iterator().next().getId());
|
||||
|
Loading…
Reference in New Issue
Block a user