From d18e24fc780131a2b8d65c735eb28cf0d8b2a16d Mon Sep 17 00:00:00 2001 From: Gregory <32060161+ggmaleva@users.noreply.github.com> Date: Tue, 13 Sep 2022 13:28:25 +0300 Subject: [PATCH] revert party id -> org id (#39) Co-authored-by: ggmaleva --- .../vality/orgmanager/service/OrganizationService.java | 4 ++-- .../orgmanager/service/ResourceAccessServiceImpl.java | 10 ++-------- .../service/ResourceAccessServiceImplTest.java | 10 +++------- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/main/java/dev/vality/orgmanager/service/OrganizationService.java b/src/main/java/dev/vality/orgmanager/service/OrganizationService.java index 334ab2c..bf94c66 100644 --- a/src/main/java/dev/vality/orgmanager/service/OrganizationService.java +++ b/src/main/java/dev/vality/orgmanager/service/OrganizationService.java @@ -306,10 +306,10 @@ public class OrganizationService { } @Transactional(readOnly = true) - public String getPartyByInvitationToken(String token) { + public String getOrgIdByInvitationToken(String token) { InvitationEntity invitationEntity = invitationService.findByToken(token); OrganizationEntity organizationEntity = findById(invitationEntity.getOrganizationId()); - return organizationEntity.getParty(); + return organizationEntity.getId(); } public OrganizationEntity findById(String orgId) { diff --git a/src/main/java/dev/vality/orgmanager/service/ResourceAccessServiceImpl.java b/src/main/java/dev/vality/orgmanager/service/ResourceAccessServiceImpl.java index 2ca6cc7..5fd8a2b 100644 --- a/src/main/java/dev/vality/orgmanager/service/ResourceAccessServiceImpl.java +++ b/src/main/java/dev/vality/orgmanager/service/ResourceAccessServiceImpl.java @@ -1,7 +1,6 @@ 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; @@ -45,15 +44,10 @@ 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 party = organizationService.getPartyByInvitationToken(resource.getInvitationToken()); - bouncerContext.setOrganizationId(party); + String orgId = organizationService.getOrgIdByInvitationToken(resource.getInvitationToken()); + bouncerContext.setOrganizationId(orgId); } if (Objects.nonNull(resource.getMemberRoleId())) { String memberRoleId = resource.getMemberRoleId(); diff --git a/src/test/java/dev/vality/orgmanager/service/ResourceAccessServiceImplTest.java b/src/test/java/dev/vality/orgmanager/service/ResourceAccessServiceImplTest.java index 5d13e6e..f529164 100644 --- a/src/test/java/dev/vality/orgmanager/service/ResourceAccessServiceImplTest.java +++ b/src/test/java/dev/vality/orgmanager/service/ResourceAccessServiceImplTest.java @@ -63,12 +63,10 @@ class ResourceAccessServiceImplTest { @Test void checkOrgRights() { - String orgId = TestObjectFactory.randomString(); ResourceDto resource = ResourceDto.builder() - .orgId(orgId) + .orgId(TestObjectFactory.randomString()) .build(); when(bouncerService.havePrivileges(any(BouncerContextDto.class))).thenReturn(true); - when(organizationService.findById(orgId)).thenReturn(TestObjectFactory.buildOrganization()); assertDoesNotThrow(() -> resourceAccessService.checkRights(resource)); } @@ -79,7 +77,7 @@ class ResourceAccessServiceImplTest { .invitationToken(TestObjectFactory.randomString()) .build(); when(bouncerService.havePrivileges(any(BouncerContextDto.class))).thenReturn(true); - when(organizationService.getPartyByInvitationToken(resource.getInvitationToken())) + when(organizationService.getOrgIdByInvitationToken(resource.getInvitationToken())) .thenThrow(new ResourceNotFoundException()); assertThrows(ResourceNotFoundException.class, @@ -98,13 +96,11 @@ class ResourceAccessServiceImplTest { @Test void checkMemberRights() { - String orgId = TestObjectFactory.randomString(); ResourceDto resource = ResourceDto.builder() - .orgId(orgId) + .orgId(TestObjectFactory.randomString()) .memberId(TestObjectFactory.randomString()) .build(); when(bouncerService.havePrivileges(any(BouncerContextDto.class))).thenReturn(true); - when(organizationService.findById(orgId)).thenReturn(TestObjectFactory.buildOrganization()); assertDoesNotThrow(() -> resourceAccessService.checkRights(resource)); }