switch orgId -> party in bouncer context (#37)

Co-authored-by: ggmaleva <ggmaleva@yandex.ru>
This commit is contained in:
Gregory 2022-09-09 14:38:37 +03:00 committed by GitHub
parent 79ed676b13
commit b7dee2e7d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 7 deletions

View File

@ -306,10 +306,10 @@ public class OrganizationService {
}
@Transactional(readOnly = true)
public String getOrgIdByInvitationToken(String token) {
public String getPartyByInvitationToken(String token) {
InvitationEntity invitationEntity = invitationService.findByToken(token);
OrganizationEntity organizationEntity = findById(invitationEntity.getOrganizationId());
return organizationEntity.getId();
return organizationEntity.getParty();
}
public OrganizationEntity findById(String orgId) {

View File

@ -1,6 +1,7 @@
package dev.vality.orgmanager.service;
import dev.vality.orgmanager.config.properties.AccessProperties;
import dev.vality.orgmanager.entity.OrganizationEntity;
import dev.vality.orgmanager.exception.AccessDeniedException;
import dev.vality.orgmanager.service.dto.BouncerContextDto;
import dev.vality.orgmanager.service.dto.InvitationDto;
@ -44,10 +45,15 @@ public class ResourceAccessServiceImpl implements ResourceAccessService {
}
String callerMethodName = StackUtils.getCallerMethodName();
BouncerContextDto bouncerContext = buildBouncerContextDto(resource, callerMethodName);
if (Objects.nonNull(resource.getOrgId())) {
log.info("Get organization by orgId: {}", resource.getOrgId());
OrganizationEntity organization = organizationService.findById(resource.getOrgId());
bouncerContext.setOrganizationId(organization.getParty());
}
if (Objects.nonNull(resource.getInvitationToken())) {
log.info("Get organization by invitation token");
String orgId = organizationService.getOrgIdByInvitationToken(resource.getInvitationToken());
bouncerContext.setOrganizationId(orgId);
String party = organizationService.getPartyByInvitationToken(resource.getInvitationToken());
bouncerContext.setOrganizationId(party);
}
if (Objects.nonNull(resource.getMemberRoleId())) {
String memberRoleId = resource.getMemberRoleId();

View File

@ -63,10 +63,12 @@ class ResourceAccessServiceImplTest {
@Test
void checkOrgRights() {
String orgId = TestObjectFactory.randomString();
ResourceDto resource = ResourceDto.builder()
.orgId(TestObjectFactory.randomString())
.orgId(orgId)
.build();
when(bouncerService.havePrivileges(any(BouncerContextDto.class))).thenReturn(true);
when(organizationService.findById(orgId)).thenReturn(TestObjectFactory.buildOrganization());
assertDoesNotThrow(() -> resourceAccessService.checkRights(resource));
}
@ -77,7 +79,7 @@ class ResourceAccessServiceImplTest {
.invitationToken(TestObjectFactory.randomString())
.build();
when(bouncerService.havePrivileges(any(BouncerContextDto.class))).thenReturn(true);
when(organizationService.getOrgIdByInvitationToken(resource.getInvitationToken()))
when(organizationService.getPartyByInvitationToken(resource.getInvitationToken()))
.thenThrow(new ResourceNotFoundException());
assertThrows(ResourceNotFoundException.class,
@ -96,11 +98,13 @@ class ResourceAccessServiceImplTest {
@Test
void checkMemberRights() {
String orgId = TestObjectFactory.randomString();
ResourceDto resource = ResourceDto.builder()
.orgId(TestObjectFactory.randomString())
.orgId(orgId)
.memberId(TestObjectFactory.randomString())
.build();
when(bouncerService.havePrivileges(any(BouncerContextDto.class))).thenReturn(true);
when(organizationService.findById(orgId)).thenReturn(TestObjectFactory.buildOrganization());
assertDoesNotThrow(() -> resourceAccessService.checkRights(resource));
}