mirror of
https://github.com/valitydev/org-manager.git
synced 2024-11-06 00:15:23 +00:00
change RoleID to String (#66)
Co-authored-by: ggmaleva <ggmaleva@yandex.ru>
This commit is contained in:
parent
388c38b0e8
commit
20ec7337b3
2
pom.xml
2
pom.xml
@ -46,7 +46,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>dev.vality</groupId>
|
<groupId>dev.vality</groupId>
|
||||||
<artifactId>swag-organizations</artifactId>
|
<artifactId>swag-organizations</artifactId>
|
||||||
<version>1.22-cd6cc10-server</version>
|
<version>1.25-de0cd06-server</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>dev.vality</groupId>
|
<groupId>dev.vality</groupId>
|
||||||
|
@ -13,7 +13,6 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ -147,11 +146,11 @@ public class OrgsController implements OrgsApi {
|
|||||||
public ResponseEntity<Role> getOrgRole(
|
public ResponseEntity<Role> getOrgRole(
|
||||||
String requestId,
|
String requestId,
|
||||||
String orgId,
|
String orgId,
|
||||||
RoleId roleId) {
|
String roleId) {
|
||||||
log.info("Get organization id: requestId={}, orgId={}, roleId={}", requestId, orgId, roleId);
|
log.info("Get organization id: requestId={}, orgId={}, roleId={}", requestId, orgId, roleId);
|
||||||
ResourceDto resource = ResourceDto.builder()
|
ResourceDto resource = ResourceDto.builder()
|
||||||
.orgId(orgId)
|
.orgId(orgId)
|
||||||
.roleId(roleId.getValue())
|
.roleId(roleId)
|
||||||
.build();
|
.build();
|
||||||
resourceAccessService.checkRights(resource);
|
resourceAccessService.checkRights(resource);
|
||||||
return ResponseEntity.ok(organizationRoleService.get(orgId, roleId));
|
return ResponseEntity.ok(organizationRoleService.get(orgId, roleId));
|
||||||
@ -187,7 +186,7 @@ public class OrgsController implements OrgsApi {
|
|||||||
ResourceDto resource = ResourceDto.builder()
|
ResourceDto resource = ResourceDto.builder()
|
||||||
.orgId(orgId)
|
.orgId(orgId)
|
||||||
.memberId(userId)
|
.memberId(userId)
|
||||||
.roleId(body.getRoleId().getValue())
|
.roleId(body.getRoleId())
|
||||||
.scopeResourceId(Objects.nonNull(body.getScope()) ? body.getScope().getResourceId() : null)
|
.scopeResourceId(Objects.nonNull(body.getScope()) ? body.getScope().getResourceId() : null)
|
||||||
.build();
|
.build();
|
||||||
resourceAccessService.checkRights(resource);
|
resourceAccessService.checkRights(resource);
|
||||||
|
@ -5,7 +5,6 @@ import dev.vality.orgmanager.service.dto.MemberWithRoleDto;
|
|||||||
import dev.vality.swag.organizations.model.MemberRole;
|
import dev.vality.swag.organizations.model.MemberRole;
|
||||||
import dev.vality.swag.organizations.model.MemberRoleScope;
|
import dev.vality.swag.organizations.model.MemberRoleScope;
|
||||||
import dev.vality.swag.organizations.model.ResourceScopeId;
|
import dev.vality.swag.organizations.model.ResourceScopeId;
|
||||||
import dev.vality.swag.organizations.model.RoleId;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -36,7 +35,7 @@ public class MemberRoleConverter {
|
|||||||
.orElse(null);
|
.orElse(null);
|
||||||
return new MemberRole()
|
return new MemberRole()
|
||||||
.id(entity.getId())
|
.id(entity.getId())
|
||||||
.roleId(RoleId.fromValue(entity.getRoleId()))
|
.roleId(entity.getRoleId())
|
||||||
.scope(memberRoleScope);
|
.scope(memberRoleScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +48,7 @@ public class MemberRoleConverter {
|
|||||||
.orElse(null);
|
.orElse(null);
|
||||||
return new MemberRole()
|
return new MemberRole()
|
||||||
.id(memberWithRoleDto.getMemberRoleId())
|
.id(memberWithRoleDto.getMemberRoleId())
|
||||||
.roleId(RoleId.fromValue(memberWithRoleDto.getRoleId()))
|
.roleId(memberWithRoleDto.getRoleId())
|
||||||
.scope(memberRoleScope);
|
.scope(memberRoleScope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,23 +3,20 @@ package dev.vality.orgmanager.converter;
|
|||||||
import dev.vality.orgmanager.entity.OrganizationRoleEntity;
|
import dev.vality.orgmanager.entity.OrganizationRoleEntity;
|
||||||
import dev.vality.swag.organizations.model.ResourceScopeId;
|
import dev.vality.swag.organizations.model.ResourceScopeId;
|
||||||
import dev.vality.swag.organizations.model.Role;
|
import dev.vality.swag.organizations.model.Role;
|
||||||
import dev.vality.swag.organizations.model.RoleId;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class OrganizationRoleConverter {
|
public class OrganizationRoleConverter {
|
||||||
|
|
||||||
public Role toDomain(OrganizationRoleEntity entity) {
|
public Role toDomain(OrganizationRoleEntity entity) {
|
||||||
return new Role()
|
return new Role()
|
||||||
.id(RoleId.fromValue(entity.getRoleId()))
|
.id(entity.getRoleId())
|
||||||
.name(entity.getName())
|
.name(entity.getName())
|
||||||
.scopes(entity.getPossibleScopes()
|
.scopes(entity.getPossibleScopes()
|
||||||
.stream()
|
.stream()
|
||||||
.map(s -> ResourceScopeId.fromValue(s.getId()))
|
.map(s -> ResourceScopeId.fromValue(s.getId()))
|
||||||
.collect(Collectors.toList()));
|
.toList());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,7 +8,6 @@ import dev.vality.orgmanager.repository.OrganizationRepository;
|
|||||||
import dev.vality.orgmanager.repository.OrganizationRoleRepository;
|
import dev.vality.orgmanager.repository.OrganizationRoleRepository;
|
||||||
import dev.vality.swag.organizations.model.Role;
|
import dev.vality.swag.organizations.model.Role;
|
||||||
import dev.vality.swag.organizations.model.RoleAvailableListResult;
|
import dev.vality.swag.organizations.model.RoleAvailableListResult;
|
||||||
import dev.vality.swag.organizations.model.RoleId;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
@ -17,8 +16,6 @@ import org.springframework.stereotype.Service;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import static java.util.stream.Collectors.toList;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class OrganizationRoleService {
|
public class OrganizationRoleService {
|
||||||
@ -27,12 +24,12 @@ public class OrganizationRoleService {
|
|||||||
private final OrganizationRoleRepository organizationRoleRepository;
|
private final OrganizationRoleRepository organizationRoleRepository;
|
||||||
private final OrganizationRoleConverter organizationRoleConverter;
|
private final OrganizationRoleConverter organizationRoleConverter;
|
||||||
|
|
||||||
public Role get(String orgId, RoleId roleId) {
|
public Role get(String orgId, String roleId) {
|
||||||
if (!organizationRepository.existsById(orgId)) {
|
if (!organizationRepository.existsById(orgId)) {
|
||||||
throw new ResourceNotFoundException();
|
throw new ResourceNotFoundException();
|
||||||
}
|
}
|
||||||
OrganizationRoleEntity entity =
|
OrganizationRoleEntity entity =
|
||||||
organizationRoleRepository.findByOrganizationIdAndRoleId(orgId, roleId.toString())
|
organizationRoleRepository.findByOrganizationIdAndRoleId(orgId, roleId)
|
||||||
.orElseThrow(ResourceNotFoundException::new);
|
.orElseThrow(ResourceNotFoundException::new);
|
||||||
|
|
||||||
return organizationRoleConverter.toDomain(entity);
|
return organizationRoleConverter.toDomain(entity);
|
||||||
@ -50,7 +47,7 @@ public class OrganizationRoleService {
|
|||||||
List<Role> roles = entity.orElseThrow().getRoles()
|
List<Role> roles = entity.orElseThrow().getRoles()
|
||||||
.stream()
|
.stream()
|
||||||
.map(organizationRoleConverter::toDomain)
|
.map(organizationRoleConverter::toDomain)
|
||||||
.collect(toList());
|
.toList();
|
||||||
|
|
||||||
return ResponseEntity
|
return ResponseEntity
|
||||||
.status(HttpStatus.OK)
|
.status(HttpStatus.OK)
|
||||||
|
@ -26,9 +26,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static java.util.stream.Collectors.toList;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@ -85,7 +82,7 @@ public class OrganizationService {
|
|||||||
private List<MemberRoleEntity> getMemberRolesInOrg(String orgId, MemberEntity memberEntity) {
|
private List<MemberRoleEntity> getMemberRolesInOrg(String orgId, MemberEntity memberEntity) {
|
||||||
return memberEntity.getRoles().stream()
|
return memberEntity.getRoles().stream()
|
||||||
.filter(memberRole -> isActiveOrgMemberRole(orgId, memberRole))
|
.filter(memberRole -> isActiveOrgMemberRole(orgId, memberRole))
|
||||||
.collect(toList());
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isActiveOrgMemberRole(String orgId, MemberRoleEntity memberRole) {
|
private boolean isActiveOrgMemberRole(String orgId, MemberRoleEntity memberRole) {
|
||||||
@ -159,7 +156,7 @@ public class OrganizationService {
|
|||||||
String continuationToken = getContinuationId(entities, limitEntities);
|
String continuationToken = getContinuationId(entities, limitEntities);
|
||||||
List<Organization> organizations = limitEntities
|
List<Organization> organizations = limitEntities
|
||||||
.stream().map(organizationConverter::toDomain)
|
.stream().map(organizationConverter::toDomain)
|
||||||
.collect(toList());
|
.toList();
|
||||||
|
|
||||||
return new OrganizationSearchResult()
|
return new OrganizationSearchResult()
|
||||||
.continuationToken(continuationToken)
|
.continuationToken(continuationToken)
|
||||||
@ -180,7 +177,7 @@ public class OrganizationService {
|
|||||||
}
|
}
|
||||||
return entities.stream()
|
return entities.stream()
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getContinuationId(List<OrganizationEntity> entities, List<OrganizationEntity> limitEntities) {
|
private String getContinuationId(List<OrganizationEntity> entities, List<OrganizationEntity> limitEntities) {
|
||||||
|
@ -56,7 +56,7 @@ public class ResourceAccessServiceImpl implements ResourceAccessService {
|
|||||||
MemberRoleScope scope = memberRole.getScope();
|
MemberRoleScope scope = memberRole.getScope();
|
||||||
bouncerContext.setRole(RoleDto.builder()
|
bouncerContext.setRole(RoleDto.builder()
|
||||||
.scopeResourceId(Objects.nonNull(scope) ? scope.getResourceId() : null)
|
.scopeResourceId(Objects.nonNull(scope) ? scope.getResourceId() : null)
|
||||||
.roleId(memberRole.getRoleId().getValue())
|
.roleId(memberRole.getRoleId())
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
callBouncer(callerMethodName, bouncerContext);
|
callBouncer(callerMethodName, bouncerContext);
|
||||||
|
@ -89,7 +89,7 @@ public abstract class TestObjectFactory {
|
|||||||
|
|
||||||
public static MemberRole testMemberRole() {
|
public static MemberRole testMemberRole() {
|
||||||
MemberRole memberRole = new MemberRole();
|
MemberRole memberRole = new MemberRole();
|
||||||
memberRole.setRoleId(RoleId.MANAGER);
|
memberRole.setRoleId("Manager");
|
||||||
return memberRole;
|
return memberRole;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,15 +165,15 @@ public abstract class TestObjectFactory {
|
|||||||
.organizationId(orgId)
|
.organizationId(orgId)
|
||||||
.status("Pending")
|
.status("Pending")
|
||||||
.inviteeRoles(Set.of(
|
.inviteeRoles(Set.of(
|
||||||
buildMemberRole(RoleId.ADMINISTRATOR, orgId),
|
buildMemberRole("Administrator", orgId),
|
||||||
buildMemberRole(RoleId.ACCOUNTANT, orgId)))
|
buildMemberRole("Accountant", orgId)))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MemberRoleEntity buildMemberRole(RoleId role, String orgId) {
|
public static MemberRoleEntity buildMemberRole(String role, String orgId) {
|
||||||
return MemberRoleEntity.builder()
|
return MemberRoleEntity.builder()
|
||||||
.id(randomString())
|
.id(randomString())
|
||||||
.roleId(role.getValue())
|
.roleId(role)
|
||||||
.resourceId(randomString())
|
.resourceId(randomString())
|
||||||
.scopeId(ResourceScopeId.SHOP.getValue())
|
.scopeId(ResourceScopeId.SHOP.getValue())
|
||||||
.organizationId(orgId)
|
.organizationId(orgId)
|
||||||
@ -181,10 +181,10 @@ public abstract class TestObjectFactory {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OrganizationRoleEntity buildOrganizationRole(RoleId role, String orgId) {
|
public static OrganizationRoleEntity buildOrganizationRole(String role, String orgId) {
|
||||||
return OrganizationRoleEntity.builder()
|
return OrganizationRoleEntity.builder()
|
||||||
.id(randomString())
|
.id(randomString())
|
||||||
.roleId(role.getValue())
|
.roleId(role)
|
||||||
.organizationId(orgId)
|
.organizationId(orgId)
|
||||||
.name(randomString())
|
.name(randomString())
|
||||||
.build();
|
.build();
|
||||||
|
@ -10,7 +10,6 @@ import dev.vality.orgmanager.service.dto.ResourceDto;
|
|||||||
import dev.vality.orgmanager.util.TestData;
|
import dev.vality.orgmanager.util.TestData;
|
||||||
import dev.vality.swag.organizations.model.InvitationRequest;
|
import dev.vality.swag.organizations.model.InvitationRequest;
|
||||||
import dev.vality.swag.organizations.model.MemberRole;
|
import dev.vality.swag.organizations.model.MemberRole;
|
||||||
import dev.vality.swag.organizations.model.RoleId;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.ArgumentMatchers;
|
import org.mockito.ArgumentMatchers;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@ -81,7 +80,7 @@ public class OrgsControllerTest extends AbstractControllerTest {
|
|||||||
|
|
||||||
MemberEntity memberEntity = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
MemberEntity memberEntity = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
||||||
OrganizationEntity organization = TestObjectFactory.buildOrganization(memberEntity);
|
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 savedMemberRole = memberRoleRepository.save(
|
||||||
memberRoleEntity);
|
memberRoleEntity);
|
||||||
memberEntity.setRoles(Set.of(savedMemberRole));
|
memberEntity.setRoles(Set.of(savedMemberRole));
|
||||||
@ -91,13 +90,13 @@ public class OrgsControllerTest extends AbstractControllerTest {
|
|||||||
MemberRole memberRole = TestData.buildMemberRole();
|
MemberRole memberRole = TestData.buildMemberRole();
|
||||||
|
|
||||||
mockMvc.perform(post(String.format("/orgs/%s/members/%s/roles", savedOrganization.getId(), savedMember.getId()))
|
mockMvc.perform(post(String.format("/orgs/%s/members/%s/roles", savedOrganization.getId(), savedMember.getId()))
|
||||||
.contentType("application/json")
|
.contentType("application/json")
|
||||||
.content(objectMapper.writeValueAsString(memberRole))
|
.content(objectMapper.writeValueAsString(memberRole))
|
||||||
.header("Authorization", "Bearer " + generateRbkAdminJwt())
|
.header("Authorization", "Bearer " + generateRbkAdminJwt())
|
||||||
.header("X-Request-ID", "testRequestId"))
|
.header("X-Request-ID", "testRequestId"))
|
||||||
.andExpect(status().isCreated())
|
.andExpect(status().isCreated())
|
||||||
.andExpect(jsonPath("$.id").isNotEmpty())
|
.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.id", equalTo(memberRole.getScope().getId().getValue())))
|
||||||
.andExpect(jsonPath("$.scope.resourceId", equalTo(memberRole.getScope().getResourceId())));
|
.andExpect(jsonPath("$.scope.resourceId", equalTo(memberRole.getScope().getResourceId())));
|
||||||
|
|
||||||
@ -110,7 +109,7 @@ public class OrgsControllerTest extends AbstractControllerTest {
|
|||||||
MemberEntity member = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
MemberEntity member = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
||||||
OrganizationEntity organization = TestObjectFactory.buildOrganization(member);
|
OrganizationEntity organization = TestObjectFactory.buildOrganization(member);
|
||||||
MemberRoleEntity savedMemberRole =
|
MemberRoleEntity savedMemberRole =
|
||||||
memberRoleRepository.save(TestObjectFactory.buildMemberRole(RoleId.ACCOUNTANT, organization.getId()));
|
memberRoleRepository.save(TestObjectFactory.buildMemberRole("Accountant", organization.getId()));
|
||||||
member.setRoles(Set.of(savedMemberRole));
|
member.setRoles(Set.of(savedMemberRole));
|
||||||
MemberEntity savedMember = memberRepository.save(member);
|
MemberEntity savedMember = memberRepository.save(member);
|
||||||
OrganizationEntity savedOrganization = organizationRepository.save(organization);
|
OrganizationEntity savedOrganization = organizationRepository.save(organization);
|
||||||
@ -133,7 +132,7 @@ public class OrgsControllerTest extends AbstractControllerTest {
|
|||||||
void removeMemberRoleWithOnlyOneRole() throws Exception {
|
void removeMemberRoleWithOnlyOneRole() throws Exception {
|
||||||
MemberEntity memberEntity = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
MemberEntity memberEntity = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
||||||
OrganizationEntity organization = TestObjectFactory.buildOrganization(memberEntity);
|
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 savedMemberRole = memberRoleRepository.save(
|
||||||
memberRoleEntity);
|
memberRoleEntity);
|
||||||
memberEntity.setRoles(Set.of(savedMemberRole));
|
memberEntity.setRoles(Set.of(savedMemberRole));
|
||||||
@ -155,8 +154,8 @@ public class OrgsControllerTest extends AbstractControllerTest {
|
|||||||
void removeMemberRole() throws Exception {
|
void removeMemberRole() throws Exception {
|
||||||
MemberEntity memberEntity = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
MemberEntity memberEntity = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
||||||
OrganizationEntity organization = TestObjectFactory.buildOrganization(memberEntity);
|
OrganizationEntity organization = TestObjectFactory.buildOrganization(memberEntity);
|
||||||
MemberRoleEntity memberRoleEntity = TestObjectFactory.buildMemberRole(RoleId.ACCOUNTANT, organization.getId());
|
MemberRoleEntity memberRoleEntity = TestObjectFactory.buildMemberRole("Accountant", organization.getId());
|
||||||
MemberRoleEntity roleToRemove = TestObjectFactory.buildMemberRole(RoleId.MANAGER, organization.getId());
|
MemberRoleEntity roleToRemove = TestObjectFactory.buildMemberRole("Manager", organization.getId());
|
||||||
List<MemberRoleEntity> roles = memberRoleRepository.saveAll(List.of(
|
List<MemberRoleEntity> roles = memberRoleRepository.saveAll(List.of(
|
||||||
memberRoleEntity, roleToRemove));
|
memberRoleEntity, roleToRemove));
|
||||||
memberEntity.setRoles(new HashSet<>(roles));
|
memberEntity.setRoles(new HashSet<>(roles));
|
||||||
@ -164,9 +163,9 @@ public class OrgsControllerTest extends AbstractControllerTest {
|
|||||||
OrganizationEntity savedOrganization = organizationRepository.save(organization);
|
OrganizationEntity savedOrganization = organizationRepository.save(organization);
|
||||||
|
|
||||||
mockMvc.perform(delete(
|
mockMvc.perform(delete(
|
||||||
String.format("/orgs/%s/members/%s/roles/%s", savedOrganization.getId(), savedMember.getId(),
|
String.format("/orgs/%s/members/%s/roles/%s", savedOrganization.getId(), savedMember.getId(),
|
||||||
roleToRemove.getId())
|
roleToRemove.getId())
|
||||||
)
|
)
|
||||||
.contentType("application/json")
|
.contentType("application/json")
|
||||||
.header("Authorization", "Bearer " + generateRbkAdminJwt())
|
.header("Authorization", "Bearer " + generateRbkAdminJwt())
|
||||||
.header("X-Request-ID", "testRequestId"))
|
.header("X-Request-ID", "testRequestId"))
|
||||||
|
@ -115,7 +115,7 @@ public class UserControllerTest extends AbstractControllerTest {
|
|||||||
assertEquals(savedOrg.getId(), organizationMembership.getOrg().getId());
|
assertEquals(savedOrg.getId(), organizationMembership.getOrg().getId());
|
||||||
assertEquals(userId, organizationMembership.getMember().getId());
|
assertEquals(userId, organizationMembership.getMember().getId());
|
||||||
List<String> actualRoles =
|
List<String> actualRoles =
|
||||||
organizationMembership.getMember().getRoles().stream().map(MemberRole::getRoleId).map(RoleId::getValue)
|
organizationMembership.getMember().getRoles().stream().map(MemberRole::getRoleId)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
List<String> expectedRoles = savedInvitation.getInviteeRoles().stream().map(MemberRoleEntity::getRoleId)
|
List<String> expectedRoles = savedInvitation.getInviteeRoles().stream().map(MemberRoleEntity::getRoleId)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
@ -147,7 +147,7 @@ public class UserControllerTest extends AbstractControllerTest {
|
|||||||
assertEquals(savedOrg.getId(), organizationMembership.getOrg().getId());
|
assertEquals(savedOrg.getId(), organizationMembership.getOrg().getId());
|
||||||
assertEquals(userId, organizationMembership.getMember().getId());
|
assertEquals(userId, organizationMembership.getMember().getId());
|
||||||
List<String> actualRoles =
|
List<String> actualRoles =
|
||||||
organizationMembership.getMember().getRoles().stream().map(MemberRole::getRoleId).map(RoleId::getValue)
|
organizationMembership.getMember().getRoles().stream().map(MemberRole::getRoleId)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
List<String> expectedRoles = savedInvitation.getInviteeRoles().stream().map(MemberRoleEntity::getRoleId)
|
List<String> expectedRoles = savedInvitation.getInviteeRoles().stream().map(MemberRoleEntity::getRoleId)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
@ -8,7 +8,6 @@ import dev.vality.orgmanager.TestObjectFactory;
|
|||||||
import dev.vality.orgmanager.entity.MemberEntity;
|
import dev.vality.orgmanager.entity.MemberEntity;
|
||||||
import dev.vality.orgmanager.entity.MemberRoleEntity;
|
import dev.vality.orgmanager.entity.MemberRoleEntity;
|
||||||
import dev.vality.orgmanager.entity.OrganizationEntity;
|
import dev.vality.orgmanager.entity.OrganizationEntity;
|
||||||
import dev.vality.swag.organizations.model.RoleId;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@ -39,7 +38,7 @@ class BouncerContextConverterTest {
|
|||||||
OrgRole actual = converter.toOrgRole(entity);
|
OrgRole actual = converter.toOrgRole(entity);
|
||||||
|
|
||||||
OrgRole expected = new OrgRole()
|
OrgRole expected = new OrgRole()
|
||||||
.setId(RoleId.ADMINISTRATOR.getValue())
|
.setId("Administrator")
|
||||||
.setScope(new OrgRoleScope()
|
.setScope(new OrgRoleScope()
|
||||||
.setShop(new Entity().setId("resource")));
|
.setShop(new Entity().setId("resource")));
|
||||||
|
|
||||||
@ -57,7 +56,7 @@ class BouncerContextConverterTest {
|
|||||||
OrgRole actual = converter.toOrgRole(entity);
|
OrgRole actual = converter.toOrgRole(entity);
|
||||||
|
|
||||||
OrgRole expected = new OrgRole()
|
OrgRole expected = new OrgRole()
|
||||||
.setId(RoleId.ADMINISTRATOR.getValue())
|
.setId("Administrator")
|
||||||
.setScope(null);
|
.setScope(null);
|
||||||
|
|
||||||
assertEquals(expected, actual);
|
assertEquals(expected, actual);
|
||||||
@ -91,7 +90,7 @@ class BouncerContextConverterTest {
|
|||||||
void shouldConvertToOrganizationWithoutRolesAnotherOrganization() {
|
void shouldConvertToOrganizationWithoutRolesAnotherOrganization() {
|
||||||
OrganizationEntity organizationEntity = TestObjectFactory.buildOrganization();
|
OrganizationEntity organizationEntity = TestObjectFactory.buildOrganization();
|
||||||
MemberRoleEntity memberRoleEntity =
|
MemberRoleEntity memberRoleEntity =
|
||||||
TestObjectFactory.buildMemberRole(RoleId.ADMINISTRATOR, TestObjectFactory.randomString());
|
TestObjectFactory.buildMemberRole("Administrator", TestObjectFactory.randomString());
|
||||||
|
|
||||||
var organization = converter.toOrganization(organizationEntity, Set.of(memberRoleEntity));
|
var organization = converter.toOrganization(organizationEntity, Set.of(memberRoleEntity));
|
||||||
|
|
||||||
@ -105,7 +104,7 @@ class BouncerContextConverterTest {
|
|||||||
void shouldConvertToOrganization() {
|
void shouldConvertToOrganization() {
|
||||||
OrganizationEntity organizationEntity = TestObjectFactory.buildOrganization();
|
OrganizationEntity organizationEntity = TestObjectFactory.buildOrganization();
|
||||||
MemberRoleEntity memberRoleEntity =
|
MemberRoleEntity memberRoleEntity =
|
||||||
TestObjectFactory.buildMemberRole(RoleId.ADMINISTRATOR, organizationEntity.getId());
|
TestObjectFactory.buildMemberRole("Administrator", organizationEntity.getId());
|
||||||
|
|
||||||
var organization = converter.toOrganization(organizationEntity, Set.of(memberRoleEntity));
|
var organization = converter.toOrganization(organizationEntity, Set.of(memberRoleEntity));
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ import dev.vality.orgmanager.entity.MemberRoleEntity;
|
|||||||
import dev.vality.swag.organizations.model.MemberRole;
|
import dev.vality.swag.organizations.model.MemberRole;
|
||||||
import dev.vality.swag.organizations.model.MemberRoleScope;
|
import dev.vality.swag.organizations.model.MemberRoleScope;
|
||||||
import dev.vality.swag.organizations.model.ResourceScopeId;
|
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.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@ -23,7 +22,7 @@ class MemberRoleConverterTest {
|
|||||||
void shouldConvertToEntityWithoutScope() {
|
void shouldConvertToEntityWithoutScope() {
|
||||||
// Given
|
// Given
|
||||||
MemberRole role = new MemberRole()
|
MemberRole role = new MemberRole()
|
||||||
.roleId(RoleId.ADMINISTRATOR);
|
.roleId("Administrator");
|
||||||
|
|
||||||
// When
|
// When
|
||||||
MemberRoleEntity entity = converter.toEntity(role, "org");
|
MemberRoleEntity entity = converter.toEntity(role, "org");
|
||||||
@ -45,7 +44,7 @@ class MemberRoleConverterTest {
|
|||||||
void shouldConvertToEntity() {
|
void shouldConvertToEntity() {
|
||||||
// Given
|
// Given
|
||||||
MemberRole role = new MemberRole()
|
MemberRole role = new MemberRole()
|
||||||
.roleId(RoleId.ADMINISTRATOR)
|
.roleId("Administrator")
|
||||||
.scope(new MemberRoleScope()
|
.scope(new MemberRoleScope()
|
||||||
.resourceId("resource")
|
.resourceId("resource")
|
||||||
.id(ResourceScopeId.SHOP));
|
.id(ResourceScopeId.SHOP));
|
||||||
@ -84,7 +83,7 @@ class MemberRoleConverterTest {
|
|||||||
// Then
|
// Then
|
||||||
MemberRole expected = new MemberRole()
|
MemberRole expected = new MemberRole()
|
||||||
.id(entity.getId())
|
.id(entity.getId())
|
||||||
.roleId(RoleId.ADMINISTRATOR);
|
.roleId("Administrator");
|
||||||
|
|
||||||
assertThat(role).usingRecursiveComparison().isEqualTo(expected);
|
assertThat(role).usingRecursiveComparison().isEqualTo(expected);
|
||||||
}
|
}
|
||||||
@ -106,7 +105,7 @@ class MemberRoleConverterTest {
|
|||||||
// Then
|
// Then
|
||||||
MemberRole expected = new MemberRole()
|
MemberRole expected = new MemberRole()
|
||||||
.id(entity.getId())
|
.id(entity.getId())
|
||||||
.roleId(RoleId.ADMINISTRATOR)
|
.roleId("Administrator")
|
||||||
.scope(new MemberRoleScope()
|
.scope(new MemberRoleScope()
|
||||||
.resourceId("resource")
|
.resourceId("resource")
|
||||||
.id(ResourceScopeId.SHOP));
|
.id(ResourceScopeId.SHOP));
|
||||||
|
@ -4,7 +4,6 @@ import dev.vality.orgmanager.entity.OrganizationRoleEntity;
|
|||||||
import dev.vality.orgmanager.entity.ScopeEntity;
|
import dev.vality.orgmanager.entity.ScopeEntity;
|
||||||
import dev.vality.swag.organizations.model.ResourceScopeId;
|
import dev.vality.swag.organizations.model.ResourceScopeId;
|
||||||
import dev.vality.swag.organizations.model.Role;
|
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.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@ -40,7 +39,7 @@ class OrganizationRoleConverterTest {
|
|||||||
|
|
||||||
// Then
|
// Then
|
||||||
Role expected = new Role()
|
Role expected = new Role()
|
||||||
.id(RoleId.ADMINISTRATOR)
|
.id("Administrator")
|
||||||
.name("name")
|
.name("name")
|
||||||
.scopes(List.of(ResourceScopeId.SHOP));
|
.scopes(List.of(ResourceScopeId.SHOP));
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ import dev.vality.orgmanager.repository.OrganizationRepository;
|
|||||||
import dev.vality.orgmanager.repository.OrganizationRoleRepository;
|
import dev.vality.orgmanager.repository.OrganizationRoleRepository;
|
||||||
import dev.vality.swag.organizations.model.Role;
|
import dev.vality.swag.organizations.model.Role;
|
||||||
import dev.vality.swag.organizations.model.RoleAvailableListResult;
|
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.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
@ -85,10 +84,10 @@ public class OrganizationRoleServiceTest {
|
|||||||
OrganizationRoleEntity organizationRoleEntity = new OrganizationRoleEntity();
|
OrganizationRoleEntity organizationRoleEntity = new OrganizationRoleEntity();
|
||||||
Role role = new Role();
|
Role role = new Role();
|
||||||
String orgId = "orgId";
|
String orgId = "orgId";
|
||||||
RoleId roleId = RoleId.ADMINISTRATOR;
|
String roleId = "Administrator";
|
||||||
when(organizationRepository.existsById(orgId))
|
when(organizationRepository.existsById(orgId))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
when(organizationRoleRepository.findByOrganizationIdAndRoleId(orgId, roleId.getValue()))
|
when(organizationRoleRepository.findByOrganizationIdAndRoleId(orgId, roleId))
|
||||||
.thenReturn(Optional.of(organizationRoleEntity));
|
.thenReturn(Optional.of(organizationRoleEntity));
|
||||||
when(organizationRoleConverter.toDomain(organizationRoleEntity))
|
when(organizationRoleConverter.toDomain(organizationRoleEntity))
|
||||||
.thenReturn(role);
|
.thenReturn(role);
|
||||||
@ -102,7 +101,7 @@ public class OrganizationRoleServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
void shouldReturnNotFoundIfOrganizationDoesNotExist() {
|
void shouldReturnNotFoundIfOrganizationDoesNotExist() {
|
||||||
String orgId = "orgId";
|
String orgId = "orgId";
|
||||||
RoleId roleId = RoleId.ADMINISTRATOR;
|
String roleId = "Administrator";
|
||||||
when(organizationRepository.existsById(orgId))
|
when(organizationRepository.existsById(orgId))
|
||||||
.thenReturn(false);
|
.thenReturn(false);
|
||||||
|
|
||||||
|
@ -39,16 +39,16 @@ public class OrganizationServiceIntegrationTest extends AbstractRepositoryTest {
|
|||||||
// Given
|
// Given
|
||||||
MemberEntity member = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
MemberEntity member = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
||||||
OrganizationEntity organization = TestObjectFactory.buildOrganization(member);
|
OrganizationEntity organization = TestObjectFactory.buildOrganization(member);
|
||||||
MemberRoleEntity nonActiveRoleInOrg = buildMemberRole(RoleId.ACCOUNTANT, organization.getId());
|
MemberRoleEntity nonActiveRoleInOrg = buildMemberRole("Accountant", organization.getId());
|
||||||
nonActiveRoleInOrg.setActive(Boolean.FALSE);
|
nonActiveRoleInOrg.setActive(Boolean.FALSE);
|
||||||
MemberRoleEntity savedMemberRoleNonActiveInOrg = memberRoleRepository.save(nonActiveRoleInOrg);
|
MemberRoleEntity savedMemberRoleNonActiveInOrg = memberRoleRepository.save(nonActiveRoleInOrg);
|
||||||
MemberRoleEntity activeRoleInOrg = buildMemberRole(RoleId.ACCOUNTANT, organization.getId());
|
MemberRoleEntity activeRoleInOrg = buildMemberRole("Accountant", organization.getId());
|
||||||
activeRoleInOrg.setActive(Boolean.TRUE);
|
activeRoleInOrg.setActive(Boolean.TRUE);
|
||||||
MemberRoleEntity savedMemberRoleInOrg =
|
MemberRoleEntity savedMemberRoleInOrg =
|
||||||
memberRoleRepository.save(activeRoleInOrg);
|
memberRoleRepository.save(activeRoleInOrg);
|
||||||
MemberRoleEntity savedMemberRoleInAnotherOrg =
|
MemberRoleEntity savedMemberRoleInAnotherOrg =
|
||||||
memberRoleRepository
|
memberRoleRepository
|
||||||
.save(TestObjectFactory.buildMemberRole(RoleId.ACCOUNTANT, TestObjectFactory.randomString()));
|
.save(TestObjectFactory.buildMemberRole("Accountant", TestObjectFactory.randomString()));
|
||||||
member.setRoles(Set.of(savedMemberRoleNonActiveInOrg, savedMemberRoleInOrg, savedMemberRoleInAnotherOrg));
|
member.setRoles(Set.of(savedMemberRoleNonActiveInOrg, savedMemberRoleInOrg, savedMemberRoleInAnotherOrg));
|
||||||
MemberEntity savedMember = memberRepository.save(member);
|
MemberEntity savedMember = memberRepository.save(member);
|
||||||
OrganizationEntity savedOrganization = organizationRepository.save(organization);
|
OrganizationEntity savedOrganization = organizationRepository.save(organization);
|
||||||
@ -70,7 +70,7 @@ public class OrganizationServiceIntegrationTest extends AbstractRepositoryTest {
|
|||||||
void shouldThrowAccessDeniedExceptionOnJoinOrgTest() {
|
void shouldThrowAccessDeniedExceptionOnJoinOrgTest() {
|
||||||
MemberEntity memberEntity = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
MemberEntity memberEntity = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
||||||
OrganizationEntity organization = TestObjectFactory.buildOrganization(memberEntity);
|
OrganizationEntity organization = TestObjectFactory.buildOrganization(memberEntity);
|
||||||
MemberRoleEntity memberRole = buildMemberRole(RoleId.ACCOUNTANT, organization.getId());
|
MemberRoleEntity memberRole = buildMemberRole("Accountant", organization.getId());
|
||||||
memberRole.setActive(Boolean.FALSE);
|
memberRole.setActive(Boolean.FALSE);
|
||||||
MemberRoleEntity savedMemberRole = memberRoleRepository.save(memberRole);
|
MemberRoleEntity savedMemberRole = memberRoleRepository.save(memberRole);
|
||||||
memberEntity.setRoles(Set.of(savedMemberRole));
|
memberEntity.setRoles(Set.of(savedMemberRole));
|
||||||
@ -97,7 +97,7 @@ public class OrganizationServiceIntegrationTest extends AbstractRepositoryTest {
|
|||||||
alreadyAcceptedInvitation.setAcceptedMemberId(TestObjectFactory.randomString());
|
alreadyAcceptedInvitation.setAcceptedMemberId(TestObjectFactory.randomString());
|
||||||
alreadyAcceptedInvitation.setStatus(InvitationStatusName.ACCEPTED.getValue());
|
alreadyAcceptedInvitation.setStatus(InvitationStatusName.ACCEPTED.getValue());
|
||||||
invitationRepository.save(alreadyAcceptedInvitation);
|
invitationRepository.save(alreadyAcceptedInvitation);
|
||||||
MemberRoleEntity memberRole = buildMemberRole(RoleId.ACCOUNTANT, savedOrganization.getId());
|
MemberRoleEntity memberRole = buildMemberRole("Accountant", savedOrganization.getId());
|
||||||
memberRole.setActive(Boolean.FALSE);
|
memberRole.setActive(Boolean.FALSE);
|
||||||
MemberRoleEntity savedMemberRole = memberRoleRepository.save(memberRole);
|
MemberRoleEntity savedMemberRole = memberRoleRepository.save(memberRole);
|
||||||
memberEntity.setRoles(Set.of(savedMemberRole));
|
memberEntity.setRoles(Set.of(savedMemberRole));
|
||||||
@ -114,7 +114,7 @@ public class OrganizationServiceIntegrationTest extends AbstractRepositoryTest {
|
|||||||
void shouldJoinExistMember() {
|
void shouldJoinExistMember() {
|
||||||
MemberEntity memberEntity = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
MemberEntity memberEntity = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
||||||
OrganizationEntity organization = TestObjectFactory.buildOrganization(memberEntity);
|
OrganizationEntity organization = TestObjectFactory.buildOrganization(memberEntity);
|
||||||
MemberRoleEntity memberRole = buildMemberRole(RoleId.ACCOUNTANT, organization.getId());
|
MemberRoleEntity memberRole = buildMemberRole("Accountant", organization.getId());
|
||||||
memberRole.setActive(Boolean.FALSE);
|
memberRole.setActive(Boolean.FALSE);
|
||||||
MemberRoleEntity savedMemberRole = memberRoleRepository.save(memberRole);
|
MemberRoleEntity savedMemberRole = memberRoleRepository.save(memberRole);
|
||||||
memberEntity.setRoles(Set.of(savedMemberRole));
|
memberEntity.setRoles(Set.of(savedMemberRole));
|
||||||
@ -130,7 +130,6 @@ public class OrganizationServiceIntegrationTest extends AbstractRepositoryTest {
|
|||||||
assertEquals(savedMember.getId(), organizationMembership.getMember().getId());
|
assertEquals(savedMember.getId(), organizationMembership.getMember().getId());
|
||||||
List<String> actualRoles = organizationMembership.getMember().getRoles().stream()
|
List<String> actualRoles = organizationMembership.getMember().getRoles().stream()
|
||||||
.map(MemberRole::getRoleId)
|
.map(MemberRole::getRoleId)
|
||||||
.map(RoleId::getValue)
|
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
List<String> expectedRoles = savedInvitation.getInviteeRoles().stream()
|
List<String> expectedRoles = savedInvitation.getInviteeRoles().stream()
|
||||||
.map(MemberRoleEntity::getRoleId)
|
.map(MemberRoleEntity::getRoleId)
|
||||||
@ -155,7 +154,6 @@ public class OrganizationServiceIntegrationTest extends AbstractRepositoryTest {
|
|||||||
assertEquals(userId, organizationMembership.getMember().getId());
|
assertEquals(userId, organizationMembership.getMember().getId());
|
||||||
List<String> actualRoles = organizationMembership.getMember().getRoles().stream()
|
List<String> actualRoles = organizationMembership.getMember().getRoles().stream()
|
||||||
.map(MemberRole::getRoleId)
|
.map(MemberRole::getRoleId)
|
||||||
.map(RoleId::getValue)
|
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
List<String> expectedRoles = savedInvitation.getInviteeRoles().stream()
|
List<String> expectedRoles = savedInvitation.getInviteeRoles().stream()
|
||||||
.map(MemberRoleEntity::getRoleId)
|
.map(MemberRoleEntity::getRoleId)
|
||||||
@ -171,7 +169,7 @@ public class OrganizationServiceIntegrationTest extends AbstractRepositoryTest {
|
|||||||
void shouldExpelOrgMember() {
|
void shouldExpelOrgMember() {
|
||||||
MemberEntity member = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
MemberEntity member = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
||||||
OrganizationEntity organization = TestObjectFactory.buildOrganization(member);
|
OrganizationEntity organization = TestObjectFactory.buildOrganization(member);
|
||||||
MemberRoleEntity activeRoleInOrg = buildMemberRole(RoleId.ACCOUNTANT, organization.getId());
|
MemberRoleEntity activeRoleInOrg = buildMemberRole("Accountant", organization.getId());
|
||||||
activeRoleInOrg.setActive(Boolean.TRUE);
|
activeRoleInOrg.setActive(Boolean.TRUE);
|
||||||
MemberRoleEntity savedMemberRole = memberRoleRepository.save(activeRoleInOrg);
|
MemberRoleEntity savedMemberRole = memberRoleRepository.save(activeRoleInOrg);
|
||||||
member.setRoles(Set.of(savedMemberRole));
|
member.setRoles(Set.of(savedMemberRole));
|
||||||
@ -197,7 +195,7 @@ public class OrganizationServiceIntegrationTest extends AbstractRepositoryTest {
|
|||||||
void shouldNotReturnOrganizationsAfterExpelOrgMember() {
|
void shouldNotReturnOrganizationsAfterExpelOrgMember() {
|
||||||
MemberEntity member = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
MemberEntity member = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
||||||
OrganizationEntity organization = TestObjectFactory.buildOrganization(member);
|
OrganizationEntity organization = TestObjectFactory.buildOrganization(member);
|
||||||
MemberRoleEntity activeRoleInOrg = buildMemberRole(RoleId.ACCOUNTANT, organization.getId());
|
MemberRoleEntity activeRoleInOrg = buildMemberRole("Accountant", organization.getId());
|
||||||
activeRoleInOrg.setActive(Boolean.TRUE);
|
activeRoleInOrg.setActive(Boolean.TRUE);
|
||||||
MemberRoleEntity savedMemberRole = memberRoleRepository.save(activeRoleInOrg);
|
MemberRoleEntity savedMemberRole = memberRoleRepository.save(activeRoleInOrg);
|
||||||
member.setRoles(Set.of(savedMemberRole));
|
member.setRoles(Set.of(savedMemberRole));
|
||||||
@ -223,20 +221,20 @@ public class OrganizationServiceIntegrationTest extends AbstractRepositoryTest {
|
|||||||
MemberEntity member1 = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
MemberEntity member1 = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
||||||
MemberEntity member2 = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
MemberEntity member2 = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
||||||
OrganizationEntity organization = TestObjectFactory.buildOrganization(Set.of(member1, member2));
|
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);
|
activeMember1RoleInOrg.setActive(Boolean.TRUE);
|
||||||
MemberRoleEntity savedMember1Role = memberRoleRepository.save(activeMember1RoleInOrg);
|
MemberRoleEntity savedMember1Role = memberRoleRepository.save(activeMember1RoleInOrg);
|
||||||
member1.setRoles(Set.of(savedMember1Role));
|
member1.setRoles(Set.of(savedMember1Role));
|
||||||
MemberRoleEntity activeMember2RoleInOrg = buildMemberRole(RoleId.ACCOUNTANT, organization.getId());
|
MemberRoleEntity activeMember2RoleInOrg = buildMemberRole("Accountant", organization.getId());
|
||||||
activeMember2RoleInOrg.setActive(Boolean.TRUE);
|
activeMember2RoleInOrg.setActive(Boolean.TRUE);
|
||||||
MemberRoleEntity savedActiveMember2Role = memberRoleRepository.save(activeMember2RoleInOrg);
|
MemberRoleEntity savedActiveMember2Role = memberRoleRepository.save(activeMember2RoleInOrg);
|
||||||
MemberRoleEntity nonActiveMember2RoleInOrg = buildMemberRole(RoleId.ACCOUNTANT, organization.getId());
|
MemberRoleEntity nonActiveMember2RoleInOrg = buildMemberRole("Accountant", organization.getId());
|
||||||
nonActiveMember2RoleInOrg.setActive(Boolean.FALSE);
|
nonActiveMember2RoleInOrg.setActive(Boolean.FALSE);
|
||||||
MemberRoleEntity savedNonActiveMember2Role = memberRoleRepository.save(nonActiveMember2RoleInOrg);
|
MemberRoleEntity savedNonActiveMember2Role = memberRoleRepository.save(nonActiveMember2RoleInOrg);
|
||||||
member2.setRoles(Set.of(savedActiveMember2Role, savedNonActiveMember2Role));
|
member2.setRoles(Set.of(savedActiveMember2Role, savedNonActiveMember2Role));
|
||||||
MemberEntity anotherMember = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
MemberEntity anotherMember = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
||||||
OrganizationEntity anotherOrganization = TestObjectFactory.buildOrganization(Set.of(anotherMember));
|
OrganizationEntity anotherOrganization = TestObjectFactory.buildOrganization(Set.of(anotherMember));
|
||||||
MemberRoleEntity activeAnotherMemberRoleInOrg = buildMemberRole(RoleId.ACCOUNTANT, anotherOrganization.getId());
|
MemberRoleEntity activeAnotherMemberRoleInOrg = buildMemberRole("Accountant", anotherOrganization.getId());
|
||||||
activeAnotherMemberRoleInOrg.setActive(Boolean.TRUE);
|
activeAnotherMemberRoleInOrg.setActive(Boolean.TRUE);
|
||||||
MemberRoleEntity savedAnotherRole = memberRoleRepository.save(activeAnotherMemberRoleInOrg);
|
MemberRoleEntity savedAnotherRole = memberRoleRepository.save(activeAnotherMemberRoleInOrg);
|
||||||
anotherMember.setRoles(Set.of(savedAnotherRole));
|
anotherMember.setRoles(Set.of(savedAnotherRole));
|
||||||
@ -265,7 +263,7 @@ public class OrganizationServiceIntegrationTest extends AbstractRepositoryTest {
|
|||||||
MemberEntity member = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
MemberEntity member = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
||||||
OrganizationEntity organization = TestObjectFactory.buildOrganization(member);
|
OrganizationEntity organization = TestObjectFactory.buildOrganization(member);
|
||||||
MemberRoleEntity role =
|
MemberRoleEntity role =
|
||||||
memberRoleRepository.save(TestObjectFactory.buildMemberRole(RoleId.ACCOUNTANT, organization.getId()));
|
memberRoleRepository.save(TestObjectFactory.buildMemberRole("Accountant", organization.getId()));
|
||||||
member.setRoles(Set.of(role));
|
member.setRoles(Set.of(role));
|
||||||
MemberEntity savedMember = memberRepository.save(member);
|
MemberEntity savedMember = memberRepository.save(member);
|
||||||
OrganizationEntity savedOrganization = organizationRepository.save(organization);
|
OrganizationEntity savedOrganization = organizationRepository.save(organization);
|
||||||
@ -281,9 +279,9 @@ public class OrganizationServiceIntegrationTest extends AbstractRepositoryTest {
|
|||||||
MemberEntity memberEntity = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
MemberEntity memberEntity = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
||||||
OrganizationEntity organization = TestObjectFactory.buildOrganization(memberEntity);
|
OrganizationEntity organization = TestObjectFactory.buildOrganization(memberEntity);
|
||||||
MemberRoleEntity role =
|
MemberRoleEntity role =
|
||||||
memberRoleRepository.save(TestObjectFactory.buildMemberRole(RoleId.ACCOUNTANT, organization.getId()));
|
memberRoleRepository.save(TestObjectFactory.buildMemberRole("Accountant", organization.getId()));
|
||||||
MemberRoleEntity roleToRemove =
|
MemberRoleEntity roleToRemove =
|
||||||
memberRoleRepository.save(TestObjectFactory.buildMemberRole(RoleId.MANAGER, organization.getId()));
|
memberRoleRepository.save(TestObjectFactory.buildMemberRole("Manager", organization.getId()));
|
||||||
memberEntity.setRoles(Set.of(role, roleToRemove));
|
memberEntity.setRoles(Set.of(role, roleToRemove));
|
||||||
MemberEntity savedMember = memberRepository.save(memberEntity);
|
MemberEntity savedMember = memberRepository.save(memberEntity);
|
||||||
OrganizationEntity savedOrganization = organizationRepository.save(organization);
|
OrganizationEntity savedOrganization = organizationRepository.save(organization);
|
||||||
|
@ -8,7 +8,6 @@ import dev.vality.orgmanager.service.dto.BouncerContextDto;
|
|||||||
import dev.vality.orgmanager.service.dto.ResourceDto;
|
import dev.vality.orgmanager.service.dto.ResourceDto;
|
||||||
import dev.vality.swag.organizations.model.MemberRole;
|
import dev.vality.swag.organizations.model.MemberRole;
|
||||||
import dev.vality.swag.organizations.model.MemberRoleScope;
|
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.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
@ -138,7 +137,7 @@ class ResourceAccessServiceImplTest {
|
|||||||
when(memberRoleService.findById(resource.getMemberRoleId()))
|
when(memberRoleService.findById(resource.getMemberRoleId()))
|
||||||
.thenReturn(
|
.thenReturn(
|
||||||
new MemberRole()
|
new MemberRole()
|
||||||
.roleId(RoleId.MANAGER)
|
.roleId("Manager")
|
||||||
.scope(new MemberRoleScope().resourceId(TestObjectFactory.randomString()))
|
.scope(new MemberRoleScope().resourceId(TestObjectFactory.randomString()))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@ import dev.vality.orgmanager.entity.MemberRoleEntity;
|
|||||||
import dev.vality.orgmanager.entity.OrganizationEntity;
|
import dev.vality.orgmanager.entity.OrganizationEntity;
|
||||||
import dev.vality.orgmanager.repository.AbstractRepositoryTest;
|
import dev.vality.orgmanager.repository.AbstractRepositoryTest;
|
||||||
import dev.vality.orgmanager.service.model.UserInfo;
|
import dev.vality.orgmanager.service.model.UserInfo;
|
||||||
import dev.vality.swag.organizations.model.RoleId;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
@ -14,9 +13,7 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
|
|
||||||
class UserServiceImplTest extends AbstractRepositoryTest {
|
class UserServiceImplTest extends AbstractRepositoryTest {
|
||||||
|
|
||||||
@ -65,7 +62,7 @@ class UserServiceImplTest extends AbstractRepositoryTest {
|
|||||||
String memberId = TestObjectFactory.randomString();
|
String memberId = TestObjectFactory.randomString();
|
||||||
var member = TestObjectFactory.testMemberEntity(memberId);
|
var member = TestObjectFactory.testMemberEntity(memberId);
|
||||||
OrganizationEntity organization = TestObjectFactory.buildOrganization(member);
|
OrganizationEntity organization = TestObjectFactory.buildOrganization(member);
|
||||||
MemberRoleEntity memberRole = TestObjectFactory.buildMemberRole(RoleId.ACCOUNTANT, organization.getId());
|
MemberRoleEntity memberRole = TestObjectFactory.buildMemberRole("Accountant", organization.getId());
|
||||||
memberRoleRepository.save(memberRole);
|
memberRoleRepository.save(memberRole);
|
||||||
member.setRoles(Set.of(memberRole));
|
member.setRoles(Set.of(memberRole));
|
||||||
memberRepository.save(member);
|
memberRepository.save(member);
|
||||||
@ -84,7 +81,7 @@ class UserServiceImplTest extends AbstractRepositoryTest {
|
|||||||
String memberId = TestObjectFactory.randomString();
|
String memberId = TestObjectFactory.randomString();
|
||||||
var member = TestObjectFactory.testMemberEntity(memberId);
|
var member = TestObjectFactory.testMemberEntity(memberId);
|
||||||
OrganizationEntity organization = TestObjectFactory.buildOrganization(member);
|
OrganizationEntity organization = TestObjectFactory.buildOrganization(member);
|
||||||
MemberRoleEntity memberRole = TestObjectFactory.buildMemberRole(RoleId.ACCOUNTANT, organization.getId());
|
MemberRoleEntity memberRole = TestObjectFactory.buildMemberRole("Accountant", organization.getId());
|
||||||
OrganizationEntity ownedOrganization = TestObjectFactory.buildOrganization();
|
OrganizationEntity ownedOrganization = TestObjectFactory.buildOrganization();
|
||||||
ownedOrganization.setOwner(memberId);
|
ownedOrganization.setOwner(memberId);
|
||||||
memberRoleRepository.save(memberRole);
|
memberRoleRepository.save(memberRole);
|
||||||
@ -111,9 +108,9 @@ class UserServiceImplTest extends AbstractRepositoryTest {
|
|||||||
OrganizationEntity organization = TestObjectFactory.buildOrganization(member);
|
OrganizationEntity organization = TestObjectFactory.buildOrganization(member);
|
||||||
organization.setOwner(memberId);
|
organization.setOwner(memberId);
|
||||||
organization.setRoles(
|
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);
|
memberRoleRepository.save(memberRole);
|
||||||
member.setRoles(Set.of(memberRole));
|
member.setRoles(Set.of(memberRole));
|
||||||
memberRepository.save(member);
|
memberRepository.save(member);
|
||||||
|
@ -23,7 +23,7 @@ public class TestData {
|
|||||||
.id(memberId)
|
.id(memberId)
|
||||||
.email("email")
|
.email("email")
|
||||||
.roles(Set.of(MemberRoleEntity.builder()
|
.roles(Set.of(MemberRoleEntity.builder()
|
||||||
.id(RoleId.ADMINISTRATOR.getValue())
|
.id("Accountant")
|
||||||
.organizationId(organizationId)
|
.organizationId(organizationId)
|
||||||
.roleId("Accountant")
|
.roleId("Accountant")
|
||||||
.scopeId("Shop")
|
.scopeId("Shop")
|
||||||
@ -67,14 +67,14 @@ public class TestData {
|
|||||||
.inviteeRoles(Set.of(
|
.inviteeRoles(Set.of(
|
||||||
MemberRoleEntity.builder()
|
MemberRoleEntity.builder()
|
||||||
.id("role1")
|
.id("role1")
|
||||||
.roleId(RoleId.ADMINISTRATOR.getValue())
|
.roleId("Administrator")
|
||||||
.resourceId("resource1")
|
.resourceId("resource1")
|
||||||
.scopeId(ResourceScopeId.SHOP.getValue())
|
.scopeId(ResourceScopeId.SHOP.getValue())
|
||||||
.organizationId(organizationId)
|
.organizationId(organizationId)
|
||||||
.build(),
|
.build(),
|
||||||
MemberRoleEntity.builder()
|
MemberRoleEntity.builder()
|
||||||
.id("role2")
|
.id("role2")
|
||||||
.roleId(RoleId.MANAGER.getValue())
|
.roleId("Manager")
|
||||||
.resourceId("resource2")
|
.resourceId("resource2")
|
||||||
.scopeId(ResourceScopeId.SHOP.getValue())
|
.scopeId(ResourceScopeId.SHOP.getValue())
|
||||||
.organizationId(organizationId)
|
.organizationId(organizationId)
|
||||||
@ -100,7 +100,7 @@ public class TestData {
|
|||||||
|
|
||||||
public static MemberRole buildMemberRole() {
|
public static MemberRole buildMemberRole() {
|
||||||
MemberRole memberRole = new MemberRole();
|
MemberRole memberRole = new MemberRole();
|
||||||
memberRole.setRoleId(RoleId.ADMINISTRATOR);
|
memberRole.setRoleId("Administrator");
|
||||||
MemberRoleScope memberRoleScope = new MemberRoleScope();
|
MemberRoleScope memberRoleScope = new MemberRoleScope();
|
||||||
memberRoleScope.setId(ResourceScopeId.SHOP);
|
memberRoleScope.setId(ResourceScopeId.SHOP);
|
||||||
memberRoleScope.setResourceId("testResourceIdKek");
|
memberRoleScope.setResourceId("testResourceIdKek");
|
||||||
|
Loading…
Reference in New Issue
Block a user