change RoleID to String (#66)

Co-authored-by: ggmaleva <ggmaleva@yandex.ru>
This commit is contained in:
Gregory 2024-02-08 11:17:02 +03:00 committed by GitHub
parent 388c38b0e8
commit 20ec7337b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 74 additions and 96 deletions

View File

@ -46,7 +46,7 @@
<dependency>
<groupId>dev.vality</groupId>
<artifactId>swag-organizations</artifactId>
<version>1.22-cd6cc10-server</version>
<version>1.25-de0cd06-server</version>
</dependency>
<dependency>
<groupId>dev.vality</groupId>

View File

@ -13,7 +13,6 @@ import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import javax.validation.constraints.Size;
import java.util.Objects;
@Slf4j
@ -147,11 +146,11 @@ public class OrgsController implements OrgsApi {
public ResponseEntity<Role> getOrgRole(
String requestId,
String orgId,
RoleId roleId) {
String roleId) {
log.info("Get organization id: requestId={}, orgId={}, roleId={}", requestId, orgId, roleId);
ResourceDto resource = ResourceDto.builder()
.orgId(orgId)
.roleId(roleId.getValue())
.roleId(roleId)
.build();
resourceAccessService.checkRights(resource);
return ResponseEntity.ok(organizationRoleService.get(orgId, roleId));
@ -187,7 +186,7 @@ public class OrgsController implements OrgsApi {
ResourceDto resource = ResourceDto.builder()
.orgId(orgId)
.memberId(userId)
.roleId(body.getRoleId().getValue())
.roleId(body.getRoleId())
.scopeResourceId(Objects.nonNull(body.getScope()) ? body.getScope().getResourceId() : null)
.build();
resourceAccessService.checkRights(resource);

View File

@ -5,7 +5,6 @@ import dev.vality.orgmanager.service.dto.MemberWithRoleDto;
import dev.vality.swag.organizations.model.MemberRole;
import dev.vality.swag.organizations.model.MemberRoleScope;
import dev.vality.swag.organizations.model.ResourceScopeId;
import dev.vality.swag.organizations.model.RoleId;
import org.springframework.stereotype.Service;
import java.util.Objects;
@ -36,7 +35,7 @@ public class MemberRoleConverter {
.orElse(null);
return new MemberRole()
.id(entity.getId())
.roleId(RoleId.fromValue(entity.getRoleId()))
.roleId(entity.getRoleId())
.scope(memberRoleScope);
}
@ -49,7 +48,7 @@ public class MemberRoleConverter {
.orElse(null);
return new MemberRole()
.id(memberWithRoleDto.getMemberRoleId())
.roleId(RoleId.fromValue(memberWithRoleDto.getRoleId()))
.roleId(memberWithRoleDto.getRoleId())
.scope(memberRoleScope);
}
}

View File

@ -3,23 +3,20 @@ package dev.vality.orgmanager.converter;
import dev.vality.orgmanager.entity.OrganizationRoleEntity;
import dev.vality.swag.organizations.model.ResourceScopeId;
import dev.vality.swag.organizations.model.Role;
import dev.vality.swag.organizations.model.RoleId;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
public class OrganizationRoleConverter {
public Role toDomain(OrganizationRoleEntity entity) {
return new Role()
.id(RoleId.fromValue(entity.getRoleId()))
.id(entity.getRoleId())
.name(entity.getName())
.scopes(entity.getPossibleScopes()
.stream()
.map(s -> ResourceScopeId.fromValue(s.getId()))
.collect(Collectors.toList()));
.toList());
}
}

View File

@ -8,7 +8,6 @@ import dev.vality.orgmanager.repository.OrganizationRepository;
import dev.vality.orgmanager.repository.OrganizationRoleRepository;
import dev.vality.swag.organizations.model.Role;
import dev.vality.swag.organizations.model.RoleAvailableListResult;
import dev.vality.swag.organizations.model.RoleId;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@ -17,8 +16,6 @@ import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
import static java.util.stream.Collectors.toList;
@Service
@RequiredArgsConstructor
public class OrganizationRoleService {
@ -27,12 +24,12 @@ public class OrganizationRoleService {
private final OrganizationRoleRepository organizationRoleRepository;
private final OrganizationRoleConverter organizationRoleConverter;
public Role get(String orgId, RoleId roleId) {
public Role get(String orgId, String roleId) {
if (!organizationRepository.existsById(orgId)) {
throw new ResourceNotFoundException();
}
OrganizationRoleEntity entity =
organizationRoleRepository.findByOrganizationIdAndRoleId(orgId, roleId.toString())
organizationRoleRepository.findByOrganizationIdAndRoleId(orgId, roleId)
.orElseThrow(ResourceNotFoundException::new);
return organizationRoleConverter.toDomain(entity);
@ -50,7 +47,7 @@ public class OrganizationRoleService {
List<Role> roles = entity.orElseThrow().getRoles()
.stream()
.map(organizationRoleConverter::toDomain)
.collect(toList());
.toList();
return ResponseEntity
.status(HttpStatus.OK)

View File

@ -26,9 +26,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import static java.util.stream.Collectors.toList;
@Slf4j
@Service
@ -85,7 +82,7 @@ public class OrganizationService {
private List<MemberRoleEntity> getMemberRolesInOrg(String orgId, MemberEntity memberEntity) {
return memberEntity.getRoles().stream()
.filter(memberRole -> isActiveOrgMemberRole(orgId, memberRole))
.collect(toList());
.toList();
}
private boolean isActiveOrgMemberRole(String orgId, MemberRoleEntity memberRole) {
@ -159,7 +156,7 @@ public class OrganizationService {
String continuationToken = getContinuationId(entities, limitEntities);
List<Organization> organizations = limitEntities
.stream().map(organizationConverter::toDomain)
.collect(toList());
.toList();
return new OrganizationSearchResult()
.continuationToken(continuationToken)
@ -180,7 +177,7 @@ public class OrganizationService {
}
return entities.stream()
.limit(limit)
.collect(Collectors.toList());
.toList();
}
private String getContinuationId(List<OrganizationEntity> entities, List<OrganizationEntity> limitEntities) {

View File

@ -56,7 +56,7 @@ public class ResourceAccessServiceImpl implements ResourceAccessService {
MemberRoleScope scope = memberRole.getScope();
bouncerContext.setRole(RoleDto.builder()
.scopeResourceId(Objects.nonNull(scope) ? scope.getResourceId() : null)
.roleId(memberRole.getRoleId().getValue())
.roleId(memberRole.getRoleId())
.build());
}
callBouncer(callerMethodName, bouncerContext);

View File

@ -89,7 +89,7 @@ public abstract class TestObjectFactory {
public static MemberRole testMemberRole() {
MemberRole memberRole = new MemberRole();
memberRole.setRoleId(RoleId.MANAGER);
memberRole.setRoleId("Manager");
return memberRole;
}
@ -165,15 +165,15 @@ public abstract class TestObjectFactory {
.organizationId(orgId)
.status("Pending")
.inviteeRoles(Set.of(
buildMemberRole(RoleId.ADMINISTRATOR, orgId),
buildMemberRole(RoleId.ACCOUNTANT, orgId)))
buildMemberRole("Administrator", orgId),
buildMemberRole("Accountant", orgId)))
.build();
}
public static MemberRoleEntity buildMemberRole(RoleId role, String orgId) {
public static MemberRoleEntity buildMemberRole(String role, String orgId) {
return MemberRoleEntity.builder()
.id(randomString())
.roleId(role.getValue())
.roleId(role)
.resourceId(randomString())
.scopeId(ResourceScopeId.SHOP.getValue())
.organizationId(orgId)
@ -181,10 +181,10 @@ public abstract class TestObjectFactory {
.build();
}
public static OrganizationRoleEntity buildOrganizationRole(RoleId role, String orgId) {
public static OrganizationRoleEntity buildOrganizationRole(String role, String orgId) {
return OrganizationRoleEntity.builder()
.id(randomString())
.roleId(role.getValue())
.roleId(role)
.organizationId(orgId)
.name(randomString())
.build();

View File

@ -10,7 +10,6 @@ import dev.vality.orgmanager.service.dto.ResourceDto;
import dev.vality.orgmanager.util.TestData;
import dev.vality.swag.organizations.model.InvitationRequest;
import dev.vality.swag.organizations.model.MemberRole;
import dev.vality.swag.organizations.model.RoleId;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.springframework.transaction.annotation.Transactional;
@ -81,7 +80,7 @@ public class OrgsControllerTest extends AbstractControllerTest {
MemberEntity memberEntity = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
OrganizationEntity organization = TestObjectFactory.buildOrganization(memberEntity);
MemberRoleEntity memberRoleEntity = TestObjectFactory.buildMemberRole(RoleId.ACCOUNTANT, organization.getId());
MemberRoleEntity memberRoleEntity = TestObjectFactory.buildMemberRole("Accountant", organization.getId());
MemberRoleEntity savedMemberRole = memberRoleRepository.save(
memberRoleEntity);
memberEntity.setRoles(Set.of(savedMemberRole));
@ -97,7 +96,7 @@ public class OrgsControllerTest extends AbstractControllerTest {
.header("X-Request-ID", "testRequestId"))
.andExpect(status().isCreated())
.andExpect(jsonPath("$.id").isNotEmpty())
.andExpect(jsonPath("$.roleId", equalTo(memberRole.getRoleId().getValue())))
.andExpect(jsonPath("$.roleId", equalTo(memberRole.getRoleId())))
.andExpect(jsonPath("$.scope.id", equalTo(memberRole.getScope().getId().getValue())))
.andExpect(jsonPath("$.scope.resourceId", equalTo(memberRole.getScope().getResourceId())));
@ -110,7 +109,7 @@ public class OrgsControllerTest extends AbstractControllerTest {
MemberEntity member = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
OrganizationEntity organization = TestObjectFactory.buildOrganization(member);
MemberRoleEntity savedMemberRole =
memberRoleRepository.save(TestObjectFactory.buildMemberRole(RoleId.ACCOUNTANT, organization.getId()));
memberRoleRepository.save(TestObjectFactory.buildMemberRole("Accountant", organization.getId()));
member.setRoles(Set.of(savedMemberRole));
MemberEntity savedMember = memberRepository.save(member);
OrganizationEntity savedOrganization = organizationRepository.save(organization);
@ -133,7 +132,7 @@ public class OrgsControllerTest extends AbstractControllerTest {
void removeMemberRoleWithOnlyOneRole() throws Exception {
MemberEntity memberEntity = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
OrganizationEntity organization = TestObjectFactory.buildOrganization(memberEntity);
MemberRoleEntity memberRoleEntity = TestObjectFactory.buildMemberRole(RoleId.ACCOUNTANT, organization.getId());
MemberRoleEntity memberRoleEntity = TestObjectFactory.buildMemberRole("Accountant", organization.getId());
MemberRoleEntity savedMemberRole = memberRoleRepository.save(
memberRoleEntity);
memberEntity.setRoles(Set.of(savedMemberRole));
@ -155,8 +154,8 @@ public class OrgsControllerTest extends AbstractControllerTest {
void removeMemberRole() throws Exception {
MemberEntity memberEntity = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
OrganizationEntity organization = TestObjectFactory.buildOrganization(memberEntity);
MemberRoleEntity memberRoleEntity = TestObjectFactory.buildMemberRole(RoleId.ACCOUNTANT, organization.getId());
MemberRoleEntity roleToRemove = TestObjectFactory.buildMemberRole(RoleId.MANAGER, organization.getId());
MemberRoleEntity memberRoleEntity = TestObjectFactory.buildMemberRole("Accountant", organization.getId());
MemberRoleEntity roleToRemove = TestObjectFactory.buildMemberRole("Manager", organization.getId());
List<MemberRoleEntity> roles = memberRoleRepository.saveAll(List.of(
memberRoleEntity, roleToRemove));
memberEntity.setRoles(new HashSet<>(roles));

View File

@ -115,7 +115,7 @@ public class UserControllerTest extends AbstractControllerTest {
assertEquals(savedOrg.getId(), organizationMembership.getOrg().getId());
assertEquals(userId, organizationMembership.getMember().getId());
List<String> actualRoles =
organizationMembership.getMember().getRoles().stream().map(MemberRole::getRoleId).map(RoleId::getValue)
organizationMembership.getMember().getRoles().stream().map(MemberRole::getRoleId)
.collect(Collectors.toList());
List<String> expectedRoles = savedInvitation.getInviteeRoles().stream().map(MemberRoleEntity::getRoleId)
.collect(Collectors.toList());
@ -147,7 +147,7 @@ public class UserControllerTest extends AbstractControllerTest {
assertEquals(savedOrg.getId(), organizationMembership.getOrg().getId());
assertEquals(userId, organizationMembership.getMember().getId());
List<String> actualRoles =
organizationMembership.getMember().getRoles().stream().map(MemberRole::getRoleId).map(RoleId::getValue)
organizationMembership.getMember().getRoles().stream().map(MemberRole::getRoleId)
.collect(Collectors.toList());
List<String> expectedRoles = savedInvitation.getInviteeRoles().stream().map(MemberRoleEntity::getRoleId)
.collect(Collectors.toList());

View File

@ -8,7 +8,6 @@ import dev.vality.orgmanager.TestObjectFactory;
import dev.vality.orgmanager.entity.MemberEntity;
import dev.vality.orgmanager.entity.MemberRoleEntity;
import dev.vality.orgmanager.entity.OrganizationEntity;
import dev.vality.swag.organizations.model.RoleId;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -39,7 +38,7 @@ class BouncerContextConverterTest {
OrgRole actual = converter.toOrgRole(entity);
OrgRole expected = new OrgRole()
.setId(RoleId.ADMINISTRATOR.getValue())
.setId("Administrator")
.setScope(new OrgRoleScope()
.setShop(new Entity().setId("resource")));
@ -57,7 +56,7 @@ class BouncerContextConverterTest {
OrgRole actual = converter.toOrgRole(entity);
OrgRole expected = new OrgRole()
.setId(RoleId.ADMINISTRATOR.getValue())
.setId("Administrator")
.setScope(null);
assertEquals(expected, actual);
@ -91,7 +90,7 @@ class BouncerContextConverterTest {
void shouldConvertToOrganizationWithoutRolesAnotherOrganization() {
OrganizationEntity organizationEntity = TestObjectFactory.buildOrganization();
MemberRoleEntity memberRoleEntity =
TestObjectFactory.buildMemberRole(RoleId.ADMINISTRATOR, TestObjectFactory.randomString());
TestObjectFactory.buildMemberRole("Administrator", TestObjectFactory.randomString());
var organization = converter.toOrganization(organizationEntity, Set.of(memberRoleEntity));
@ -105,7 +104,7 @@ class BouncerContextConverterTest {
void shouldConvertToOrganization() {
OrganizationEntity organizationEntity = TestObjectFactory.buildOrganization();
MemberRoleEntity memberRoleEntity =
TestObjectFactory.buildMemberRole(RoleId.ADMINISTRATOR, organizationEntity.getId());
TestObjectFactory.buildMemberRole("Administrator", organizationEntity.getId());
var organization = converter.toOrganization(organizationEntity, Set.of(memberRoleEntity));

View File

@ -4,7 +4,6 @@ import dev.vality.orgmanager.entity.MemberRoleEntity;
import dev.vality.swag.organizations.model.MemberRole;
import dev.vality.swag.organizations.model.MemberRoleScope;
import dev.vality.swag.organizations.model.ResourceScopeId;
import dev.vality.swag.organizations.model.RoleId;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -23,7 +22,7 @@ class MemberRoleConverterTest {
void shouldConvertToEntityWithoutScope() {
// Given
MemberRole role = new MemberRole()
.roleId(RoleId.ADMINISTRATOR);
.roleId("Administrator");
// When
MemberRoleEntity entity = converter.toEntity(role, "org");
@ -45,7 +44,7 @@ class MemberRoleConverterTest {
void shouldConvertToEntity() {
// Given
MemberRole role = new MemberRole()
.roleId(RoleId.ADMINISTRATOR)
.roleId("Administrator")
.scope(new MemberRoleScope()
.resourceId("resource")
.id(ResourceScopeId.SHOP));
@ -84,7 +83,7 @@ class MemberRoleConverterTest {
// Then
MemberRole expected = new MemberRole()
.id(entity.getId())
.roleId(RoleId.ADMINISTRATOR);
.roleId("Administrator");
assertThat(role).usingRecursiveComparison().isEqualTo(expected);
}
@ -106,7 +105,7 @@ class MemberRoleConverterTest {
// Then
MemberRole expected = new MemberRole()
.id(entity.getId())
.roleId(RoleId.ADMINISTRATOR)
.roleId("Administrator")
.scope(new MemberRoleScope()
.resourceId("resource")
.id(ResourceScopeId.SHOP));

View File

@ -4,7 +4,6 @@ import dev.vality.orgmanager.entity.OrganizationRoleEntity;
import dev.vality.orgmanager.entity.ScopeEntity;
import dev.vality.swag.organizations.model.ResourceScopeId;
import dev.vality.swag.organizations.model.Role;
import dev.vality.swag.organizations.model.RoleId;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -40,7 +39,7 @@ class OrganizationRoleConverterTest {
// Then
Role expected = new Role()
.id(RoleId.ADMINISTRATOR)
.id("Administrator")
.name("name")
.scopes(List.of(ResourceScopeId.SHOP));

View File

@ -8,7 +8,6 @@ import dev.vality.orgmanager.repository.OrganizationRepository;
import dev.vality.orgmanager.repository.OrganizationRoleRepository;
import dev.vality.swag.organizations.model.Role;
import dev.vality.swag.organizations.model.RoleAvailableListResult;
import dev.vality.swag.organizations.model.RoleId;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
@ -85,10 +84,10 @@ public class OrganizationRoleServiceTest {
OrganizationRoleEntity organizationRoleEntity = new OrganizationRoleEntity();
Role role = new Role();
String orgId = "orgId";
RoleId roleId = RoleId.ADMINISTRATOR;
String roleId = "Administrator";
when(organizationRepository.existsById(orgId))
.thenReturn(true);
when(organizationRoleRepository.findByOrganizationIdAndRoleId(orgId, roleId.getValue()))
when(organizationRoleRepository.findByOrganizationIdAndRoleId(orgId, roleId))
.thenReturn(Optional.of(organizationRoleEntity));
when(organizationRoleConverter.toDomain(organizationRoleEntity))
.thenReturn(role);
@ -102,7 +101,7 @@ public class OrganizationRoleServiceTest {
@Test
void shouldReturnNotFoundIfOrganizationDoesNotExist() {
String orgId = "orgId";
RoleId roleId = RoleId.ADMINISTRATOR;
String roleId = "Administrator";
when(organizationRepository.existsById(orgId))
.thenReturn(false);

View File

@ -39,16 +39,16 @@ public class OrganizationServiceIntegrationTest extends AbstractRepositoryTest {
// Given
MemberEntity member = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
OrganizationEntity organization = TestObjectFactory.buildOrganization(member);
MemberRoleEntity nonActiveRoleInOrg = buildMemberRole(RoleId.ACCOUNTANT, organization.getId());
MemberRoleEntity nonActiveRoleInOrg = buildMemberRole("Accountant", organization.getId());
nonActiveRoleInOrg.setActive(Boolean.FALSE);
MemberRoleEntity savedMemberRoleNonActiveInOrg = memberRoleRepository.save(nonActiveRoleInOrg);
MemberRoleEntity activeRoleInOrg = buildMemberRole(RoleId.ACCOUNTANT, organization.getId());
MemberRoleEntity activeRoleInOrg = buildMemberRole("Accountant", organization.getId());
activeRoleInOrg.setActive(Boolean.TRUE);
MemberRoleEntity savedMemberRoleInOrg =
memberRoleRepository.save(activeRoleInOrg);
MemberRoleEntity savedMemberRoleInAnotherOrg =
memberRoleRepository
.save(TestObjectFactory.buildMemberRole(RoleId.ACCOUNTANT, TestObjectFactory.randomString()));
.save(TestObjectFactory.buildMemberRole("Accountant", TestObjectFactory.randomString()));
member.setRoles(Set.of(savedMemberRoleNonActiveInOrg, savedMemberRoleInOrg, savedMemberRoleInAnotherOrg));
MemberEntity savedMember = memberRepository.save(member);
OrganizationEntity savedOrganization = organizationRepository.save(organization);
@ -70,7 +70,7 @@ public class OrganizationServiceIntegrationTest extends AbstractRepositoryTest {
void shouldThrowAccessDeniedExceptionOnJoinOrgTest() {
MemberEntity memberEntity = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
OrganizationEntity organization = TestObjectFactory.buildOrganization(memberEntity);
MemberRoleEntity memberRole = buildMemberRole(RoleId.ACCOUNTANT, organization.getId());
MemberRoleEntity memberRole = buildMemberRole("Accountant", organization.getId());
memberRole.setActive(Boolean.FALSE);
MemberRoleEntity savedMemberRole = memberRoleRepository.save(memberRole);
memberEntity.setRoles(Set.of(savedMemberRole));
@ -97,7 +97,7 @@ public class OrganizationServiceIntegrationTest extends AbstractRepositoryTest {
alreadyAcceptedInvitation.setAcceptedMemberId(TestObjectFactory.randomString());
alreadyAcceptedInvitation.setStatus(InvitationStatusName.ACCEPTED.getValue());
invitationRepository.save(alreadyAcceptedInvitation);
MemberRoleEntity memberRole = buildMemberRole(RoleId.ACCOUNTANT, savedOrganization.getId());
MemberRoleEntity memberRole = buildMemberRole("Accountant", savedOrganization.getId());
memberRole.setActive(Boolean.FALSE);
MemberRoleEntity savedMemberRole = memberRoleRepository.save(memberRole);
memberEntity.setRoles(Set.of(savedMemberRole));
@ -114,7 +114,7 @@ public class OrganizationServiceIntegrationTest extends AbstractRepositoryTest {
void shouldJoinExistMember() {
MemberEntity memberEntity = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
OrganizationEntity organization = TestObjectFactory.buildOrganization(memberEntity);
MemberRoleEntity memberRole = buildMemberRole(RoleId.ACCOUNTANT, organization.getId());
MemberRoleEntity memberRole = buildMemberRole("Accountant", organization.getId());
memberRole.setActive(Boolean.FALSE);
MemberRoleEntity savedMemberRole = memberRoleRepository.save(memberRole);
memberEntity.setRoles(Set.of(savedMemberRole));
@ -130,7 +130,6 @@ public class OrganizationServiceIntegrationTest extends AbstractRepositoryTest {
assertEquals(savedMember.getId(), organizationMembership.getMember().getId());
List<String> actualRoles = organizationMembership.getMember().getRoles().stream()
.map(MemberRole::getRoleId)
.map(RoleId::getValue)
.collect(Collectors.toList());
List<String> expectedRoles = savedInvitation.getInviteeRoles().stream()
.map(MemberRoleEntity::getRoleId)
@ -155,7 +154,6 @@ public class OrganizationServiceIntegrationTest extends AbstractRepositoryTest {
assertEquals(userId, organizationMembership.getMember().getId());
List<String> actualRoles = organizationMembership.getMember().getRoles().stream()
.map(MemberRole::getRoleId)
.map(RoleId::getValue)
.collect(Collectors.toList());
List<String> expectedRoles = savedInvitation.getInviteeRoles().stream()
.map(MemberRoleEntity::getRoleId)
@ -171,7 +169,7 @@ public class OrganizationServiceIntegrationTest extends AbstractRepositoryTest {
void shouldExpelOrgMember() {
MemberEntity member = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
OrganizationEntity organization = TestObjectFactory.buildOrganization(member);
MemberRoleEntity activeRoleInOrg = buildMemberRole(RoleId.ACCOUNTANT, organization.getId());
MemberRoleEntity activeRoleInOrg = buildMemberRole("Accountant", organization.getId());
activeRoleInOrg.setActive(Boolean.TRUE);
MemberRoleEntity savedMemberRole = memberRoleRepository.save(activeRoleInOrg);
member.setRoles(Set.of(savedMemberRole));
@ -197,7 +195,7 @@ public class OrganizationServiceIntegrationTest extends AbstractRepositoryTest {
void shouldNotReturnOrganizationsAfterExpelOrgMember() {
MemberEntity member = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
OrganizationEntity organization = TestObjectFactory.buildOrganization(member);
MemberRoleEntity activeRoleInOrg = buildMemberRole(RoleId.ACCOUNTANT, organization.getId());
MemberRoleEntity activeRoleInOrg = buildMemberRole("Accountant", organization.getId());
activeRoleInOrg.setActive(Boolean.TRUE);
MemberRoleEntity savedMemberRole = memberRoleRepository.save(activeRoleInOrg);
member.setRoles(Set.of(savedMemberRole));
@ -223,20 +221,20 @@ public class OrganizationServiceIntegrationTest extends AbstractRepositoryTest {
MemberEntity member1 = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
MemberEntity member2 = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
OrganizationEntity organization = TestObjectFactory.buildOrganization(Set.of(member1, member2));
MemberRoleEntity activeMember1RoleInOrg = buildMemberRole(RoleId.ACCOUNTANT, organization.getId());
MemberRoleEntity activeMember1RoleInOrg = buildMemberRole("Accountant", organization.getId());
activeMember1RoleInOrg.setActive(Boolean.TRUE);
MemberRoleEntity savedMember1Role = memberRoleRepository.save(activeMember1RoleInOrg);
member1.setRoles(Set.of(savedMember1Role));
MemberRoleEntity activeMember2RoleInOrg = buildMemberRole(RoleId.ACCOUNTANT, organization.getId());
MemberRoleEntity activeMember2RoleInOrg = buildMemberRole("Accountant", organization.getId());
activeMember2RoleInOrg.setActive(Boolean.TRUE);
MemberRoleEntity savedActiveMember2Role = memberRoleRepository.save(activeMember2RoleInOrg);
MemberRoleEntity nonActiveMember2RoleInOrg = buildMemberRole(RoleId.ACCOUNTANT, organization.getId());
MemberRoleEntity nonActiveMember2RoleInOrg = buildMemberRole("Accountant", organization.getId());
nonActiveMember2RoleInOrg.setActive(Boolean.FALSE);
MemberRoleEntity savedNonActiveMember2Role = memberRoleRepository.save(nonActiveMember2RoleInOrg);
member2.setRoles(Set.of(savedActiveMember2Role, savedNonActiveMember2Role));
MemberEntity anotherMember = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
OrganizationEntity anotherOrganization = TestObjectFactory.buildOrganization(Set.of(anotherMember));
MemberRoleEntity activeAnotherMemberRoleInOrg = buildMemberRole(RoleId.ACCOUNTANT, anotherOrganization.getId());
MemberRoleEntity activeAnotherMemberRoleInOrg = buildMemberRole("Accountant", anotherOrganization.getId());
activeAnotherMemberRoleInOrg.setActive(Boolean.TRUE);
MemberRoleEntity savedAnotherRole = memberRoleRepository.save(activeAnotherMemberRoleInOrg);
anotherMember.setRoles(Set.of(savedAnotherRole));
@ -265,7 +263,7 @@ public class OrganizationServiceIntegrationTest extends AbstractRepositoryTest {
MemberEntity member = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
OrganizationEntity organization = TestObjectFactory.buildOrganization(member);
MemberRoleEntity role =
memberRoleRepository.save(TestObjectFactory.buildMemberRole(RoleId.ACCOUNTANT, organization.getId()));
memberRoleRepository.save(TestObjectFactory.buildMemberRole("Accountant", organization.getId()));
member.setRoles(Set.of(role));
MemberEntity savedMember = memberRepository.save(member);
OrganizationEntity savedOrganization = organizationRepository.save(organization);
@ -281,9 +279,9 @@ public class OrganizationServiceIntegrationTest extends AbstractRepositoryTest {
MemberEntity memberEntity = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
OrganizationEntity organization = TestObjectFactory.buildOrganization(memberEntity);
MemberRoleEntity role =
memberRoleRepository.save(TestObjectFactory.buildMemberRole(RoleId.ACCOUNTANT, organization.getId()));
memberRoleRepository.save(TestObjectFactory.buildMemberRole("Accountant", organization.getId()));
MemberRoleEntity roleToRemove =
memberRoleRepository.save(TestObjectFactory.buildMemberRole(RoleId.MANAGER, organization.getId()));
memberRoleRepository.save(TestObjectFactory.buildMemberRole("Manager", organization.getId()));
memberEntity.setRoles(Set.of(role, roleToRemove));
MemberEntity savedMember = memberRepository.save(memberEntity);
OrganizationEntity savedOrganization = organizationRepository.save(organization);

View File

@ -8,7 +8,6 @@ import dev.vality.orgmanager.service.dto.BouncerContextDto;
import dev.vality.orgmanager.service.dto.ResourceDto;
import dev.vality.swag.organizations.model.MemberRole;
import dev.vality.swag.organizations.model.MemberRoleScope;
import dev.vality.swag.organizations.model.RoleId;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@ -138,7 +137,7 @@ class ResourceAccessServiceImplTest {
when(memberRoleService.findById(resource.getMemberRoleId()))
.thenReturn(
new MemberRole()
.roleId(RoleId.MANAGER)
.roleId("Manager")
.scope(new MemberRoleScope().resourceId(TestObjectFactory.randomString()))
);

View File

@ -6,7 +6,6 @@ import dev.vality.orgmanager.entity.MemberRoleEntity;
import dev.vality.orgmanager.entity.OrganizationEntity;
import dev.vality.orgmanager.repository.AbstractRepositoryTest;
import dev.vality.orgmanager.service.model.UserInfo;
import dev.vality.swag.organizations.model.RoleId;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@ -14,9 +13,7 @@ import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;
class UserServiceImplTest extends AbstractRepositoryTest {
@ -65,7 +62,7 @@ class UserServiceImplTest extends AbstractRepositoryTest {
String memberId = TestObjectFactory.randomString();
var member = TestObjectFactory.testMemberEntity(memberId);
OrganizationEntity organization = TestObjectFactory.buildOrganization(member);
MemberRoleEntity memberRole = TestObjectFactory.buildMemberRole(RoleId.ACCOUNTANT, organization.getId());
MemberRoleEntity memberRole = TestObjectFactory.buildMemberRole("Accountant", organization.getId());
memberRoleRepository.save(memberRole);
member.setRoles(Set.of(memberRole));
memberRepository.save(member);
@ -84,7 +81,7 @@ class UserServiceImplTest extends AbstractRepositoryTest {
String memberId = TestObjectFactory.randomString();
var member = TestObjectFactory.testMemberEntity(memberId);
OrganizationEntity organization = TestObjectFactory.buildOrganization(member);
MemberRoleEntity memberRole = TestObjectFactory.buildMemberRole(RoleId.ACCOUNTANT, organization.getId());
MemberRoleEntity memberRole = TestObjectFactory.buildMemberRole("Accountant", organization.getId());
OrganizationEntity ownedOrganization = TestObjectFactory.buildOrganization();
ownedOrganization.setOwner(memberId);
memberRoleRepository.save(memberRole);
@ -111,9 +108,9 @@ class UserServiceImplTest extends AbstractRepositoryTest {
OrganizationEntity organization = TestObjectFactory.buildOrganization(member);
organization.setOwner(memberId);
organization.setRoles(
Set.of(TestObjectFactory.buildOrganizationRole(RoleId.ACCOUNTANT, organization.getId()))
Set.of(TestObjectFactory.buildOrganizationRole("Accountant", organization.getId()))
);
MemberRoleEntity memberRole = TestObjectFactory.buildMemberRole(RoleId.ACCOUNTANT, organization.getId());
MemberRoleEntity memberRole = TestObjectFactory.buildMemberRole("Accountant", organization.getId());
memberRoleRepository.save(memberRole);
member.setRoles(Set.of(memberRole));
memberRepository.save(member);

View File

@ -23,7 +23,7 @@ public class TestData {
.id(memberId)
.email("email")
.roles(Set.of(MemberRoleEntity.builder()
.id(RoleId.ADMINISTRATOR.getValue())
.id("Accountant")
.organizationId(organizationId)
.roleId("Accountant")
.scopeId("Shop")
@ -67,14 +67,14 @@ public class TestData {
.inviteeRoles(Set.of(
MemberRoleEntity.builder()
.id("role1")
.roleId(RoleId.ADMINISTRATOR.getValue())
.roleId("Administrator")
.resourceId("resource1")
.scopeId(ResourceScopeId.SHOP.getValue())
.organizationId(organizationId)
.build(),
MemberRoleEntity.builder()
.id("role2")
.roleId(RoleId.MANAGER.getValue())
.roleId("Manager")
.resourceId("resource2")
.scopeId(ResourceScopeId.SHOP.getValue())
.organizationId(organizationId)
@ -100,7 +100,7 @@ public class TestData {
public static MemberRole buildMemberRole() {
MemberRole memberRole = new MemberRole();
memberRole.setRoleId(RoleId.ADMINISTRATOR);
memberRole.setRoleId("Administrator");
MemberRoleScope memberRoleScope = new MemberRoleScope();
memberRoleScope.setId(ResourceScopeId.SHOP);
memberRoleScope.setResourceId("testResourceIdKek");