mirror of
https://github.com/valitydev/org-manager.git
synced 2024-11-06 00:15:23 +00:00
commit
6048d770f3
23
pom.xml
23
pom.xml
@ -5,8 +5,8 @@
|
||||
|
||||
<parent>
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.3.7.RELEASE</version>
|
||||
<artifactId>service-parent-pom</artifactId>
|
||||
<version>1.2.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>org-manager</artifactId>
|
||||
@ -23,7 +23,6 @@
|
||||
<exposed.ports>${server.port}</exposed.ports>
|
||||
<dockerfile.base.service.tag>c0612d6052ac049496b72a23a04acb142035f249</dockerfile.base.service.tag>
|
||||
<dockerfile.registry>dr2.rbkmoney.com</dockerfile.registry>
|
||||
<shared.resources.version>0.3.6</shared.resources.version>
|
||||
<keycloak.version>12.0.3</keycloak.version>
|
||||
<schedlock.version>4.14.0</schedlock.version>
|
||||
<swag.organizations.version>1.18-38ef431-server</swag.organizations.version>
|
||||
@ -39,17 +38,14 @@
|
||||
<dependency>
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
<artifactId>custom-actuator-endpoints</artifactId>
|
||||
<version>0.0.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.rbkmoney.woody</groupId>
|
||||
<artifactId>woody-thrift</artifactId>
|
||||
<version>1.1.15</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
<artifactId>shared-resources</artifactId>
|
||||
<version>${shared.resources.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
@ -59,7 +55,6 @@
|
||||
<dependency>
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
<artifactId>damsel</artifactId>
|
||||
<version>1.475-bde841f</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
@ -103,18 +98,6 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
<version>2.4.5</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-core</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-core</artifactId>
|
||||
<version>5.4.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.javacrumbs.shedlock</groupId>
|
||||
@ -288,7 +271,7 @@
|
||||
</dependencies>
|
||||
<configuration>
|
||||
<resourceBundles>
|
||||
<resourceBundle>com.rbkmoney:shared-resources:${shared.resources.version}</resourceBundle>
|
||||
<resourceBundle>com.rbkmoney:shared-resources:${shared-resources.version}</resourceBundle>
|
||||
</resourceBundles>
|
||||
<attachToMain>false</attachToMain>
|
||||
<attachToTest>false</attachToTest>
|
||||
|
@ -14,7 +14,8 @@ public class DudoserConfig {
|
||||
|
||||
@Bean
|
||||
public MessageSenderSrv.Iface dudoserSrv(@Value("${dudoser.url}") Resource resource,
|
||||
@Value("${dudoser.networkTimeout}") int networkTimeout) throws IOException {
|
||||
@Value("${dudoser.networkTimeout}") int networkTimeout)
|
||||
throws IOException {
|
||||
return new THSpawnClientBuilder()
|
||||
.withNetworkTimeout(networkTimeout)
|
||||
.withAddress(resource.getURI()).build(MessageSenderSrv.Iface.class);
|
||||
|
@ -26,79 +26,79 @@ public class OrgsController implements OrgsApi {
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Organization> createOrg(
|
||||
String xRequestID,
|
||||
String requestId,
|
||||
Organization organization,
|
||||
String xIdempotencyKey) {
|
||||
log.info("Create organization: requestId={}, idempontencyKey={}, organization={}", xRequestID, xIdempotencyKey,
|
||||
String idempotencyKey) {
|
||||
log.info("Create organization: requestId={}, idempotencyKey={}, organization={}", requestId, idempotencyKey,
|
||||
organization);
|
||||
resourceAccessService.checkRights();
|
||||
AccessToken accessToken = keycloakService.getAccessToken();
|
||||
return organizationService.create(accessToken.getSubject(), organization, xIdempotencyKey);
|
||||
return organizationService.create(accessToken.getSubject(), organization, idempotencyKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Organization> getOrg(
|
||||
String xRequestID,
|
||||
String requestId,
|
||||
String orgId) {
|
||||
log.info("Get organization: requestId={}, orgId={}", xRequestID, orgId);
|
||||
log.info("Get organization: requestId={}, orgId={}", requestId, orgId);
|
||||
resourceAccessService.checkOrganizationRights(orgId);
|
||||
return organizationService.get(orgId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Member> getOrgMember(
|
||||
String xRequestID,
|
||||
String requestId,
|
||||
String orgId,
|
||||
String userId) {
|
||||
log.info("Get organization member: requestId={}, orgId={}, userId={}", xRequestID, orgId, userId);
|
||||
log.info("Get organization member: requestId={}, orgId={}, userId={}", requestId, orgId, userId);
|
||||
resourceAccessService.checkMemberRights(orgId, userId);
|
||||
return ResponseEntity.ok(organizationService.getOrgMember(userId, orgId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<MemberOrgListResult> listOrgMembers(String xRequestID, String orgId) {
|
||||
log.info("List organization members: requestId={}, orgId={}", xRequestID, orgId);
|
||||
public ResponseEntity<MemberOrgListResult> listOrgMembers(String requestId, String orgId) {
|
||||
log.info("List organization members: requestId={}, orgId={}", requestId, orgId);
|
||||
resourceAccessService.checkOrganizationRights(orgId);
|
||||
return ResponseEntity.ok(organizationService.listMembers(orgId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Invitation> createInvitation(String xRequestID,
|
||||
public ResponseEntity<Invitation> createInvitation(String requestId,
|
||||
@Size(min = 1, max = 40) String orgId,
|
||||
@Valid InvitationRequest invitationRequest,
|
||||
String xIdempotencyKey) {
|
||||
log.info("Create invitation: requestId={}, idempontencyKey={}, orgId={}, invitation={}",
|
||||
xRequestID, xIdempotencyKey, orgId, invitationRequest);
|
||||
String idempotencyKey) {
|
||||
log.info("Create invitation: requestId={}, idempotencyKey={}, orgId={}, invitation={}",
|
||||
requestId, idempotencyKey, orgId, invitationRequest);
|
||||
resourceAccessService.checkInvitationRights(orgId, invitationRequest);
|
||||
return invitationService.create(orgId, invitationRequest, xIdempotencyKey);
|
||||
return invitationService.create(orgId, invitationRequest, idempotencyKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Invitation> getInvitation(
|
||||
String xRequestID,
|
||||
String requestId,
|
||||
String orgId,
|
||||
String invitationId) {
|
||||
log.info("Get invitation: requestId={}, orgId={}, invitationId={}", xRequestID, orgId, invitationId);
|
||||
log.info("Get invitation: requestId={}, orgId={}, invitationId={}", requestId, orgId, invitationId);
|
||||
resourceAccessService.checkInvitationRights(orgId, invitationId);
|
||||
return invitationService.get(invitationId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<InvitationListResult> listInvitations(String xRequestID,
|
||||
public ResponseEntity<InvitationListResult> listInvitations(String requestId,
|
||||
String orgId,
|
||||
InvitationStatusName status) {
|
||||
log.info("List invitations: requestId={}, orgId={}, status={}", xRequestID, orgId, status);
|
||||
log.info("List invitations: requestId={}, orgId={}, status={}", requestId, orgId, status);
|
||||
resourceAccessService.checkOrganizationRights(orgId);
|
||||
return invitationService.list(orgId, status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Void> revokeInvitation(String xRequestID,
|
||||
public ResponseEntity<Void> revokeInvitation(String requestId,
|
||||
String orgId,
|
||||
String invitationId,
|
||||
InlineObject1 inlineObject1) {
|
||||
log.info("Revoke invitation: requestId={}, orgId={}, invitationId={}, payload={}",
|
||||
xRequestID, orgId, invitationId, inlineObject1);
|
||||
requestId, orgId, invitationId, inlineObject1);
|
||||
resourceAccessService.checkInvitationRights(orgId, invitationId);
|
||||
invitationService.revoke(orgId, invitationId, inlineObject1);
|
||||
return ResponseEntity
|
||||
@ -108,36 +108,36 @@ public class OrgsController implements OrgsApi {
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Role> getOrgRole(
|
||||
String xRequestID,
|
||||
String requestId,
|
||||
String orgId,
|
||||
RoleId roleId) {
|
||||
log.info("Get organization id: requestId={}, orgId={}, roleId={}", xRequestID, orgId, roleId);
|
||||
log.info("Get organization id: requestId={}, orgId={}, roleId={}", requestId, orgId, roleId);
|
||||
MemberRole memberRole = new MemberRole();
|
||||
memberRole.setRoleId(roleId);
|
||||
resourceAccessService.checkRoleRights(orgId, memberRole);
|
||||
return organizationRoleService.get(orgId, roleId);
|
||||
return ResponseEntity.ok(organizationRoleService.get(orgId, roleId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<RoleAvailableListResult> listOrgRoles(String xRequestID, String orgId) {
|
||||
log.info("List organization roles: requestId={}, orgId={}", xRequestID, orgId);
|
||||
public ResponseEntity<RoleAvailableListResult> listOrgRoles(String requestId, String orgId) {
|
||||
log.info("List organization roles: requestId={}, orgId={}", requestId, orgId);
|
||||
resourceAccessService.checkOrganizationRights(orgId);
|
||||
return organizationRoleService.list(orgId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Organization> patchOrg(String xRequestID, String orgId, InlineObject inlineObject) {
|
||||
public ResponseEntity<Organization> patchOrg(String requestId, String orgId, InlineObject inlineObject) {
|
||||
resourceAccessService.checkOrganizationRights(orgId);
|
||||
return organizationService.modify(orgId, inlineObject.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<MemberRole> assignMemberRole(
|
||||
String xRequestID,
|
||||
String requestId,
|
||||
String orgId,
|
||||
String userId,
|
||||
MemberRole body) {
|
||||
log.info("Assign member role: requestId={}, orgId={}, payload={}", xRequestID, orgId, body);
|
||||
log.info("Assign member role: requestId={}, orgId={}, payload={}", requestId, orgId, body);
|
||||
resourceAccessService.checkMemberRoleRights(orgId, userId, body);
|
||||
return ResponseEntity
|
||||
.status(HttpStatus.CREATED)
|
||||
@ -146,10 +146,10 @@ public class OrgsController implements OrgsApi {
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Void> expelOrgMember(
|
||||
String xRequestID,
|
||||
String requestId,
|
||||
String orgId,
|
||||
String userId) {
|
||||
log.info("Expel member organization: requestId={}, orgId={}, userId={}", xRequestID, orgId, userId);
|
||||
log.info("Expel member organization: requestId={}, orgId={}, userId={}", requestId, orgId, userId);
|
||||
resourceAccessService.checkMemberRights(orgId, userId);
|
||||
organizationService.expelOrgMember(orgId, userId);
|
||||
return ResponseEntity.noContent().build();
|
||||
@ -157,11 +157,11 @@ public class OrgsController implements OrgsApi {
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Void> removeMemberRole(
|
||||
String xRequestID,
|
||||
String requestId,
|
||||
String orgId,
|
||||
String userId,
|
||||
String memberRoleId) {
|
||||
log.info("Remove member role: requestId={}, orgId={}, userId={}, memberRoleId={}", xRequestID, orgId,
|
||||
log.info("Remove member role: requestId={}, orgId={}, userId={}, memberRoleId={}", requestId, orgId,
|
||||
userId, memberRoleId);
|
||||
resourceAccessService.checkMemberRoleRights(orgId, userId, memberRoleId);
|
||||
organizationService.removeMemberRole(orgId, userId, memberRoleId);
|
||||
|
@ -24,7 +24,7 @@ public class UserController implements UserApi {
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Void> cancelOrgMembership(
|
||||
String xRequestID,
|
||||
String requestId,
|
||||
String orgId) {
|
||||
log.info("Cancel org membership: orgId={}", orgId);
|
||||
resourceAccessService.checkOrganizationRights(orgId);
|
||||
@ -34,7 +34,7 @@ public class UserController implements UserApi {
|
||||
|
||||
@Override
|
||||
public ResponseEntity<OrganizationMembership> inquireOrgMembership(
|
||||
String xRequestID,
|
||||
String requestId,
|
||||
String orgId) {
|
||||
log.info("Inquire org membership: orgId={}", orgId);
|
||||
resourceAccessService.checkOrganizationRights(orgId);
|
||||
@ -44,7 +44,7 @@ public class UserController implements UserApi {
|
||||
|
||||
@Override
|
||||
public ResponseEntity<OrganizationMembership> joinOrg(
|
||||
String xRequestID,
|
||||
String requestId,
|
||||
OrganizationJoinRequest body) {
|
||||
log.info("Join organization: body={}", body);
|
||||
resourceAccessService.checkOrganizationRights(body);
|
||||
@ -54,7 +54,8 @@ public class UserController implements UserApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<OrganizationSearchResult> listOrgMembership(String xRequestID, Integer limit,
|
||||
public ResponseEntity<OrganizationSearchResult> listOrgMembership(String requestId,
|
||||
Integer limit,
|
||||
String continuationToken) {
|
||||
log.info("List org membership: limit={}, continuationToken={}", limit, continuationToken);
|
||||
resourceAccessService.checkRights();
|
||||
|
@ -63,34 +63,34 @@ public class InvitationConverter {
|
||||
break;
|
||||
case ACCEPTED:
|
||||
invitation = new InvitationAccepted()
|
||||
.acceptedAt(OffsetDateTime.from(entity.getAcceptedAt()))
|
||||
.member(new InvitationAcceptedAllOfMember().id(entity.getAcceptedMemberId()));
|
||||
.acceptedAt(OffsetDateTime.from(entity.getAcceptedAt()))
|
||||
.member(new InvitationAcceptedAllOfMember().id(entity.getAcceptedMemberId()));
|
||||
break;
|
||||
case EXPIRED:
|
||||
invitation = new InvitationExpired();
|
||||
break;
|
||||
case REVOKED:
|
||||
invitation = new InvitationRevoked()
|
||||
.revokedAt(OffsetDateTime.from(entity.getRevokedAt()))
|
||||
.reason(entity.getRevocationReason());
|
||||
.revokedAt(OffsetDateTime.from(entity.getRevokedAt()))
|
||||
.reason(entity.getRevocationReason());
|
||||
break;
|
||||
default:
|
||||
invitation = new Invitation();
|
||||
}
|
||||
|
||||
invitation.id(entity.getId())
|
||||
.createdAt(OffsetDateTime.of(entity.getCreatedAt(), ZoneOffset.UTC))
|
||||
.expiresAt(OffsetDateTime.of(entity.getExpiresAt(), ZoneOffset.UTC))
|
||||
.acceptToken(entity.getAcceptToken())
|
||||
.metadata(entity.getMetadata() != null ? jsonMapper.toMap(entity.getMetadata()) : null)
|
||||
.invitee(new Invitee()
|
||||
.contact(new InviteeContact()
|
||||
.type(InviteeContact.TypeEnum.fromValue(entity.getInviteeContactType()))
|
||||
.email(entity.getInviteeContactEmail()))
|
||||
.roles(entity.getInviteeRoles()
|
||||
.stream()
|
||||
.map(memberRoleConverter::toDomain)
|
||||
.collect(Collectors.toList())));
|
||||
.createdAt(OffsetDateTime.of(entity.getCreatedAt(), ZoneOffset.UTC))
|
||||
.expiresAt(OffsetDateTime.of(entity.getExpiresAt(), ZoneOffset.UTC))
|
||||
.acceptToken(entity.getAcceptToken())
|
||||
.metadata(entity.getMetadata() != null ? jsonMapper.toMap(entity.getMetadata()) : null)
|
||||
.invitee(new Invitee()
|
||||
.contact(new InviteeContact()
|
||||
.type(InviteeContact.TypeEnum.fromValue(entity.getInviteeContactType()))
|
||||
.email(entity.getInviteeContactEmail()))
|
||||
.roles(entity.getInviteeRoles()
|
||||
.stream()
|
||||
.map(memberRoleConverter::toDomain)
|
||||
.collect(Collectors.toList())));
|
||||
|
||||
return invitation;
|
||||
}
|
||||
|
@ -15,7 +15,8 @@ public interface OrganizationRepository extends JpaRepository<OrganizationEntity
|
||||
" SELECT * FROM org_manager.organization AS o " +
|
||||
" WHERE o.id IN " +
|
||||
" ( " +
|
||||
" SELECT mo.organization_id FROM org_manager.member_to_organization AS mo WHERE mo.member_id = ?1 " +
|
||||
" SELECT mo.organization_id FROM org_manager.member_to_organization AS mo " +
|
||||
" WHERE mo.member_id = ?1 " +
|
||||
" UNION " +
|
||||
" SELECT id FROM org_manager.organization WHERE owner = ?1 " +
|
||||
" ) " +
|
||||
@ -27,7 +28,8 @@ public interface OrganizationRepository extends JpaRepository<OrganizationEntity
|
||||
" SELECT * FROM org_manager.organization AS o " +
|
||||
" WHERE o.id IN " +
|
||||
" ( " +
|
||||
" SELECT mo.organization_id FROM org_manager.member_to_organization AS mo WHERE mo.member_id = ?1 " +
|
||||
" SELECT mo.organization_id FROM org_manager.member_to_organization AS mo " +
|
||||
" WHERE mo.member_id = ?1 " +
|
||||
" UNION " +
|
||||
" SELECT id FROM org_manager.organization WHERE owner = ?1 " +
|
||||
" ) " +
|
||||
|
@ -21,9 +21,9 @@ public class AuthContextService implements AuthContextProviderSrv.Iface {
|
||||
new com.rbkmoney.bouncer.context.v1.ContextFragment();
|
||||
User user = userService.findById(id);
|
||||
contextFragment.setUser(user);
|
||||
TSerializer tSerializer = new TSerializer();
|
||||
TSerializer byteSerializer = new TSerializer();
|
||||
return new ContextFragment()
|
||||
.setType(ContextFragmentType.v1_thrift_binary)
|
||||
.setContent(tSerializer.serialize(contextFragment));
|
||||
.setContent(byteSerializer.serialize(contextFragment));
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ public class InvitationService {
|
||||
public ResponseEntity<Invitation> create(
|
||||
String orgId,
|
||||
InvitationRequest invitation,
|
||||
String xIdempotencyKey) {
|
||||
String idempotencyKey) {
|
||||
InvitationEntity entity = invitationConverter.toEntity(invitation, orgId);
|
||||
InvitationEntity savedEntity = invitationRepository.save(entity);
|
||||
|
||||
|
@ -1,22 +1,24 @@
|
||||
package com.rbkmoney.orgmanager.service;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.rbkmoney.orgmanager.converter.OrganizationRoleConverter;
|
||||
import com.rbkmoney.orgmanager.entity.OrganizationEntity;
|
||||
import com.rbkmoney.orgmanager.entity.OrganizationRoleEntity;
|
||||
import com.rbkmoney.orgmanager.exception.ResourceNotFoundException;
|
||||
import com.rbkmoney.orgmanager.repository.OrganizationRepository;
|
||||
import com.rbkmoney.orgmanager.repository.OrganizationRoleRepository;
|
||||
import com.rbkmoney.swag.organizations.model.Role;
|
||||
import com.rbkmoney.swag.organizations.model.RoleAvailableListResult;
|
||||
import com.rbkmoney.swag.organizations.model.RoleId;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
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 {
|
||||
@ -25,25 +27,15 @@ public class OrganizationRoleService {
|
||||
private final OrganizationRoleRepository organizationRoleRepository;
|
||||
private final OrganizationRoleConverter organizationRoleConverter;
|
||||
|
||||
public ResponseEntity<Role> get(String orgId, RoleId roleId) {
|
||||
boolean isOrganizationExists = organizationRepository.existsById(orgId);
|
||||
|
||||
if (!isOrganizationExists) {
|
||||
return ResponseEntity
|
||||
.status(HttpStatus.NOT_FOUND)
|
||||
.build();
|
||||
public Role get(String orgId, RoleId roleId) {
|
||||
if (!organizationRepository.existsById(orgId)) {
|
||||
throw new ResourceNotFoundException();
|
||||
}
|
||||
OrganizationRoleEntity entity =
|
||||
organizationRoleRepository.findByOrganizationIdAndRoleId(orgId, roleId.toString())
|
||||
.orElseThrow(ResourceNotFoundException::new);
|
||||
|
||||
Optional<OrganizationRoleEntity> entity = organizationRoleRepository.findByOrganizationIdAndRoleId(orgId, roleId.toString());
|
||||
|
||||
if (entity.isEmpty()) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
Role role = organizationRoleConverter.toDomain(entity.get());
|
||||
return ResponseEntity
|
||||
.status(HttpStatus.OK)
|
||||
.body(role);
|
||||
return organizationRoleConverter.toDomain(entity);
|
||||
}
|
||||
|
||||
public ResponseEntity<RoleAvailableListResult> list(String orgId) {
|
||||
|
@ -46,7 +46,7 @@ public class OrganizationService {
|
||||
public ResponseEntity<Organization> create(
|
||||
String ownerId,
|
||||
Organization organization,
|
||||
String xIdempotencyKey) {
|
||||
String idempotencyKey) {
|
||||
OrganizationEntity entity = organizationConverter.toEntity(organization, ownerId);
|
||||
OrganizationEntity savedEntity = organizationRepository.save(entity);
|
||||
|
||||
@ -166,10 +166,10 @@ public class OrganizationService {
|
||||
}
|
||||
|
||||
private List<OrganizationEntity> getOrganizationsByUser(String continuationId, String userId) {
|
||||
if (StringUtils.isEmpty(continuationId)) {
|
||||
return organizationRepository.findAllByMember(userId);
|
||||
if (StringUtils.hasLength(continuationId)) {
|
||||
return organizationRepository.findAllByMember(userId, continuationId);
|
||||
}
|
||||
return organizationRepository.findAllByMember(userId, continuationId);
|
||||
return organizationRepository.findAllByMember(userId);
|
||||
}
|
||||
|
||||
private List<OrganizationEntity> limitOrganizations(Integer limit,
|
||||
|
@ -87,12 +87,12 @@ public abstract class TestObjectFactory {
|
||||
}
|
||||
|
||||
public static InvitationRequest testInvitationRequest() {
|
||||
InvitationRequest invitationRequest = new InvitationRequest();
|
||||
Invitee invitee = new Invitee();
|
||||
InviteeContact inviteeContact = new InviteeContact();
|
||||
inviteeContact.setEmail(randomString());
|
||||
inviteeContact.setType(InviteeContact.TypeEnum.EMAIL);
|
||||
invitee.setContact(inviteeContact);
|
||||
InvitationRequest invitationRequest = new InvitationRequest();
|
||||
invitationRequest.setInvitee(invitee);
|
||||
return invitationRequest;
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ public abstract class AbstractControllerTest extends AbstractRepositoryTest {
|
||||
return keycloakOpenIdStub.generateJwt(iat, exp, roles);
|
||||
}
|
||||
|
||||
protected String generateRBKadminJwt() {
|
||||
protected String generateRbkAdminJwt() {
|
||||
return keycloakOpenIdStub.generateJwt("RBKadmin");
|
||||
}
|
||||
|
||||
|
@ -12,9 +12,9 @@ import java.util.UUID;
|
||||
|
||||
public class JwtTokenBuilder {
|
||||
|
||||
public final static String DEFAULT_USERNAME = "Darth Vader";
|
||||
public static final String DEFAULT_USERNAME = "Darth Vader";
|
||||
|
||||
public final static String DEFAULT_EMAIL = "darkside-the-best@mail.com";
|
||||
public static final String DEFAULT_EMAIL = "darkside-the-best@mail.com";
|
||||
|
||||
private final String userId;
|
||||
|
||||
|
@ -1,9 +1,6 @@
|
||||
package com.rbkmoney.orgmanager.controller;
|
||||
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.get;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.*;
|
||||
|
||||
public class KeycloakOpenIdStub {
|
||||
|
||||
@ -18,15 +15,15 @@ public class KeycloakOpenIdStub {
|
||||
this.issuer = keycloakAuthServerUrl + "/realms/" + keycloakRealm;
|
||||
this.openidConfig = "{\n" +
|
||||
" \"issuer\": \"" + issuer + "\",\n" +
|
||||
" \"authorization_endpoint\": \"" + keycloakAuthServerUrl + "/realms/" + keycloakRealm + "/protocol/openid-connect/auth\",\n" +
|
||||
" \"token_endpoint\": \"" + keycloakAuthServerUrl + "/realms/" + keycloakRealm + "/protocol/openid-connect/token\",\n" +
|
||||
" \"token_introspection_endpoint\": \"" + keycloakAuthServerUrl + "/realms/" + keycloakRealm + "/protocol/openid-connect/token/introspect\",\n" +
|
||||
" \"userinfo_endpoint\": \"" + keycloakAuthServerUrl + "/realms/" + keycloakRealm + "/protocol/openid-connect/userinfo\",\n" +
|
||||
" \"end_session_endpoint\": \"" + keycloakAuthServerUrl + "/realms/" + keycloakRealm + "/protocol/openid-connect/logout\",\n" +
|
||||
" \"jwks_uri\": \"" + keycloakAuthServerUrl + "/realms/" + keycloakRealm + "/protocol/openid-connect/certs\",\n" +
|
||||
" \"check_session_iframe\": \"" + keycloakAuthServerUrl + "/realms/" + keycloakRealm + "/protocol/openid-connect/login-status-iframe.html\",\n" +
|
||||
" \"registration_endpoint\": \"" + keycloakAuthServerUrl + "/realms/" + keycloakRealm + "/clients-registrations/openid-connect\",\n" +
|
||||
" \"introspection_endpoint\": \"" + keycloakAuthServerUrl + "/realms/" + keycloakRealm + "/protocol/openid-connect/token/introspect\"\n" +
|
||||
" \"authorization_endpoint\": \"" + issuer + "/protocol/openid-connect/auth\",\n" +
|
||||
" \"token_endpoint\": \"" + issuer + "/protocol/openid-connect/token\",\n" +
|
||||
" \"token_introspection_endpoint\": \"" + issuer + "/protocol/openid-connect/token/introspect\",\n" +
|
||||
" \"userinfo_endpoint\": \"" + issuer + "/protocol/openid-connect/userinfo\",\n" +
|
||||
" \"end_session_endpoint\": \"" + issuer + "/protocol/openid-connect/logout\",\n" +
|
||||
" \"jwks_uri\": \"" + issuer + "/protocol/openid-connect/certs\",\n" +
|
||||
" \"check_session_iframe\": \"" + issuer + "/protocol/openid-connect/login-status-iframe.html\",\n" +
|
||||
" \"registration_endpoint\": \"" + issuer + "/clients-registrations/openid-connect\",\n" +
|
||||
" \"introspection_endpoint\": \"" + issuer + "/protocol/openid-connect/token/introspect\"\n" +
|
||||
"}";
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ public class KeycloakTestConfig {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JwtTokenBuilder JwtTokenBuilder(KeyPair keyPair) {
|
||||
public JwtTokenBuilder jwtTokenBuilder(KeyPair keyPair) {
|
||||
return new JwtTokenBuilder(keyPair.getPrivate());
|
||||
}
|
||||
|
||||
@ -36,7 +36,8 @@ public class KeycloakTestConfig {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public static PropertySourcesPlaceholderConfigurer properties(KeyPair keyPair) throws NoSuchAlgorithmException, InvalidKeySpecException, IOException {
|
||||
public static PropertySourcesPlaceholderConfigurer properties(KeyPair keyPair)
|
||||
throws NoSuchAlgorithmException, InvalidKeySpecException, IOException {
|
||||
KeyFactory fact = KeyFactory.getInstance("RSA");
|
||||
X509EncodedKeySpec spec = fact.getKeySpec(keyPair.getPublic(), X509EncodedKeySpec.class);
|
||||
String publicKey = Base64.getEncoder().encodeToString(spec.getEncoded());
|
||||
|
@ -39,7 +39,7 @@ public class OrgsControllerTest extends AbstractControllerTest {
|
||||
|
||||
mockMvc.perform(delete(String.format("/orgs/%s/members/%s", ORGANIZATION_ID, MEMBER_ID))
|
||||
.contentType("application/json")
|
||||
.header("Authorization", "Bearer " + generateRBKadminJwt())
|
||||
.header("Authorization", "Bearer " + generateRbkAdminJwt())
|
||||
.header("X-Request-ID", "testRequestId"))
|
||||
.andExpect(status().isFailedDependency());
|
||||
}
|
||||
@ -51,7 +51,7 @@ public class OrgsControllerTest extends AbstractControllerTest {
|
||||
|
||||
mockMvc.perform(delete(String.format("/orgs/%s/members/%s", ORGANIZATION_ID, MEMBER_ID))
|
||||
.contentType("application/json")
|
||||
.header("Authorization", "Bearer " + generateRBKadminJwt())
|
||||
.header("Authorization", "Bearer " + generateRbkAdminJwt())
|
||||
.header("X-Request-ID", "testRequestId"))
|
||||
.andExpect(status().isForbidden());
|
||||
}
|
||||
@ -65,7 +65,7 @@ public class OrgsControllerTest extends AbstractControllerTest {
|
||||
mockMvc.perform(post(String.format("/orgs/%s/members/%s/roles", ORGANIZATION_ID, MEMBER_ID))
|
||||
.contentType("application/json")
|
||||
.content(objectMapper.writeValueAsString(memberRole))
|
||||
.header("Authorization", "Bearer " + generateRBKadminJwt())
|
||||
.header("Authorization", "Bearer " + generateRbkAdminJwt())
|
||||
.header("X-Request-ID", "testRequestId"))
|
||||
.andExpect(status().isForbidden());
|
||||
}
|
||||
@ -77,7 +77,9 @@ public class OrgsControllerTest extends AbstractControllerTest {
|
||||
|
||||
MemberEntity memberEntity = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
||||
OrganizationEntity organization = TestObjectFactory.buildOrganization(memberEntity);
|
||||
MemberRoleEntity savedMemberRole = memberRoleRepository.save(TestObjectFactory.buildMemberRole(RoleId.ACCOUNTANT, organization.getId()));
|
||||
MemberRoleEntity memberRoleEntity = TestObjectFactory.buildMemberRole(RoleId.ACCOUNTANT, organization.getId());
|
||||
MemberRoleEntity savedMemberRole = memberRoleRepository.save(
|
||||
memberRoleEntity);
|
||||
memberEntity.setRoles(Set.of(savedMemberRole));
|
||||
MemberEntity savedMember = memberRepository.save(memberEntity);
|
||||
OrganizationEntity savedOrganization = organizationRepository.save(organization);
|
||||
@ -87,7 +89,7 @@ public class OrgsControllerTest extends AbstractControllerTest {
|
||||
mockMvc.perform(post(String.format("/orgs/%s/members/%s/roles", savedOrganization.getId(), savedMember.getId()))
|
||||
.contentType("application/json")
|
||||
.content(objectMapper.writeValueAsString(memberRole))
|
||||
.header("Authorization", "Bearer " + generateRBKadminJwt())
|
||||
.header("Authorization", "Bearer " + generateRbkAdminJwt())
|
||||
.header("X-Request-ID", "testRequestId"))
|
||||
.andExpect(status().isCreated())
|
||||
.andExpect(jsonPath("$.id").isNotEmpty())
|
||||
@ -112,7 +114,7 @@ public class OrgsControllerTest extends AbstractControllerTest {
|
||||
|
||||
mockMvc.perform(delete(String.format("/orgs/%s/members/%s", savedOrganization.getId(), savedMember.getId()))
|
||||
.contentType("application/json")
|
||||
.header("Authorization", "Bearer " + generateRBKadminJwt())
|
||||
.header("Authorization", "Bearer " + generateRbkAdminJwt())
|
||||
.header("X-Request-ID", "testRequestId"))
|
||||
.andExpect(status().isNoContent());
|
||||
|
||||
@ -127,16 +129,21 @@ public class OrgsControllerTest extends AbstractControllerTest {
|
||||
void removeMemberRoleTest() throws Exception {
|
||||
MemberEntity memberEntity = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
||||
OrganizationEntity organization = TestObjectFactory.buildOrganization(memberEntity);
|
||||
MemberRoleEntity savedMemberRole = memberRoleRepository.save(TestObjectFactory.buildMemberRole(RoleId.ACCOUNTANT, organization.getId()));
|
||||
MemberRoleEntity memberRoleEntity = TestObjectFactory.buildMemberRole(RoleId.ACCOUNTANT, organization.getId());
|
||||
MemberRoleEntity savedMemberRole = memberRoleRepository.save(
|
||||
memberRoleEntity);
|
||||
memberEntity.setRoles(Set.of(savedMemberRole));
|
||||
MemberEntity savedMember = memberRepository.save(memberEntity);
|
||||
OrganizationEntity savedOrganization = organizationRepository.save(organization);
|
||||
|
||||
mockMvc.perform(delete(String.format("/orgs/%s/members/%s/roles/%s", savedOrganization.getId(), savedMember.getId(), savedMemberRole.getId()))
|
||||
mockMvc.perform(delete(
|
||||
String.format("/orgs/%s/members/%s/roles/%s", savedOrganization.getId(), savedMember.getId(),
|
||||
savedMemberRole.getId())
|
||||
)
|
||||
.contentType("application/json")
|
||||
.header("Authorization", "Bearer " + generateRBKadminJwt())
|
||||
.header("X-Request-ID", "testRequestId")).
|
||||
andExpect(status().isNoContent());
|
||||
.header("Authorization", "Bearer " + generateRbkAdminJwt())
|
||||
.header("X-Request-ID", "testRequestId"))
|
||||
.andExpect(status().isNoContent());
|
||||
|
||||
|
||||
assertThat(memberRepository.findById(savedMember.getId()).get().getRoles(), not(hasItem(savedMemberRole)));
|
||||
@ -155,7 +162,7 @@ public class OrgsControllerTest extends AbstractControllerTest {
|
||||
mockMvc.perform(post(String.format("/orgs/%s/invitations", ORGANIZATION_ID))
|
||||
.contentType("application/json")
|
||||
.content(body)
|
||||
.header("Authorization", "Bearer " + generateRBKadminJwt())
|
||||
.header("Authorization", "Bearer " + generateRbkAdminJwt())
|
||||
.header("X-Request-ID", "testRequestId"))
|
||||
.andExpect(status().isForbidden());
|
||||
}
|
||||
@ -170,19 +177,23 @@ public class OrgsControllerTest extends AbstractControllerTest {
|
||||
mockMvc.perform(post(String.format("/orgs/%s/invitations", ORGANIZATION_ID))
|
||||
.contentType("application/json")
|
||||
.content(body)
|
||||
.header("Authorization", "Bearer " + generateRBKadminJwt())
|
||||
.header("Authorization", "Bearer " + generateRbkAdminJwt())
|
||||
.header("X-Request-ID", "testRequestId"))
|
||||
.andExpect(jsonPath("$.status", is("Pending")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listOrgMembersTest() throws Exception {
|
||||
MemberEntity savedMember = memberRepository.save(TestObjectFactory.testMemberEntity(TestObjectFactory.randomString()));
|
||||
OrganizationEntity savedOrganization = organizationRepository.save(TestObjectFactory.buildOrganization(savedMember));
|
||||
MemberEntity memberEntity = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
||||
MemberEntity savedMember = memberRepository.save(
|
||||
memberEntity);
|
||||
OrganizationEntity organizationEntity = TestObjectFactory.buildOrganization(savedMember);
|
||||
OrganizationEntity savedOrganization = organizationRepository.save(
|
||||
organizationEntity);
|
||||
|
||||
mockMvc.perform(get(String.format("/orgs/%s/members", savedOrganization.getId()))
|
||||
.contentType("application/json")
|
||||
.header("Authorization", "Bearer " + generateRBKadminJwt())
|
||||
.header("Authorization", "Bearer " + generateRbkAdminJwt())
|
||||
.header("X-Request-ID", "testRequestId"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.result", anything()));
|
||||
|
@ -36,7 +36,7 @@ public class UserControllerTest extends AbstractControllerTest {
|
||||
mockMvc.perform(post("/user/membership")
|
||||
.contentType("application/json")
|
||||
.content(objectMapper.writeValueAsString(organizationJoinRequest))
|
||||
.header("Authorization", "Bearer " + generateRBKadminJwt())
|
||||
.header("Authorization", "Bearer " + generateRbkAdminJwt())
|
||||
.header("X-Request-ID", "testRequestId"))
|
||||
.andExpect(status().isNotFound());
|
||||
}
|
||||
@ -51,14 +51,14 @@ public class UserControllerTest extends AbstractControllerTest {
|
||||
mockMvc.perform(post("/user/membership")
|
||||
.contentType("application/json")
|
||||
.content(objectMapper.writeValueAsString(organizationJoinRequest))
|
||||
.header("Authorization", "Bearer " + generateRBKadminJwt())
|
||||
.header("Authorization", "Bearer " + generateRbkAdminJwt())
|
||||
.header("X-Request-ID", "testRequestId"))
|
||||
.andExpect(status().isForbidden());
|
||||
}
|
||||
|
||||
@Test
|
||||
void joinOrgNewMemberTest() throws Exception {
|
||||
String jwtToken = generateRBKadminJwt();
|
||||
String jwtToken = generateRbkAdminJwt();
|
||||
String userId = getUserFromToken();
|
||||
OrganizationEntity savedOrg = organizationRepository.save(buildOrganization());
|
||||
InvitationEntity savedInvitation = invitationRepository.save(buildInvitation(savedOrg.getId()));
|
||||
@ -89,7 +89,7 @@ public class UserControllerTest extends AbstractControllerTest {
|
||||
|
||||
@Test
|
||||
void joinOrgExistMemberTest() throws Exception {
|
||||
String jwtToken = generateRBKadminJwt();
|
||||
String jwtToken = generateRbkAdminJwt();
|
||||
String userId = getUserFromToken();
|
||||
memberRepository.save(testMemberEntity(userId));
|
||||
OrganizationEntity savedOrg = organizationRepository.save(buildOrganization());
|
||||
@ -123,7 +123,7 @@ public class UserControllerTest extends AbstractControllerTest {
|
||||
@Test
|
||||
@Transactional
|
||||
void cancelOrgMembershipTest() throws Exception {
|
||||
String jwtToken = generateRBKadminJwt();
|
||||
String jwtToken = generateRbkAdminJwt();
|
||||
String userId = getUserFromToken();
|
||||
MemberEntity member = memberRepository.save(testMemberEntity(userId));
|
||||
OrganizationEntity orgWithMember = organizationRepository.save(buildOrganization(member));
|
||||
@ -140,7 +140,7 @@ public class UserControllerTest extends AbstractControllerTest {
|
||||
|
||||
@Test
|
||||
void inquireOrgMembershipTest() throws Exception {
|
||||
String jwtToken = generateRBKadminJwt();
|
||||
String jwtToken = generateRbkAdminJwt();
|
||||
String userId = getUserFromToken();
|
||||
MemberEntity member = memberRepository.save(testMemberEntity(userId));
|
||||
OrganizationEntity orgWithMember = organizationRepository.save(buildOrganization(member));
|
||||
@ -159,7 +159,7 @@ public class UserControllerTest extends AbstractControllerTest {
|
||||
|
||||
@Test
|
||||
void listOrgMembershipWithoutLimitTest() throws Exception {
|
||||
String jwtToken = generateRBKadminJwt();
|
||||
String jwtToken = generateRbkAdminJwt();
|
||||
String userId = getUserFromToken();
|
||||
MemberEntity targetMember = memberRepository.save(testMemberEntity(userId));
|
||||
Set<OrganizationEntity> targetEntities = buildOrganization(targetMember, 7);
|
||||
@ -179,7 +179,6 @@ public class UserControllerTest extends AbstractControllerTest {
|
||||
|
||||
@Test
|
||||
void listOrgMembershipTest() throws Exception {
|
||||
String jwtToken = generateRBKadminJwt();
|
||||
String userId = getUserFromToken();
|
||||
MemberEntity targetMember = memberRepository.save(testMemberEntity(userId));
|
||||
Set<OrganizationEntity> targetEntities = buildOrganization(targetMember, 9);
|
||||
@ -189,6 +188,7 @@ public class UserControllerTest extends AbstractControllerTest {
|
||||
targetEntities.addAll(List.of(anotherOrganization, organizationWithOwner));
|
||||
organizationRepository.saveAll(targetEntities);
|
||||
String limit = "4";
|
||||
String jwtToken = generateRbkAdminJwt();
|
||||
|
||||
MvcResult mvcResultFirst = mockMvc.perform(get("/user/membership")
|
||||
.queryParam("limit", limit)
|
||||
|
@ -24,7 +24,7 @@ public class AuthContextServiceTest {
|
||||
@InjectMocks
|
||||
private AuthContextService service;
|
||||
|
||||
private final TDeserializer tDeserializer = new TDeserializer();
|
||||
private final TDeserializer byteDeserializer = new TDeserializer();
|
||||
|
||||
@Test
|
||||
void testUserContext() throws TException {
|
||||
@ -37,7 +37,7 @@ public class AuthContextServiceTest {
|
||||
verify(userService, times(1)).findById(id);
|
||||
com.rbkmoney.bouncer.context.v1.ContextFragment contextFragment =
|
||||
new com.rbkmoney.bouncer.context.v1.ContextFragment();
|
||||
tDeserializer.deserialize(contextFragment, userContext.getContent());
|
||||
byteDeserializer.deserialize(contextFragment, userContext.getContent());
|
||||
|
||||
|
||||
assertEquals(user.getId(), contextFragment.getUser().getId());
|
||||
|
@ -56,8 +56,8 @@ class BouncerContextFactoryTest {
|
||||
ContextFragment fragment = context.getFragments().get(bouncerProperties.getContextFragmentId());
|
||||
com.rbkmoney.bouncer.context.v1.ContextFragment contextFragment =
|
||||
new com.rbkmoney.bouncer.context.v1.ContextFragment();
|
||||
TDeserializer tDeserializer = new TDeserializer();
|
||||
tDeserializer.deserialize(contextFragment, fragment.getContent());
|
||||
TDeserializer byteDeserializer = new TDeserializer();
|
||||
byteDeserializer.deserialize(contextFragment, fragment.getContent());
|
||||
|
||||
assertEquals(ContextFragmentType.v1_thrift_binary, fragment.getType());
|
||||
assertEquals(token.getId(), contextFragment.getAuth().getToken().getId());
|
||||
|
@ -212,13 +212,12 @@ public class InvitationServiceTest {
|
||||
|
||||
@Test
|
||||
void shouldThrowInviteRevokedExceptionIfInvitationRevoked() {
|
||||
String token = TestObjectFactory.randomString();
|
||||
String orgId = TestObjectFactory.randomString();
|
||||
InvitationEntity invitationEntity = TestObjectFactory.buildInvitation(orgId);
|
||||
invitationEntity.setStatus(InvitationStatusName.REVOKED.getValue());
|
||||
invitationEntity.setRevokedAt(LocalDateTime.now());
|
||||
invitationEntity.setRevocationReason(TestObjectFactory.randomString());
|
||||
|
||||
String token = TestObjectFactory.randomString();
|
||||
when(invitationRepository.findByAcceptToken(token))
|
||||
.thenReturn(Optional.of(invitationEntity));
|
||||
|
||||
|
@ -3,6 +3,7 @@ package com.rbkmoney.orgmanager.service;
|
||||
import com.rbkmoney.orgmanager.converter.OrganizationRoleConverter;
|
||||
import com.rbkmoney.orgmanager.entity.OrganizationEntity;
|
||||
import com.rbkmoney.orgmanager.entity.OrganizationRoleEntity;
|
||||
import com.rbkmoney.orgmanager.exception.ResourceNotFoundException;
|
||||
import com.rbkmoney.orgmanager.repository.OrganizationRepository;
|
||||
import com.rbkmoney.orgmanager.repository.OrganizationRoleRepository;
|
||||
import com.rbkmoney.swag.organizations.model.Role;
|
||||
@ -20,6 +21,7 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@ -80,13 +82,10 @@ public class OrganizationRoleServiceTest {
|
||||
|
||||
@Test
|
||||
void shouldFindRoleById() {
|
||||
// Given
|
||||
OrganizationRoleEntity organizationRoleEntity = new OrganizationRoleEntity();
|
||||
Role role = new Role();
|
||||
|
||||
String orgId = "orgId";
|
||||
RoleId roleId = RoleId.ADMINISTRATOR;
|
||||
|
||||
when(organizationRepository.existsById(orgId))
|
||||
.thenReturn(true);
|
||||
when(organizationRoleRepository.findByOrganizationIdAndRoleId(orgId, roleId.getValue()))
|
||||
@ -94,32 +93,20 @@ public class OrganizationRoleServiceTest {
|
||||
when(organizationRoleConverter.toDomain(organizationRoleEntity))
|
||||
.thenReturn(role);
|
||||
|
||||
// When
|
||||
ResponseEntity<Role> response = service.get(orgId, roleId);
|
||||
Role response = service.get(orgId, roleId);
|
||||
|
||||
// Then
|
||||
assertThat(response.getStatusCode())
|
||||
.isEqualTo(HttpStatus.OK);
|
||||
assertThat(response.getBody())
|
||||
assertThat(response)
|
||||
.isEqualTo(role);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnNotFoundIfOrganizationDoesNotExist() {
|
||||
// Given
|
||||
String orgId = "orgId";
|
||||
RoleId roleId = RoleId.ADMINISTRATOR;
|
||||
|
||||
when(organizationRepository.existsById(orgId))
|
||||
.thenReturn(false);
|
||||
|
||||
// When
|
||||
ResponseEntity<Role> response = service.get(orgId, roleId);
|
||||
assertThrows(ResourceNotFoundException.class, () -> service.get(orgId, roleId));
|
||||
|
||||
// Then
|
||||
assertThat(response.getStatusCode())
|
||||
.isEqualTo(HttpStatus.NOT_FOUND);
|
||||
assertThat(response.getBody())
|
||||
.isNull();
|
||||
}
|
||||
}
|
||||
|
@ -145,9 +145,7 @@ public class OrganizationServiceIntegrationTest extends AbstractRepositoryTest {
|
||||
void shouldGetListOrgMembers() {
|
||||
MemberEntity member1 = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
||||
MemberEntity member2 = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
||||
MemberEntity anotherMember = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
|
||||
OrganizationEntity organization = TestObjectFactory.buildOrganization(Set.of(member1, member2));
|
||||
OrganizationEntity anotherOrganization = TestObjectFactory.buildOrganization(Set.of(anotherMember));
|
||||
MemberRoleEntity activeMember1RoleInOrg = buildMemberRole(RoleId.ACCOUNTANT, organization.getId());
|
||||
activeMember1RoleInOrg.setActive(Boolean.TRUE);
|
||||
MemberRoleEntity savedMember1Role = memberRoleRepository.save(activeMember1RoleInOrg);
|
||||
@ -159,6 +157,8 @@ public class OrganizationServiceIntegrationTest extends AbstractRepositoryTest {
|
||||
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());
|
||||
activeAnotherMemberRoleInOrg.setActive(Boolean.TRUE);
|
||||
MemberRoleEntity savedAnotherRole = memberRoleRepository.save(activeAnotherMemberRoleInOrg);
|
||||
|
@ -38,7 +38,8 @@ class ResourceAccessServiceImplTest {
|
||||
void setUp() {
|
||||
accessProperties = new AccessProperties();
|
||||
accessProperties.setEnabled(true);
|
||||
resourceAccessService = new ResourceAccessServiceImpl(accessProperties, bouncerService, organizationService, memberRoleService);
|
||||
resourceAccessService =
|
||||
new ResourceAccessServiceImpl(accessProperties, bouncerService, organizationService, memberRoleService);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -186,7 +187,7 @@ class ResourceAccessServiceImplTest {
|
||||
.thenThrow(new ResourceNotFoundException());
|
||||
|
||||
assertThrows(ResourceNotFoundException.class,
|
||||
() -> resourceAccessService.checkMemberRoleRights(orgId,memberId, memberRoleId));
|
||||
() -> resourceAccessService.checkMemberRoleRights(orgId, memberId, memberRoleId));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -72,17 +72,13 @@ public class TestData {
|
||||
}
|
||||
|
||||
public static InvitationRequest buildInvitationRequest() {
|
||||
InvitationRequest invitation = new InvitationRequest();
|
||||
|
||||
Invitee invitee = new Invitee();
|
||||
|
||||
InviteeContact inviteeContact = new InviteeContact();
|
||||
inviteeContact.setEmail("testEmail@mail.ru");
|
||||
inviteeContact.setType(InviteeContact.TypeEnum.EMAIL);
|
||||
Invitee invitee = new Invitee();
|
||||
invitee.setContact(inviteeContact);
|
||||
|
||||
invitee.setRoles(List.of(buildMemberRole()));
|
||||
|
||||
InvitationRequest invitation = new InvitationRequest();
|
||||
invitation.setInvitee(invitee);
|
||||
Map<String, String> metadata = new HashMap<>();
|
||||
metadata.put("testKey", "testValue");
|
||||
|
Loading…
Reference in New Issue
Block a user