rename hs-admin to hs-office regarding the module name

This commit is contained in:
Michael Hoennig 2022-09-13 13:27:52 +02:00
parent 7465b9df63
commit 4e90f53bf3
43 changed files with 540 additions and 544 deletions

View File

@ -131,8 +131,8 @@ openapiProcessor {
springHs { springHs {
processorName 'spring' processorName 'spring'
processor 'io.openapiprocessor:openapi-processor-spring:2022.4' processor 'io.openapiprocessor:openapi-processor-spring:2022.4'
apiPath "$projectDir/src/main/resources/api-definition/hs-admin/hs-admin.yaml" apiPath "$projectDir/src/main/resources/api-definition/hs-office/hs-office.yaml"
mapping "$projectDir/src/main/resources/api-definition/hs-admin/api-mappings.yaml" mapping "$projectDir/src/main/resources/api-definition/hs-office/api-mappings.yaml"
targetDir "$projectDir/build/generated/sources/openapi" targetDir "$projectDir/build/generated/sources/openapi"
showWarnings true showWarnings true
openApiNullable true openApiNullable true
@ -200,7 +200,7 @@ jacocoTestReport {
classDirectories.setFrom(files(classDirectories.files.collect { classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: [ fileTree(dir: it, exclude: [
"net/hostsharing/hsadminng/**/generated/**/*.class", "net/hostsharing/hsadminng/**/generated/**/*.class",
"net/hostsharing/hsadminng/hs/hscustomer/HsadminNgApplication.class" "net/hostsharing/hsadminng/hs/HsadminNgApplication.class"
]) ])
})) }))
} }

View File

@ -1,10 +1,6 @@
package net.hostsharing.hsadminng; package net.hostsharing.hsadminng;
import net.hostsharing.hsadminng.hs.admin.generated.api.v1.model.HsAdminPersonResource;
import net.hostsharing.hsadminng.hs.admin.person.HsAdminPersonEntity;
import org.modelmapper.Converter;
import org.modelmapper.ModelMapper; import org.modelmapper.ModelMapper;
import org.modelmapper.spi.MappingContext;
import java.util.List; import java.util.List;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;

View File

@ -1,8 +0,0 @@
package net.hostsharing.hsadminng.hs.admin.person;
public enum HsAdminPersonType {
NATURAL,
LEGAL,
SOLE_REPRESENTATION,
JOINT_REPRESENTATION
}

View File

@ -1,4 +1,4 @@
package net.hostsharing.hsadminng.hs.admin.contact; package net.hostsharing.hsadminng.hs.office.contact;
import lombok.*; import lombok.*;
@ -9,13 +9,13 @@ import javax.persistence.Table;
import java.util.UUID; import java.util.UUID;
@Entity @Entity
@Table(name = "hs_admin_contact_rv") @Table(name = "hs_office_contact_rv")
@Getter @Getter
@Setter @Setter
@Builder @Builder
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class HsAdminContactEntity { public class HsOfficeContactEntity {
private @Id UUID uuid; private @Id UUID uuid;
private String label; private String label;

View File

@ -1,4 +1,4 @@
package net.hostsharing.hsadminng.hs.admin.contact; package net.hostsharing.hsadminng.hs.office.contact;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository; import org.springframework.data.repository.Repository;
@ -7,19 +7,19 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
public interface HsAdminContactRepository extends Repository<HsAdminContactEntity, UUID> { public interface HsOfficeContactRepository extends Repository<HsOfficeContactEntity, UUID> {
Optional<HsAdminContactEntity> findByUuid(UUID id); Optional<HsOfficeContactEntity> findByUuid(UUID id);
@Query(""" @Query("""
SELECT c FROM HsAdminContactEntity c SELECT c FROM HsOfficeContactEntity c
WHERE :label is null WHERE :label is null
OR c.label like concat(:label, '%') OR c.label like concat(:label, '%')
""") """)
// TODO.feat: join tables missing // TODO.feat: join tables missing
List<HsAdminContactEntity> findContactByOptionalLabelLike(String label); List<HsOfficeContactEntity> findContactByOptionalLabelLike(String label);
HsAdminContactEntity save(final HsAdminContactEntity entity); HsOfficeContactEntity save(final HsOfficeContactEntity entity);
void deleteByUuid(final UUID uuid); void deleteByUuid(final UUID uuid);

View File

@ -1,14 +1,14 @@
package net.hostsharing.hsadminng.hs.admin.partner; package net.hostsharing.hsadminng.hs.office.partner;
import net.hostsharing.hsadminng.Mapper; import net.hostsharing.hsadminng.Mapper;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.admin.contact.HsAdminContactEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.admin.generated.api.v1.api.HsAdminPartnersApi; import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficePartnersApi;
import net.hostsharing.hsadminng.hs.admin.generated.api.v1.model.HsAdminContactResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeContactResource;
import net.hostsharing.hsadminng.hs.admin.generated.api.v1.model.HsAdminPartnerResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerResource;
import net.hostsharing.hsadminng.hs.admin.generated.api.v1.model.HsAdminPartnerUpdateResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerUpdateResource;
import net.hostsharing.hsadminng.hs.admin.generated.api.v1.model.HsAdminPersonResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePersonResource;
import net.hostsharing.hsadminng.hs.admin.person.HsAdminPersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -23,17 +23,17 @@ import static net.hostsharing.hsadminng.Mapper.map;
@RestController @RestController
public class HsAdminPartnerController implements HsAdminPartnersApi { public class HsOfficePartnerController implements HsOfficePartnersApi {
@Autowired @Autowired
private Context context; private Context context;
@Autowired @Autowired
private HsAdminPartnerRepository partnerRepo; private HsOfficePartnerRepository partnerRepo;
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public ResponseEntity<List<HsAdminPartnerResource>> listPartners( public ResponseEntity<List<HsOfficePartnerResource>> listPartners(
final String currentUser, final String currentUser,
final String assumedRoles, final String assumedRoles,
final String name) { final String name) {
@ -42,46 +42,46 @@ public class HsAdminPartnerController implements HsAdminPartnersApi {
// TODO.feat: final var entities = partnerRepo.findPartnerByOptionalNameLike(name); // TODO.feat: final var entities = partnerRepo.findPartnerByOptionalNameLike(name);
final var entities = List.of( final var entities = List.of(
HsAdminPartnerEntity.builder() HsOfficePartnerEntity.builder()
.uuid(UUID.randomUUID()) .uuid(UUID.randomUUID())
.person(HsAdminPersonEntity.builder() .person(HsOfficePersonEntity.builder()
.tradeName("Ixx AG") .tradeName("Ixx AG")
.build()) .build())
.contact(HsAdminContactEntity.builder() .contact(HsOfficeContactEntity.builder()
.label("Ixx AG") .label("Ixx AG")
.build()) .build())
.build(), .build(),
HsAdminPartnerEntity.builder() HsOfficePartnerEntity.builder()
.uuid(UUID.randomUUID()) .uuid(UUID.randomUUID())
.person(HsAdminPersonEntity.builder() .person(HsOfficePersonEntity.builder()
.tradeName("Ypsilon GmbH") .tradeName("Ypsilon GmbH")
.build()) .build())
.contact(HsAdminContactEntity.builder() .contact(HsOfficeContactEntity.builder()
.label("Ypsilon GmbH") .label("Ypsilon GmbH")
.build()) .build())
.build(), .build(),
HsAdminPartnerEntity.builder() HsOfficePartnerEntity.builder()
.uuid(UUID.randomUUID()) .uuid(UUID.randomUUID())
.person(HsAdminPersonEntity.builder() .person(HsOfficePersonEntity.builder()
.tradeName("Zett OHG") .tradeName("Zett OHG")
.build()) .build())
.contact(HsAdminContactEntity.builder() .contact(HsOfficeContactEntity.builder()
.label("Zett OHG") .label("Zett OHG")
.build()) .build())
.build() .build()
); );
final var resources = Mapper.mapList(entities, HsAdminPartnerResource.class, final var resources = Mapper.mapList(entities, HsOfficePartnerResource.class,
PARTNER_ENTITY_TO_RESOURCE_POSTMAPPER); PARTNER_ENTITY_TO_RESOURCE_POSTMAPPER);
return ResponseEntity.ok(resources); return ResponseEntity.ok(resources);
} }
@Override @Override
@Transactional @Transactional
public ResponseEntity<HsAdminPartnerResource> addPartner( public ResponseEntity<HsOfficePartnerResource> addPartner(
final String currentUser, final String currentUser,
final String assumedRoles, final String assumedRoles,
final HsAdminPartnerResource body) { final HsOfficePartnerResource body) {
// TODO.feat: context.define(currentUser, assumedRoles); // TODO.feat: context.define(currentUser, assumedRoles);
@ -89,21 +89,21 @@ public class HsAdminPartnerController implements HsAdminPartnersApi {
body.setUuid(UUID.randomUUID()); body.setUuid(UUID.randomUUID());
} }
// TODO.feat: final var saved = partnerRepo.save(map(body, HsAdminPartnerEntity.class)); // TODO.feat: final var saved = partnerRepo.save(map(body, HsOfficePartnerEntity.class));
final var saved = map(body, HsAdminPartnerEntity.class, PARTNER_RESOURCE_TO_ENTITY_POSTMAPPER); final var saved = map(body, HsOfficePartnerEntity.class, PARTNER_RESOURCE_TO_ENTITY_POSTMAPPER);
final var uri = final var uri =
MvcUriComponentsBuilder.fromController(getClass()) MvcUriComponentsBuilder.fromController(getClass())
.path("/api/hs/admin/partners/{id}") .path("/api/hs/office/partners/{id}")
.buildAndExpand(body.getUuid()) .buildAndExpand(body.getUuid())
.toUri(); .toUri();
final var mapped = map(saved, HsAdminPartnerResource.class, final var mapped = map(saved, HsOfficePartnerResource.class,
PARTNER_ENTITY_TO_RESOURCE_POSTMAPPER); PARTNER_ENTITY_TO_RESOURCE_POSTMAPPER);
return ResponseEntity.created(uri).body(mapped); return ResponseEntity.created(uri).body(mapped);
} }
@Override @Override
public ResponseEntity<HsAdminPartnerResource> getPartnerByUuid( public ResponseEntity<HsOfficePartnerResource> getPartnerByUuid(
final String currentUser, final String currentUser,
final String assumedRoles, final String assumedRoles,
final UUID partnerUuid) { final UUID partnerUuid) {
@ -113,19 +113,19 @@ public class HsAdminPartnerController implements HsAdminPartnersApi {
// TODO.feat: final var result = partnerRepo.findByUuid(partnerUuid); // TODO.feat: final var result = partnerRepo.findByUuid(partnerUuid);
final var result = final var result =
partnerUuid.equals(UUID.fromString("3fa85f64-5717-4562-b3fc-2c963f66afa6")) ? null : partnerUuid.equals(UUID.fromString("3fa85f64-5717-4562-b3fc-2c963f66afa6")) ? null :
HsAdminPartnerEntity.builder() HsOfficePartnerEntity.builder()
.uuid(UUID.randomUUID()) .uuid(UUID.randomUUID())
.person(HsAdminPersonEntity.builder() .person(HsOfficePersonEntity.builder()
.tradeName("Ixx AG") .tradeName("Ixx AG")
.build()) .build())
.contact(HsAdminContactEntity.builder() .contact(HsOfficeContactEntity.builder()
.label("Ixx AG") .label("Ixx AG")
.build()) .build())
.build(); .build();
if (result == null) { if (result == null) {
return ResponseEntity.notFound().build(); return ResponseEntity.notFound().build();
} }
return ResponseEntity.ok(map(result, HsAdminPartnerResource.class, PARTNER_ENTITY_TO_RESOURCE_POSTMAPPER)); return ResponseEntity.ok(map(result, HsOfficePartnerResource.class, PARTNER_ENTITY_TO_RESOURCE_POSTMAPPER));
} }
@Override @Override
@ -134,22 +134,22 @@ public class HsAdminPartnerController implements HsAdminPartnersApi {
} }
@Override @Override
public ResponseEntity<HsAdminPartnerResource> updatePartner( public ResponseEntity<HsOfficePartnerResource> updatePartner(
final String currentUser, final String currentUser,
final String assumedRoles, final String assumedRoles,
final UUID partnerUuid, final UUID partnerUuid,
final HsAdminPartnerUpdateResource body) { final HsOfficePartnerUpdateResource body) {
return null; return null;
} }
private final BiConsumer<HsAdminPartnerResource, HsAdminPartnerEntity> PARTNER_RESOURCE_TO_ENTITY_POSTMAPPER = (resource, entity) -> { private final BiConsumer<HsOfficePartnerResource, HsOfficePartnerEntity> PARTNER_RESOURCE_TO_ENTITY_POSTMAPPER = (resource, entity) -> {
entity.setPerson(map(resource.getPerson(), HsAdminPersonEntity.class)); entity.setPerson(map(resource.getPerson(), HsOfficePersonEntity.class));
entity.setContact(map(resource.getContact(), HsAdminContactEntity.class)); entity.setContact(map(resource.getContact(), HsOfficeContactEntity.class));
}; };
private final BiConsumer<HsAdminPartnerEntity, HsAdminPartnerResource> PARTNER_ENTITY_TO_RESOURCE_POSTMAPPER = (entity, resource) -> { private final BiConsumer<HsOfficePartnerEntity, HsOfficePartnerResource> PARTNER_ENTITY_TO_RESOURCE_POSTMAPPER = (entity, resource) -> {
resource.setPerson(map(entity.getPerson(), HsAdminPersonResource.class)); resource.setPerson(map(entity.getPerson(), HsOfficePersonResource.class));
resource.setContact(map(entity.getContact(), HsAdminContactResource.class)); resource.setContact(map(entity.getContact(), HsOfficeContactResource.class));
}; };
} }

View File

@ -1,31 +1,31 @@
package net.hostsharing.hsadminng.hs.admin.partner; package net.hostsharing.hsadminng.hs.office.partner;
import lombok.*; import lombok.*;
import net.hostsharing.hsadminng.hs.admin.contact.HsAdminContactEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.admin.person.HsAdminPersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import javax.persistence.*; import javax.persistence.*;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.UUID; import java.util.UUID;
@Entity @Entity
@Table(name = "hs_admin_partner_rv") @Table(name = "hs_office_partner_rv")
@Getter @Getter
@Setter @Setter
@Builder @Builder
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class HsAdminPartnerEntity { public class HsOfficePartnerEntity {
private @Id UUID uuid; private @Id UUID uuid;
@ManyToOne @ManyToOne
@JoinColumn(name = "personuuid") @JoinColumn(name = "personuuid")
private HsAdminPersonEntity person; private HsOfficePersonEntity person;
@ManyToOne @ManyToOne
@JoinColumn(name = "contactuuid") @JoinColumn(name = "contactuuid")
private HsAdminContactEntity contact; private HsOfficeContactEntity contact;
private @Column(name = "registrationoffice") String registrationOffice; private @Column(name = "registrationoffice") String registrationOffice;
private @Column(name = "registrationnumber") String registrationNumber; private @Column(name = "registrationnumber") String registrationNumber;

View File

@ -1,4 +1,4 @@
package net.hostsharing.hsadminng.hs.admin.partner; package net.hostsharing.hsadminng.hs.office.partner;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository; import org.springframework.data.repository.Repository;
@ -7,14 +7,14 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
public interface HsAdminPartnerRepository extends Repository<HsAdminPartnerEntity, UUID> { public interface HsOfficePartnerRepository extends Repository<HsOfficePartnerEntity, UUID> {
Optional<HsAdminPartnerEntity> findByUuid(UUID id); Optional<HsOfficePartnerEntity> findByUuid(UUID id);
@Query(""" @Query("""
SELECT partner FROM HsAdminPartnerEntity partner SELECT partner FROM HsOfficePartnerEntity partner
JOIN HsAdminContactEntity contact ON contact.uuid = partner.contact JOIN HsOfficeContactEntity contact ON contact.uuid = partner.contact
JOIN HsAdminPersonEntity person ON person.uuid = partner.person JOIN HsOfficePersonEntity person ON person.uuid = partner.person
WHERE :name is null WHERE :name is null
OR partner.birthName like concat(:name, '%') OR partner.birthName like concat(:name, '%')
OR contact.label like concat(:name, '%') OR contact.label like concat(:name, '%')
@ -22,9 +22,9 @@ public interface HsAdminPartnerRepository extends Repository<HsAdminPartnerEntit
OR person.givenName like concat(:name, '%') OR person.givenName like concat(:name, '%')
OR person.familyName like concat(:name, '%') OR person.familyName like concat(:name, '%')
""") """)
List<HsAdminPartnerEntity> findPartnerByOptionalNameLike(String name); List<HsOfficePartnerEntity> findPartnerByOptionalNameLike(String name);
HsAdminPartnerEntity save(final HsAdminPartnerEntity entity); HsOfficePartnerEntity save(final HsOfficePartnerEntity entity);
long count(); long count();

View File

@ -1,4 +1,4 @@
package net.hostsharing.hsadminng.hs.admin.person; package net.hostsharing.hsadminng.hs.office.person;
import com.vladmihalcea.hibernate.type.basic.PostgreSQLEnumType; import com.vladmihalcea.hibernate.type.basic.PostgreSQLEnumType;
import lombok.*; import lombok.*;
@ -10,7 +10,7 @@ import javax.persistence.*;
import java.util.UUID; import java.util.UUID;
@Entity @Entity
@Table(name = "hs_admin_person_rv") @Table(name = "hs_office_person_rv")
@TypeDef( @TypeDef(
name = "pgsql_enum", name = "pgsql_enum",
typeClass = PostgreSQLEnumType.class typeClass = PostgreSQLEnumType.class
@ -20,14 +20,14 @@ import java.util.UUID;
@Builder @Builder
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class HsAdminPersonEntity { public class HsOfficePersonEntity {
private @Id UUID uuid; private @Id UUID uuid;
@Column(name = "persontype") @Column(name = "persontype")
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
@Type( type = "pgsql_enum" ) @Type( type = "pgsql_enum" )
private HsAdminPersonType personType; private HsOfficePersonType personType;
@Column(name = "tradename") @Column(name = "tradename")
private String tradeName; private String tradeName;

View File

@ -1,4 +1,4 @@
package net.hostsharing.hsadminng.hs.admin.person; package net.hostsharing.hsadminng.hs.office.person;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository; import org.springframework.data.repository.Repository;
@ -7,20 +7,20 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
public interface HsAdminPersonRepository extends Repository<HsAdminPersonEntity, UUID> { public interface HsOfficePersonRepository extends Repository<HsOfficePersonEntity, UUID> {
Optional<HsAdminPersonEntity> findByUuid(UUID personUuid); Optional<HsOfficePersonEntity> findByUuid(UUID personUuid);
@Query(""" @Query("""
SELECT p FROM HsAdminPersonEntity p SELECT p FROM HsOfficePersonEntity p
WHERE :name is null WHERE :name is null
OR p.tradeName like concat(:name, '%') OR p.tradeName like concat(:name, '%')
OR p.givenName like concat(:name, '%') OR p.givenName like concat(:name, '%')
OR p.familyName like concat(:name, '%') OR p.familyName like concat(:name, '%')
""") """)
List<HsAdminPersonEntity> findPersonByOptionalNameLike(String name); List<HsOfficePersonEntity> findPersonByOptionalNameLike(String name);
HsAdminPersonEntity save(final HsAdminPersonEntity entity); HsOfficePersonEntity save(final HsOfficePersonEntity entity);
int deleteByUuid(final UUID personUuid); int deleteByUuid(final UUID personUuid);

View File

@ -0,0 +1,8 @@
package net.hostsharing.hsadminng.hs.office.person;
public enum HsOfficePersonType {
NATURAL,
LEGAL,
SOLE_REPRESENTATION,
JOINT_REPRESENTATION
}

View File

@ -1,7 +1,7 @@
openapi-processor-mapping: v2 openapi-processor-mapping: v2
options: options:
package-name: net.hostsharing.hsadminng.hs.admin.generated.api.v1 package-name: net.hostsharing.hsadminng.hs.office.generated.api.v1
model-name-suffix: Resource model-name-suffix: Resource
map: map:
@ -12,5 +12,5 @@ map:
- type: string:uuid => java.util.UUID - type: string:uuid => java.util.UUID
paths: paths:
/api/hs/admin/partners/{packageUUID}: /api/hs/office/partners/{packageUUID}:
null: org.openapitools.jackson.nullable.JsonNullable null: org.openapitools.jackson.nullable.JsonNullable

View File

@ -3,7 +3,7 @@ components:
schemas: schemas:
HsAdminContactBase: HsOfficeContactBase:
type: object type: object
properties: properties:
label: label:
@ -15,14 +15,14 @@ components:
phoneNumbers: phoneNumbers:
type: string type: string
HsAdminContact: HsOfficeContact:
allOf: allOf:
- type: object - type: object
properties: properties:
uuid: uuid:
type: string type: string
format: uuid format: uuid
- $ref: '#/components/schemas/HsAdminContactBase' - $ref: '#/components/schemas/HsOfficeContactBase'
HsAdminContactUpdate: HsOfficeContactUpdate:
$ref: '#/components/schemas/HsAdminContactBase' $ref: '#/components/schemas/HsOfficeContactBase'

View File

@ -3,7 +3,7 @@ components:
schemas: schemas:
HsAdminPartnerBase: HsOfficePartnerBase:
type: object type: object
properties: properties:
registrationOffice: registrationOffice:
@ -19,7 +19,7 @@ components:
type: string type: string
format: date format: date
HsAdminPartner: HsOfficePartner:
allOf: allOf:
- type: object - type: object
properties: properties:
@ -27,12 +27,12 @@ components:
type: string type: string
format: uuid format: uuid
person: person:
$ref: './hs-admin-person-schemas.yaml#/components/schemas/HsAdminPerson' $ref: './hs-office-person-schemas.yaml#/components/schemas/HsOfficePerson'
contact: contact:
$ref: './hs-admin-contact-schemas.yaml#/components/schemas/HsAdminContact' $ref: './hs-office-contact-schemas.yaml#/components/schemas/HsOfficeContact'
- $ref: '#/components/schemas/HsAdminPartnerBase' - $ref: '#/components/schemas/HsOfficePartnerBase'
HsAdminPartnerUpdate: HsOfficePartnerUpdate:
allOf: allOf:
- type: object - type: object
properties: properties:
@ -42,4 +42,4 @@ components:
contactUuid: contactUuid:
type: string type: string
format: uuid format: uuid
- $ref: '#/components/schemas/HsAdminPartnerBase' - $ref: '#/components/schemas/HsOfficePartnerBase'

View File

@ -1,6 +1,6 @@
get: get:
tags: tags:
- hs-admin-partners - hs-office-partners
description: 'Fetch a single business partner by its uuid, if visible for the current subject.' description: 'Fetch a single business partner by its uuid, if visible for the current subject.'
operationId: getPartnerByUuid operationId: getPartnerByUuid
parameters: parameters:
@ -18,7 +18,7 @@ get:
content: content:
'application/json': 'application/json':
schema: schema:
$ref: './hs-admin-partner-schemas.yaml#/components/schemas/HsAdminPartner' $ref: './hs-office-partner-schemas.yaml#/components/schemas/HsOfficePartner'
"401": "401":
$ref: './error-responses.yaml#/components/responses/Unauthorized' $ref: './error-responses.yaml#/components/responses/Unauthorized'
@ -27,7 +27,7 @@ get:
patch: patch:
tags: tags:
- hs-admin-partners - hs-office-partners
operationId: updatePartner operationId: updatePartner
parameters: parameters:
- $ref: './auth.yaml#/components/parameters/currentUser' - $ref: './auth.yaml#/components/parameters/currentUser'
@ -42,14 +42,14 @@ patch:
content: content:
'application/json': 'application/json':
schema: schema:
$ref: './hs-admin-partner-schemas.yaml#/components/schemas/HsAdminPartnerUpdate' $ref: './hs-office-partner-schemas.yaml#/components/schemas/HsOfficePartnerUpdate'
responses: responses:
"200": "200":
description: OK description: OK
content: content:
'application/json': 'application/json':
schema: schema:
$ref: './hs-admin-partner-schemas.yaml#/components/schemas/HsAdminPartner' $ref: './hs-office-partner-schemas.yaml#/components/schemas/HsOfficePartner'
"401": "401":
$ref: './error-responses.yaml#/components/responses/Unauthorized' $ref: './error-responses.yaml#/components/responses/Unauthorized'
"403": "403":
@ -58,7 +58,7 @@ patch:
delete: delete:
tags: tags:
- hs-admin-partners - hs-office-partners
operationId: deletePartnerByUuid operationId: deletePartnerByUuid
parameters: parameters:
- $ref: './auth.yaml#/components/parameters/currentUser' - $ref: './auth.yaml#/components/parameters/currentUser'

View File

@ -2,7 +2,7 @@ get:
summary: Returns a list of (optionally filtered) business partners. summary: Returns a list of (optionally filtered) business partners.
description: Returns the list of (optionally filtered) business partners which are visible to the current user or any of it's assumed roles. description: Returns the list of (optionally filtered) business partners which are visible to the current user or any of it's assumed roles.
tags: tags:
- hs-admin-partners - hs-office-partners
operationId: listPartners operationId: listPartners
parameters: parameters:
- $ref: './auth.yaml#/components/parameters/currentUser' - $ref: './auth.yaml#/components/parameters/currentUser'
@ -21,7 +21,7 @@ get:
schema: schema:
type: array type: array
items: items:
$ref: './hs-admin-partner-schemas.yaml#/components/schemas/HsAdminPartner' $ref: './hs-office-partner-schemas.yaml#/components/schemas/HsOfficePartner'
"401": "401":
$ref: './error-responses.yaml#/components/responses/Unauthorized' $ref: './error-responses.yaml#/components/responses/Unauthorized'
"403": "403":
@ -30,7 +30,7 @@ get:
post: post:
summary: Adds a new business partner. summary: Adds a new business partner.
tags: tags:
- hs-admin-partners - hs-office-partners
operationId: addPartner operationId: addPartner
parameters: parameters:
- $ref: './auth.yaml#/components/parameters/currentUser' - $ref: './auth.yaml#/components/parameters/currentUser'
@ -39,7 +39,7 @@ post:
content: content:
'application/json': 'application/json':
schema: schema:
$ref: './hs-admin-partner-schemas.yaml#/components/schemas/HsAdminPartner' $ref: './hs-office-partner-schemas.yaml#/components/schemas/HsOfficePartner'
required: true required: true
responses: responses:
"201": "201":
@ -47,7 +47,7 @@ post:
content: content:
'application/json': 'application/json':
schema: schema:
$ref: './hs-admin-partner-schemas.yaml#/components/schemas/HsAdminPartner' $ref: './hs-office-partner-schemas.yaml#/components/schemas/HsOfficePartner'
"401": "401":
$ref: './error-responses.yaml#/components/responses/Unauthorized' $ref: './error-responses.yaml#/components/responses/Unauthorized'
"403": "403":

View File

@ -3,7 +3,7 @@ components:
schemas: schemas:
HsAdminPersonBase: HsOfficePersonBase:
type: object type: object
properties: properties:
personType: personType:
@ -20,14 +20,14 @@ components:
familyName: familyName:
type: string type: string
HsAdminPerson: HsOfficePerson:
allOf: allOf:
- type: object - type: object
properties: properties:
uuid: uuid:
type: string type: string
format: uuid format: uuid
- $ref: '#/components/schemas/HsAdminPersonBase' - $ref: '#/components/schemas/HsOfficePersonBase'
HsAdminPersonUpdate: HsOfficePersonUpdate:
$ref: '#/components/schemas/HsAdminPersonBase' $ref: '#/components/schemas/HsOfficePersonBase'

View File

@ -8,9 +8,9 @@ servers:
paths: paths:
/api/hs/admin/partners: /api/hs/office/partners:
$ref: "./hs-admin-partners.yaml" $ref: "./hs-office-partners.yaml"
/api/hs/admin/partners/{partnerUUID}: /api/hs/office/partners/{partnerUUID}:
$ref: "./hs-admin-partners-with-uuid.yaml" $ref: "./hs-office-partners-with-uuid.yaml"

View File

@ -1,10 +1,10 @@
--liquibase formatted sql --liquibase formatted sql
-- ============================================================================ -- ============================================================================
--changeset hs-admin-contact-MAIN-TABLE:1 endDelimiter:--// --changeset hs-office-contact-MAIN-TABLE:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
create table if not exists hs_admin_contact create table if not exists hs_office_contact
( (
uuid uuid unique references RbacObject (uuid) initially deferred, uuid uuid unique references RbacObject (uuid) initially deferred,
label varchar(96) not null, label varchar(96) not null,

View File

@ -1,51 +1,51 @@
--liquibase formatted sql --liquibase formatted sql
-- ============================================================================ -- ============================================================================
--changeset hs-admin-contact-rbac-OBJECT:1 endDelimiter:--// --changeset hs-office-contact-rbac-OBJECT:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
call generateRelatedRbacObject('hs_admin_contact'); call generateRelatedRbacObject('hs_office_contact');
--// --//
-- ============================================================================ -- ============================================================================
--changeset hs-admin-contact-rbac-ROLE-DESCRIPTORS:1 endDelimiter:--// --changeset hs-office-contact-rbac-ROLE-DESCRIPTORS:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
create or replace function hsAdminContactOwner(contact hs_admin_contact) create or replace function hsOfficeContactOwner(contact hs_office_contact)
returns RbacRoleDescriptor returns RbacRoleDescriptor
language plpgsql language plpgsql
strict as $$ strict as $$
begin begin
return roleDescriptor('hs_admin_contact', contact.uuid, 'owner'); return roleDescriptor('hs_office_contact', contact.uuid, 'owner');
end; $$; end; $$;
create or replace function hsAdminContactAdmin(contact hs_admin_contact) create or replace function hsOfficeContactAdmin(contact hs_office_contact)
returns RbacRoleDescriptor returns RbacRoleDescriptor
language plpgsql language plpgsql
strict as $$ strict as $$
begin begin
return roleDescriptor('hs_admin_contact', contact.uuid, 'admin'); return roleDescriptor('hs_office_contact', contact.uuid, 'admin');
end; $$; end; $$;
create or replace function hsAdminContactTenant(contact hs_admin_contact) create or replace function hsOfficeContactTenant(contact hs_office_contact)
returns RbacRoleDescriptor returns RbacRoleDescriptor
language plpgsql language plpgsql
strict as $$ strict as $$
begin begin
return roleDescriptor('hs_admin_contact', contact.uuid, 'tenant'); return roleDescriptor('hs_office_contact', contact.uuid, 'tenant');
end; $$; end; $$;
--// --//
-- ============================================================================ -- ============================================================================
--changeset hs-admin-contact-rbac-ROLES-CREATION:1 endDelimiter:--// --changeset hs-office-contact-rbac-ROLES-CREATION:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
/* /*
Creates the roles and their assignments for a new contact for the AFTER INSERT TRIGGER. Creates the roles and their assignments for a new contact for the AFTER INSERT TRIGGER.
*/ */
create or replace function createRbacRolesForHsAdminContact() create or replace function createRbacRolesForhsOfficeContact()
returns trigger returns trigger
language plpgsql language plpgsql
strict as $$ strict as $$
@ -59,7 +59,7 @@ begin
-- the owner role with full access for the creator assigned to the current user -- the owner role with full access for the creator assigned to the current user
ownerRole := createRole( ownerRole := createRole(
hsAdminContactOwner(NEW), hsOfficeContactOwner(NEW),
grantingPermissions(forObjectUuid => NEW.uuid, permitOps => array ['*']), grantingPermissions(forObjectUuid => NEW.uuid, permitOps => array ['*']),
beneathRole(globalAdmin()), beneathRole(globalAdmin()),
withoutSubRoles(), withoutSubRoles(),
@ -69,14 +69,14 @@ begin
-- the tenant role for those related users who can view the data -- the tenant role for those related users who can view the data
adminRole := createRole( adminRole := createRole(
hsAdminContactAdmin(NEW), hsOfficeContactAdmin(NEW),
grantingPermissions(forObjectUuid => NEW.uuid, permitOps => array ['edit']), grantingPermissions(forObjectUuid => NEW.uuid, permitOps => array ['edit']),
beneathRole(ownerRole) beneathRole(ownerRole)
); );
-- the tenant role for those related users who can view the data -- the tenant role for those related users who can view the data
perform createRole( perform createRole(
hsAdminContactTenant(NEW), hsOfficeContactTenant(NEW),
grantingPermissions(forObjectUuid => NEW.uuid, permitOps => array ['view']), grantingPermissions(forObjectUuid => NEW.uuid, permitOps => array ['view']),
beneathRole(adminRole) beneathRole(adminRole)
); );
@ -88,82 +88,82 @@ end; $$;
An AFTER INSERT TRIGGER which creates the role structure for a new customer. An AFTER INSERT TRIGGER which creates the role structure for a new customer.
*/ */
create trigger createRbacRolesForHsAdminContact_Trigger create trigger createRbacRolesForhsOfficeContact_Trigger
after insert after insert
on hs_admin_contact on hs_office_contact
for each row for each row
execute procedure createRbacRolesForHsAdminContact(); execute procedure createRbacRolesForhsOfficeContact();
--// --//
-- ============================================================================ -- ============================================================================
--changeset hs-admin-contact-rbac-IDENTITY-VIEW:1 endDelimiter:--// --changeset hs-office-contact-rbac-IDENTITY-VIEW:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
/* /*
Creates a view to the contact main table which maps the identifying name Creates a view to the contact main table which maps the identifying name
(in this case, the prefix) to the objectUuid. (in this case, the prefix) to the objectUuid.
*/ */
create or replace view hs_admin_contact_iv as create or replace view hs_office_contact_iv as
select target.uuid, cleanIdentifier(target.label) as idName select target.uuid, cleanIdentifier(target.label) as idName
from hs_admin_contact as target; from hs_office_contact as target;
-- TODO.spec: Is it ok that everybody has access to this information? -- TODO.spec: Is it ok that everybody has access to this information?
grant all privileges on hs_admin_contact_iv to restricted; grant all privileges on hs_office_contact_iv to restricted;
/* /*
Returns the objectUuid for a given identifying name (in this case the prefix). Returns the objectUuid for a given identifying name (in this case the prefix).
*/ */
create or replace function hs_admin_contactUuidByIdName(idName varchar) create or replace function hs_office_contactUuidByIdName(idName varchar)
returns uuid returns uuid
language sql language sql
strict as $$ strict as $$
select uuid from hs_admin_contact_iv iv where iv.idName = hs_admin_contactUuidByIdName.idName; select uuid from hs_office_contact_iv iv where iv.idName = hs_office_contactUuidByIdName.idName;
$$; $$;
/* /*
Returns the identifying name for a given objectUuid (in this case the label). Returns the identifying name for a given objectUuid (in this case the label).
*/ */
create or replace function hs_admin_contactIdNameByUuid(uuid uuid) create or replace function hs_office_contactIdNameByUuid(uuid uuid)
returns varchar returns varchar
language sql language sql
strict as $$ strict as $$
select idName from hs_admin_contact_iv iv where iv.uuid = hs_admin_contactIdNameByUuid.uuid; select idName from hs_office_contact_iv iv where iv.uuid = hs_office_contactIdNameByUuid.uuid;
$$; $$;
--// --//
-- ============================================================================ -- ============================================================================
--changeset hs-admin-contact-rbac-RESTRICTED-VIEW:1 endDelimiter:--// --changeset hs-office-contact-rbac-RESTRICTED-VIEW:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
/* /*
Creates a view to the contact main table with row-level limitation Creates a view to the contact main table with row-level limitation
based on the 'view' permission of the current user or assumed roles. based on the 'view' permission of the current user or assumed roles.
*/ */
set session session authorization default; set session session authorization default;
drop view if exists hs_admin_contact_rv; drop view if exists hs_office_contact_rv;
create or replace view hs_admin_contact_rv as create or replace view hs_office_contact_rv as
select target.* select target.*
from hs_admin_contact as target from hs_office_contact as target
where target.uuid in (select queryAccessibleObjectUuidsOfSubjectIds('view', 'hs_admin_contact', currentSubjectsUuids())); where target.uuid in (select queryAccessibleObjectUuidsOfSubjectIds('view', 'hs_office_contact', currentSubjectsUuids()));
grant all privileges on hs_admin_contact_rv to restricted; grant all privileges on hs_office_contact_rv to restricted;
--// --//
-- ============================================================================ -- ============================================================================
--changeset hs-admin-contact-rbac-INSTEAD-OF-INSERT-TRIGGER:1 endDelimiter:--// --changeset hs-office-contact-rbac-INSTEAD-OF-INSERT-TRIGGER:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
/** /**
Instead of insert trigger function for hs_admin_contact_rv. Instead of insert trigger function for hs_office_contact_rv.
*/ */
create or replace function insertHsAdminContact() create or replace function inserthsOfficeContact()
returns trigger returns trigger
language plpgsql as $$ language plpgsql as $$
declare declare
newUser hs_admin_contact; newUser hs_office_contact;
begin begin
insert insert
into hs_admin_contact into hs_office_contact
values (new.*) values (new.*)
returning * into newUser; returning * into newUser;
return newUser; return newUser;
@ -171,48 +171,48 @@ end;
$$; $$;
/* /*
Creates an instead of insert trigger for the hs_admin_contact_rv view. Creates an instead of insert trigger for the hs_office_contact_rv view.
*/ */
create trigger insertHsAdminContact_Trigger create trigger inserthsOfficeContact_Trigger
instead of insert instead of insert
on hs_admin_contact_rv on hs_office_contact_rv
for each row for each row
execute function insertHsAdminContact(); execute function inserthsOfficeContact();
--// --//
-- ============================================================================ -- ============================================================================
--changeset hs-admin-contact-rbac-INSTEAD-OF-DELETE-TRIGGER:1 endDelimiter:--// --changeset hs-office-contact-rbac-INSTEAD-OF-DELETE-TRIGGER:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
/** /**
Instead of delete trigger function for hs_admin_contact_rv. Instead of delete trigger function for hs_office_contact_rv.
Checks if the current subject (user / assumed role) has the permission to delete the row. Checks if the current subject (user / assumed role) has the permission to delete the row.
*/ */
create or replace function deleteHsAdminContact() create or replace function deletehsOfficeContact()
returns trigger returns trigger
language plpgsql as $$ language plpgsql as $$
begin begin
if hasGlobalRoleGranted(currentUserUuid()) or if hasGlobalRoleGranted(currentUserUuid()) or
old.uuid in (select queryAccessibleObjectUuidsOfSubjectIds('delete', 'hs_admin_contact', currentSubjectsUuids())) then old.uuid in (select queryAccessibleObjectUuidsOfSubjectIds('delete', 'hs_office_contact', currentSubjectsUuids())) then
delete from hs_admin_contact c where c.uuid = old.uuid; delete from hs_office_contact c where c.uuid = old.uuid;
return old; return old;
end if; end if;
raise exception '[403] User % not allowed to delete contact uuid %', currentUser(), old.uuid; raise exception '[403] User % not allowed to delete contact uuid %', currentUser(), old.uuid;
end; $$; end; $$;
/* /*
Creates an instead of delete trigger for the hs_admin_contact_rv view. Creates an instead of delete trigger for the hs_office_contact_rv view.
*/ */
create trigger deleteHsAdminContact_Trigger create trigger deletehsOfficeContact_Trigger
instead of delete instead of delete
on hs_admin_contact_rv on hs_office_contact_rv
for each row for each row
execute function deleteHsAdminContact(); execute function deletehsOfficeContact();
--/ --/
-- ============================================================================ -- ============================================================================
--changeset hs-admin-contact-rbac-NEW-CONTACT:1 endDelimiter:--// --changeset hs-office-contact-rbac-NEW-CONTACT:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
/* /*
Creates a global permission for new-contact and assigns it to the hostsharing admins role. Creates a global permission for new-contact and assigns it to the hostsharing admins role.
@ -235,7 +235,7 @@ $$;
/** /**
Used by the trigger to prevent the add-customer to current user respectively assumed roles. Used by the trigger to prevent the add-customer to current user respectively assumed roles.
*/ */
create or replace function addHsAdminContactNotAllowedForCurrentSubjects() create or replace function addHsOfficeContactNotAllowedForCurrentSubjects()
returns trigger returns trigger
language PLPGSQL language PLPGSQL
as $$ as $$
@ -247,12 +247,12 @@ end; $$;
/** /**
Checks if the user or assumed roles are allowed to create a new customer. Checks if the user or assumed roles are allowed to create a new customer.
*/ */
create trigger hs_admin_contact_insert_trigger create trigger hs_office_contact_insert_trigger
before insert before insert
on hs_admin_contact on hs_office_contact
for each row for each row
-- TODO.spec: who is allowed to create new contacts -- TODO.spec: who is allowed to create new contacts
when ( not hasAssumedRole() ) when ( not hasAssumedRole() )
execute procedure addHsAdminContactNotAllowedForCurrentSubjects(); execute procedure addHsOfficeContactNotAllowedForCurrentSubjects();
--// --//

View File

@ -2,13 +2,13 @@
-- ============================================================================ -- ============================================================================
--changeset hs-admin-contact-TEST-DATA-GENERATOR:1 endDelimiter:--// --changeset hs-office-contact-TEST-DATA-GENERATOR:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
/* /*
Creates a single contact test record. Creates a single contact test record.
*/ */
create or replace procedure createHsAdminContactTestData(contLabel varchar) create or replace procedure createHsOfficeContactTestData(contLabel varchar)
language plpgsql as $$ language plpgsql as $$
declare declare
currentTask varchar; currentTask varchar;
@ -24,7 +24,7 @@ begin
raise notice 'creating test contact: %', contLabel; raise notice 'creating test contact: %', contLabel;
insert insert
into hs_admin_contact (label, postaladdress, emailaddresses, phonenumbers) into hs_office_contact (label, postaladdress, emailaddresses, phonenumbers)
values (contLabel, $address$ values (contLabel, $address$
Vorname Nachname Vorname Nachname
Straße Hnr Straße Hnr
@ -36,7 +36,7 @@ end; $$;
/* /*
Creates a range of test contact for mass data generation. Creates a range of test contact for mass data generation.
*/ */
create or replace procedure createTestContactTestData( create or replace procedure createHsOfficeContactTestData(
startCount integer, -- count of auto generated rows before the run startCount integer, -- count of auto generated rows before the run
endCount integer -- count of auto generated rows after the run endCount integer -- count of auto generated rows after the run
) )
@ -44,7 +44,7 @@ create or replace procedure createTestContactTestData(
begin begin
for t in startCount..endCount for t in startCount..endCount
loop loop
call createHsAdminContactTestData(intToVarChar(t, 4) || '#' || t); call createHsOfficeContactTestData(intToVarChar(t, 4) || '#' || t);
commit; commit;
end loop; end loop;
end; $$; end; $$;
@ -52,15 +52,15 @@ end; $$;
-- ============================================================================ -- ============================================================================
--changeset hs-admin-contact-TEST-DATA-GENERATION:1 context=dev,tc endDelimiter:--// --changeset hs-office-contact-TEST-DATA-GENERATION:1 context=dev,tc endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
do language plpgsql $$ do language plpgsql $$
begin begin
call createHsAdminContactTestData('first contact'); call createHsOfficeContactTestData('first contact');
call createHsAdminContactTestData('second contact'); call createHsOfficeContactTestData('second contact');
call createHsAdminContactTestData('third contact'); call createHsOfficeContactTestData('third contact');
call createHsAdminContactTestData('forth contact'); call createHsOfficeContactTestData('forth contact');
end; end;
$$; $$;
--// --//

View File

@ -1,17 +1,17 @@
--liquibase formatted sql --liquibase formatted sql
-- ============================================================================ -- ============================================================================
--changeset hs-admin-person-MAIN-TABLE:1 endDelimiter:--// --changeset hs-office-person-MAIN-TABLE:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
CREATE TYPE HsAdminPersonType AS ENUM ('NATURAL', 'LEGAL', 'SOLE_REPRESENTATION', 'JOINT_REPRESENTATION'); CREATE TYPE HsOfficePersonType AS ENUM ('NATURAL', 'LEGAL', 'SOLE_REPRESENTATION', 'JOINT_REPRESENTATION');
CREATE CAST (character varying as HsAdminPersonType) WITH INOUT AS IMPLICIT; CREATE CAST (character varying as HsOfficePersonType) WITH INOUT AS IMPLICIT;
create table if not exists hs_admin_person create table if not exists hs_office_person
( (
uuid uuid unique references RbacObject (uuid) initially deferred, uuid uuid unique references RbacObject (uuid) initially deferred,
personType HsAdminPersonType not null, personType HsOfficePersonType not null,
tradeName varchar(96), tradeName varchar(96),
givenName varchar(48), givenName varchar(48),
familyName varchar(48) familyName varchar(48)

View File

@ -2,51 +2,51 @@
-- ============================================================================ -- ============================================================================
--changeset hs-admin-person-rbac-OBJECT:1 endDelimiter:--// --changeset hs-office-person-rbac-OBJECT:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
call generateRelatedRbacObject('hs_admin_person'); call generateRelatedRbacObject('hs_office_person');
--// --//
-- ============================================================================ -- ============================================================================
--changeset hs-admin-person-rbac-ROLE-DESCRIPTORS:1 endDelimiter:--// --changeset hs-office-person-rbac-ROLE-DESCRIPTORS:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
create or replace function hsAdminPersonOwner(person hs_admin_person) create or replace function hsOfficePersonOwner(person hs_office_person)
returns RbacRoleDescriptor returns RbacRoleDescriptor
language plpgsql language plpgsql
strict as $$ strict as $$
begin begin
return roleDescriptor('hs_admin_person', person.uuid, 'owner'); return roleDescriptor('hs_office_person', person.uuid, 'owner');
end; $$; end; $$;
create or replace function hsAdminPersonAdmin(person hs_admin_person) create or replace function hsOfficePersonAdmin(person hs_office_person)
returns RbacRoleDescriptor returns RbacRoleDescriptor
language plpgsql language plpgsql
strict as $$ strict as $$
begin begin
return roleDescriptor('hs_admin_person', person.uuid, 'admin'); return roleDescriptor('hs_office_person', person.uuid, 'admin');
end; $$; end; $$;
create or replace function hsAdminPersonTenant(person hs_admin_person) create or replace function hsOfficePersonTenant(person hs_office_person)
returns RbacRoleDescriptor returns RbacRoleDescriptor
language plpgsql language plpgsql
strict as $$ strict as $$
begin begin
return roleDescriptor('hs_admin_person', person.uuid, 'tenant'); return roleDescriptor('hs_office_person', person.uuid, 'tenant');
end; $$; end; $$;
--// --//
-- ============================================================================ -- ============================================================================
--changeset hs-admin-person-rbac-ROLES-CREATION:1 endDelimiter:--// --changeset hs-office-person-rbac-ROLES-CREATION:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
/* /*
Creates the roles and their assignments for a new person for the AFTER INSERT TRIGGER. Creates the roles and their assignments for a new person for the AFTER INSERT TRIGGER.
*/ */
create or replace function createRbacRolesForHsAdminPerson() create or replace function createRbacRolesForHsOfficePerson()
returns trigger returns trigger
language plpgsql language plpgsql
strict as $$ strict as $$
@ -60,7 +60,7 @@ begin
-- the owner role with full access for the creator assigned to the current user -- the owner role with full access for the creator assigned to the current user
ownerRole := createRole( ownerRole := createRole(
hsAdminPersonOwner(NEW), hsOfficePersonOwner(NEW),
grantingPermissions(forObjectUuid => NEW.uuid, permitOps => array ['*']), grantingPermissions(forObjectUuid => NEW.uuid, permitOps => array ['*']),
beneathRole(globalAdmin()), beneathRole(globalAdmin()),
withoutSubRoles(), withoutSubRoles(),
@ -70,14 +70,14 @@ begin
-- the tenant role for those related users who can view the data -- the tenant role for those related users who can view the data
adminRole := createRole( adminRole := createRole(
hsAdminPersonAdmin(NEW), hsOfficePersonAdmin(NEW),
grantingPermissions(forObjectUuid => NEW.uuid, permitOps => array ['edit']), grantingPermissions(forObjectUuid => NEW.uuid, permitOps => array ['edit']),
beneathRole(ownerRole) beneathRole(ownerRole)
); );
-- the tenant role for those related users who can view the data -- the tenant role for those related users who can view the data
perform createRole( perform createRole(
hsAdminPersonTenant(NEW), hsOfficePersonTenant(NEW),
grantingPermissions(forObjectUuid => NEW.uuid, permitOps => array ['view']), grantingPermissions(forObjectUuid => NEW.uuid, permitOps => array ['view']),
beneathRole(adminRole) beneathRole(adminRole)
); );
@ -89,82 +89,82 @@ end; $$;
An AFTER INSERT TRIGGER which creates the role structure for a new customer. An AFTER INSERT TRIGGER which creates the role structure for a new customer.
*/ */
create trigger createRbacRolesForHsAdminPerson_Trigger create trigger createRbacRolesForHsOfficePerson_Trigger
after insert after insert
on hs_admin_person on hs_office_person
for each row for each row
execute procedure createRbacRolesForHsAdminPerson(); execute procedure createRbacRolesForHsOfficePerson();
--// --//
-- ============================================================================ -- ============================================================================
--changeset hs-admin-person-rbac-IDENTITY-VIEW:1 endDelimiter:--// --changeset hs-office-person-rbac-IDENTITY-VIEW:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
/* /*
Creates a view to the person main table which maps the identifying name Creates a view to the person main table which maps the identifying name
(in this case, the prefix) to the objectUuid. (in this case, the prefix) to the objectUuid.
*/ */
create or replace view hs_admin_person_iv as create or replace view hs_office_person_iv as
select target.uuid, cleanIdentifier(concat(target.tradeName, target.familyName, target.givenName)) as idName select target.uuid, cleanIdentifier(concat(target.tradeName, target.familyName, target.givenName)) as idName
from hs_admin_person as target; from hs_office_person as target;
-- TODO.spec: Is it ok that everybody has access to this information? -- TODO.spec: Is it ok that everybody has access to this information?
grant all privileges on hs_admin_person_iv to restricted; grant all privileges on hs_office_person_iv to restricted;
/* /*
Returns the objectUuid for a given identifying name (in this case the prefix). Returns the objectUuid for a given identifying name (in this case the prefix).
*/ */
create or replace function hs_admin_personUuidByIdName(idName varchar) create or replace function hsOfficePersonUuidByIdName(idName varchar)
returns uuid returns uuid
language sql language sql
strict as $$ strict as $$
select uuid from hs_admin_person_iv iv where iv.idName = hs_admin_personUuidByIdName.idName; select uuid from hs_office_person_iv iv where iv.idName = hsOfficePersonUuidByIdName.idName;
$$; $$;
/* /*
Returns the identifying name for a given objectUuid (in this case the label). Returns the identifying name for a given objectUuid (in this case the label).
*/ */
create or replace function hs_admin_personIdNameByUuid(uuid uuid) create or replace function hs_office_personIdNameByUuid(uuid uuid)
returns varchar returns varchar
language sql language sql
strict as $$ strict as $$
select idName from hs_admin_person_iv iv where iv.uuid = hs_admin_personIdNameByUuid.uuid; select idName from hs_office_person_iv iv where iv.uuid = hs_office_personIdNameByUuid.uuid;
$$; $$;
--// --//
-- ============================================================================ -- ============================================================================
--changeset hs-admin-person-rbac-RESTRICTED-VIEW:1 endDelimiter:--// --changeset hs-office-person-rbac-RESTRICTED-VIEW:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
/* /*
Creates a view to the person main table with row-level limitation Creates a view to the person main table with row-level limitation
based on the 'view' permission of the current user or assumed roles. based on the 'view' permission of the current user or assumed roles.
*/ */
set session session authorization default; set session session authorization default;
drop view if exists hs_admin_person_rv; drop view if exists hs_office_person_rv;
create or replace view hs_admin_person_rv as create or replace view hs_office_person_rv as
select target.* select target.*
from hs_admin_person as target from hs_office_person as target
where target.uuid in (select queryAccessibleObjectUuidsOfSubjectIds('view', 'hs_admin_person', currentSubjectsUuids())); where target.uuid in (select queryAccessibleObjectUuidsOfSubjectIds('view', 'hs_office_person', currentSubjectsUuids()));
grant all privileges on hs_admin_person_rv to restricted; grant all privileges on hs_office_person_rv to restricted;
--// --//
-- ============================================================================ -- ============================================================================
--changeset hs-admin-person-rbac-INSTEAD-OF-INSERT-TRIGGER:1 endDelimiter:--// --changeset hs-office-person-rbac-INSTEAD-OF-INSERT-TRIGGER:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
/** /**
Instead of insert trigger function for hs_admin_person_rv. Instead of insert trigger function for hs_office_person_rv.
*/ */
create or replace function insertHsAdminPerson() create or replace function insertHsOfficePerson()
returns trigger returns trigger
language plpgsql as $$ language plpgsql as $$
declare declare
newUser hs_admin_person; newUser hs_office_person;
begin begin
insert insert
into hs_admin_person into hs_office_person
values (new.*) values (new.*)
returning * into newUser; returning * into newUser;
return newUser; return newUser;
@ -172,48 +172,48 @@ end;
$$; $$;
/* /*
Creates an instead of insert trigger for the hs_admin_person_rv view. Creates an instead of insert trigger for the hs_office_person_rv view.
*/ */
create trigger insertHsAdminPerson_Trigger create trigger insertHsOfficePerson_Trigger
instead of insert instead of insert
on hs_admin_person_rv on hs_office_person_rv
for each row for each row
execute function insertHsAdminPerson(); execute function insertHsOfficePerson();
--// --//
-- ============================================================================ -- ============================================================================
--changeset hs-admin-person-rbac-INSTEAD-OF-DELETE-TRIGGER:1 endDelimiter:--// --changeset hs-office-person-rbac-INSTEAD-OF-DELETE-TRIGGER:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
/** /**
Instead of delete trigger function for hs_admin_person_rv. Instead of delete trigger function for hs_office_person_rv.
Checks if the current subject (user / assumed role) has the permission to delete the row. Checks if the current subject (user / assumed role) has the permission to delete the row.
*/ */
create or replace function deleteHsAdminPerson() create or replace function deleteHsOfficePerson()
returns trigger returns trigger
language plpgsql as $$ language plpgsql as $$
begin begin
if hasGlobalRoleGranted(currentUserUuid()) or if hasGlobalRoleGranted(currentUserUuid()) or
old.uuid in (select queryAccessibleObjectUuidsOfSubjectIds('delete', 'hs_admin_person', currentSubjectsUuids())) then old.uuid in (select queryAccessibleObjectUuidsOfSubjectIds('delete', 'hs_office_person', currentSubjectsUuids())) then
delete from hs_admin_person c where c.uuid = old.uuid; delete from hs_office_person c where c.uuid = old.uuid;
return old; return old;
end if; end if;
raise exception '[403] User % not allowed to delete person uuid %', currentUser(), old.uuid; raise exception '[403] User % not allowed to delete person uuid %', currentUser(), old.uuid;
end; $$; end; $$;
/* /*
Creates an instead of delete trigger for the hs_admin_person_rv view. Creates an instead of delete trigger for the hs_office_person_rv view.
*/ */
create trigger deleteHsAdminPerson_Trigger create trigger deleteHsOfficePerson_Trigger
instead of delete instead of delete
on hs_admin_person_rv on hs_office_person_rv
for each row for each row
execute function deleteHsAdminPerson(); execute function deleteHsOfficePerson();
--/ --/
-- ============================================================================ -- ============================================================================
--changeset hs-admin-person-rbac-NEW-PERSON:1 endDelimiter:--// --changeset hs-office-person-rbac-NEW-PERSON:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
/* /*
Creates a global permission for new-person and assigns it to the hostsharing admins role. Creates a global permission for new-person and assigns it to the hostsharing admins role.
@ -236,7 +236,7 @@ $$;
/** /**
Used by the trigger to prevent the add-customer to current user respectively assumed roles. Used by the trigger to prevent the add-customer to current user respectively assumed roles.
*/ */
create or replace function addHsAdminPersonNotAllowedForCurrentSubjects() create or replace function addHsOfficePersonNotAllowedForCurrentSubjects()
returns trigger returns trigger
language PLPGSQL language PLPGSQL
as $$ as $$
@ -248,12 +248,12 @@ end; $$;
/** /**
Checks if the user or assumed roles are allowed to create a new customer. Checks if the user or assumed roles are allowed to create a new customer.
*/ */
create trigger hs_admin_person_insert_trigger create trigger hs_office_person_insert_trigger
before insert before insert
on hs_admin_person on hs_office_person
for each row for each row
-- TODO.spec: who is allowed to create new persons -- TODO.spec: who is allowed to create new persons
when ( not hasAssumedRole() ) when ( not hasAssumedRole() )
execute procedure addHsAdminPersonNotAllowedForCurrentSubjects(); execute procedure addHsOfficePersonNotAllowedForCurrentSubjects();
--// --//

View File

@ -2,14 +2,14 @@
-- ============================================================================ -- ============================================================================
--changeset hs-admin-person-TEST-DATA-GENERATOR:1 endDelimiter:--// --changeset hs-office-person-TEST-DATA-GENERATOR:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
/* /*
Creates a single person test record. Creates a single person test record.
*/ */
create or replace procedure createHsAdminPersonTestData( create or replace procedure createHsOfficePersonTestData(
newPersonType HsAdminPersonType, newPersonType HsOfficePersonType,
newTradeName varchar, newTradeName varchar,
newFamilyName varchar = null, newFamilyName varchar = null,
newGivenName varchar = null newGivenName varchar = null
@ -30,7 +30,7 @@ begin
raise notice 'creating test person: %', fullName; raise notice 'creating test person: %', fullName;
insert insert
into hs_admin_person (persontype, tradename, givenname, familyname) into hs_office_person (persontype, tradename, givenname, familyname)
values (newPersonType, newTradeName, newGivenName, newFamilyName); values (newPersonType, newTradeName, newGivenName, newFamilyName);
end; $$; end; $$;
--// --//
@ -46,7 +46,7 @@ create or replace procedure createTestPersonTestData(
begin begin
for t in startCount..endCount for t in startCount..endCount
loop loop
call createHsAdminPersonTestData('LEGAL', intToVarChar(t, 4)); call createHsOfficePersonTestData('LEGAL', intToVarChar(t, 4));
commit; commit;
end loop; end loop;
end; $$; end; $$;
@ -54,16 +54,16 @@ end; $$;
-- ============================================================================ -- ============================================================================
--changeset hs-admin-person-TEST-DATA-GENERATION:1 context=dev,tc endDelimiter:--// --changeset hs-office-person-TEST-DATA-GENERATION:1 context=dev,tc endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
do language plpgsql $$ do language plpgsql $$
begin begin
call createHsAdminPersonTestData('LEGAL', 'First Impressions GmbH'); call createHsOfficePersonTestData('LEGAL', 'First Impressions GmbH');
call createHsAdminPersonTestData('NATURAL', null, 'Peter', 'Smith'); call createHsOfficePersonTestData('NATURAL', null, 'Peter', 'Smith');
call createHsAdminPersonTestData('LEGAL', 'Rockshop e.K.', 'Sandra', 'Miller'); call createHsOfficePersonTestData('LEGAL', 'Rockshop e.K.', 'Sandra', 'Miller');
call createHsAdminPersonTestData('SOLE_REPRESENTATION', 'Ostfriesische Kuhhandel OHG'); call createHsOfficePersonTestData('SOLE_REPRESENTATION', 'Ostfriesische Kuhhandel OHG');
call createHsAdminPersonTestData('JOINT_REPRESENTATION', 'Erben Bessler', 'Mel', 'Bessler'); call createHsOfficePersonTestData('JOINT_REPRESENTATION', 'Erben Bessler', 'Mel', 'Bessler');
end; end;
$$; $$;
--// --//

View File

@ -1,14 +1,14 @@
--liquibase formatted sql --liquibase formatted sql
-- ============================================================================ -- ============================================================================
--changeset hs-admin-partner-MAIN-TABLE:1 endDelimiter:--// --changeset hs-office-partner-MAIN-TABLE:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
create table if not exists hs_admin_partner create table if not exists hs_office_partner
( (
uuid uuid unique references RbacObject (uuid) initially deferred, -- on delete cascade uuid uuid unique references RbacObject (uuid) initially deferred, -- on delete cascade
personUuid uuid not null references hs_admin_person(uuid), personUuid uuid not null references hs_office_person(uuid),
contactUuid uuid not null references hs_admin_contact(uuid), contactUuid uuid not null references hs_office_contact(uuid),
registrationOffice varchar(96), registrationOffice varchar(96),
registrationNumber varchar(96), registrationNumber varchar(96),
birthName varchar(96), birthName varchar(96),

View File

@ -1,87 +1,87 @@
--liquibase formatted sql --liquibase formatted sql
-- ============================================================================ -- ============================================================================
--changeset hs-admin-partner-rbac-OBJECT:1 endDelimiter:--// --changeset hs-office-partner-rbac-OBJECT:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
call generateRelatedRbacObject('hs_admin_partner'); call generateRelatedRbacObject('hs_office_partner');
--// --//
-- ============================================================================ -- ============================================================================
--changeset hs-admin-partner-rbac-ROLE-DESCRIPTORS:1 endDelimiter:--// --changeset hs-office-partner-rbac-ROLE-DESCRIPTORS:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
create or replace function hsAdminPartnerOwner(partner hs_admin_partner) create or replace function HsOfficePartnerOwner(partner hs_office_partner)
returns RbacRoleDescriptor returns RbacRoleDescriptor
language plpgsql language plpgsql
strict as $$ strict as $$
begin begin
return roleDescriptor('hs_admin_partner', partner.uuid, 'owner'); return roleDescriptor('hs_office_partner', partner.uuid, 'owner');
end; $$; end; $$;
create or replace function hsAdminPartnerAdmin(partner hs_admin_partner) create or replace function HsOfficePartnerAdmin(partner hs_office_partner)
returns RbacRoleDescriptor returns RbacRoleDescriptor
language plpgsql language plpgsql
strict as $$ strict as $$
begin begin
return roleDescriptor('hs_admin_partner', partner.uuid, 'admin'); return roleDescriptor('hs_office_partner', partner.uuid, 'admin');
end; $$; end; $$;
create or replace function hsAdminPartnerTenant(partner hs_admin_partner) create or replace function HsOfficePartnerTenant(partner hs_office_partner)
returns RbacRoleDescriptor returns RbacRoleDescriptor
language plpgsql language plpgsql
strict as $$ strict as $$
begin begin
return roleDescriptor('hs_admin_partner', partner.uuid, 'tenant'); return roleDescriptor('hs_office_partner', partner.uuid, 'tenant');
end; $$; end; $$;
--// --//
-- ============================================================================ -- ============================================================================
--changeset hs-admin-partner-rbac-ROLES-CREATION:1 endDelimiter:--// --changeset hs-office-partner-rbac-ROLES-CREATION:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
/* /*
Creates the roles and their assignments for a new partner for the AFTER INSERT TRIGGER. Creates the roles and their assignments for a new partner for the AFTER INSERT TRIGGER.
*/ */
create or replace function createRbacRolesForHsAdminPartner() create or replace function createRbacRolesForHsOfficePartner()
returns trigger returns trigger
language plpgsql language plpgsql
strict as $$ strict as $$
declare declare
ownerRole uuid; ownerRole uuid;
adminRole uuid; adminRole uuid;
person hs_admin_person; person hs_office_person;
contact hs_admin_contact; contact hs_office_contact;
begin begin
if TG_OP <> 'INSERT' then if TG_OP <> 'INSERT' then
raise exception 'invalid usage of TRIGGER AFTER INSERT'; raise exception 'invalid usage of TRIGGER AFTER INSERT';
end if; end if;
select * from hs_admin_person as p where p.uuid = NEW.personUuid into person; select * from hs_office_person as p where p.uuid = NEW.personUuid into person;
select * from hs_admin_contact as c where c.uuid = NEW.contactUuid into contact; select * from hs_office_contact as c where c.uuid = NEW.contactUuid into contact;
-- the owner role with full access for the global admins -- the owner role with full access for the global admins
ownerRole = createRole( ownerRole = createRole(
hsAdminPartnerOwner(NEW), HsOfficePartnerOwner(NEW),
grantingPermissions(forObjectUuid => NEW.uuid, permitOps => array ['*']), grantingPermissions(forObjectUuid => NEW.uuid, permitOps => array ['*']),
beneathRole(globalAdmin()) beneathRole(globalAdmin())
); );
-- the admin role with full access for the global admins -- the admin role with full access for the global admins
adminRole = createRole( adminRole = createRole(
hsAdminPartnerAdmin(NEW), HsOfficePartnerAdmin(NEW),
grantingPermissions(forObjectUuid => NEW.uuid, permitOps => array ['edit']), grantingPermissions(forObjectUuid => NEW.uuid, permitOps => array ['edit']),
beneathRole(ownerRole) beneathRole(ownerRole)
); );
-- the tenant role for those related users who can view the data -- the tenant role for those related users who can view the data
perform createRole( perform createRole(
hsAdminPartnerTenant(NEW), HsOfficePartnerTenant(NEW),
grantingPermissions(forObjectUuid => NEW.uuid, permitOps => array ['view']), grantingPermissions(forObjectUuid => NEW.uuid, permitOps => array ['view']),
beneathRoles(array[hsAdminPartnerAdmin(NEW), hsAdminPersonAdmin(person), hsAdminContactAdmin(contact)]), beneathRoles(array[HsOfficePartnerAdmin(NEW), hsOfficePersonAdmin(person), hsOfficeContactAdmin(contact)]),
withSubRoles(array[hsAdminPersonTenant(person), hsAdminContactTenant(contact)]) withSubRoles(array[hsOfficePersonTenant(person), hsOfficeContactTenant(contact)])
); );
return NEW; return NEW;
@ -91,88 +91,88 @@ end; $$;
An AFTER INSERT TRIGGER which creates the role structure for a new customer. An AFTER INSERT TRIGGER which creates the role structure for a new customer.
*/ */
create trigger createRbacRolesForHsAdminPartner_Trigger create trigger createRbacRolesForHsOfficePartner_Trigger
after insert after insert
on hs_admin_partner on hs_office_partner
for each row for each row
execute procedure createRbacRolesForHsAdminPartner(); execute procedure createRbacRolesForHsOfficePartner();
--// --//
-- ============================================================================ -- ============================================================================
--changeset hs-admin-partner-rbac-IDENTITY-VIEW:1 endDelimiter:--// --changeset hs-office-partner-rbac-IDENTITY-VIEW:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
/* /*
Creates a view to the partner main table which maps the identifying name Creates a view to the partner main table which maps the identifying name
(in this case, the prefix) to the objectUuid. (in this case, the prefix) to the objectUuid.
*/ */
create or replace view hs_admin_partner_iv as create or replace view hs_office_partner_iv as
select target.uuid, select target.uuid,
cleanIdentifier( cleanIdentifier(
(select idName from hs_admin_person_iv p where p.uuid = target.personuuid) (select idName from hs_office_person_iv p where p.uuid = target.personuuid)
|| '-' || || '-' ||
(select idName from hs_admin_contact_iv c where c.uuid = target.contactuuid) (select idName from hs_office_contact_iv c where c.uuid = target.contactuuid)
) )
as idName as idName
from hs_admin_partner as target; from hs_office_partner as target;
-- TODO.spec: Is it ok that everybody has access to this information? -- TODO.spec: Is it ok that everybody has access to this information?
grant all privileges on hs_admin_partner_iv to restricted; grant all privileges on hs_office_partner_iv to restricted;
/* /*
Returns the objectUuid for a given identifying name (in this case the prefix). Returns the objectUuid for a given identifying name (in this case the prefix).
*/ */
create or replace function hs_admin_partnerUuidByIdName(idName varchar) create or replace function hs_office_partnerUuidByIdName(idName varchar)
returns uuid returns uuid
language sql language sql
strict as $$ strict as $$
select uuid from hs_admin_partner_iv iv where iv.idName = hs_admin_partnerUuidByIdName.idName; select uuid from hs_office_partner_iv iv where iv.idName = hs_office_partnerUuidByIdName.idName;
$$; $$;
/* /*
Returns the identifying name for a given objectUuid (in this case the label). Returns the identifying name for a given objectUuid (in this case the label).
*/ */
create or replace function hs_admin_partnerIdNameByUuid(uuid uuid) create or replace function hs_office_partnerIdNameByUuid(uuid uuid)
returns varchar returns varchar
language sql language sql
strict as $$ strict as $$
select idName from hs_admin_partner_iv iv where iv.uuid = hs_admin_partnerIdNameByUuid.uuid; select idName from hs_office_partner_iv iv where iv.uuid = hs_office_partnerIdNameByUuid.uuid;
$$; $$;
--// --//
-- ============================================================================ -- ============================================================================
--changeset hs-admin-partner-rbac-RESTRICTED-VIEW:1 endDelimiter:--// --changeset hs-office-partner-rbac-RESTRICTED-VIEW:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
/* /*
Creates a view to the partner main table with row-level limitation Creates a view to the partner main table with row-level limitation
based on the 'view' permission of the current user or assumed roles. based on the 'view' permission of the current user or assumed roles.
*/ */
set session session authorization default; set session session authorization default;
drop view if exists hs_admin_partner_rv; drop view if exists hs_office_partner_rv;
create or replace view hs_admin_partner_rv as create or replace view hs_office_partner_rv as
select target.* select target.*
from hs_admin_partner as target from hs_office_partner as target
where target.uuid in (select queryAccessibleObjectUuidsOfSubjectIds('view', 'hs_admin_partner', currentSubjectsUuids())); where target.uuid in (select queryAccessibleObjectUuidsOfSubjectIds('view', 'hs_office_partner', currentSubjectsUuids()));
grant all privileges on hs_admin_partner_rv to restricted; grant all privileges on hs_office_partner_rv to restricted;
--// --//
-- ============================================================================ -- ============================================================================
--changeset hs-admin-partner-rbac-INSTEAD-OF-INSERT-TRIGGER:1 endDelimiter:--// --changeset hs-office-partner-rbac-INSTEAD-OF-INSERT-TRIGGER:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
/** /**
Instead of insert trigger function for hs_admin_partner_rv. Instead of insert trigger function for hs_office_partner_rv.
*/ */
create or replace function insertHsAdminPartner() create or replace function insertHsOfficePartner()
returns trigger returns trigger
language plpgsql as $$ language plpgsql as $$
declare declare
newUser hs_admin_partner; newUser hs_office_partner;
begin begin
insert insert
into hs_admin_partner into hs_office_partner
values (new.*) values (new.*)
returning * into newUser; returning * into newUser;
return newUser; return newUser;
@ -180,48 +180,48 @@ end;
$$; $$;
/* /*
Creates an instead of insert trigger for the hs_admin_partner_rv view. Creates an instead of insert trigger for the hs_office_partner_rv view.
*/ */
create trigger insertHsAdminPartner_Trigger create trigger insertHsOfficePartner_Trigger
instead of insert instead of insert
on hs_admin_partner_rv on hs_office_partner_rv
for each row for each row
execute function insertHsAdminPartner(); execute function insertHsOfficePartner();
--// --//
-- ============================================================================ -- ============================================================================
--changeset hs-admin-partner-rbac-INSTEAD-OF-DELETE-TRIGGER:1 endDelimiter:--// --changeset hs-office-partner-rbac-INSTEAD-OF-DELETE-TRIGGER:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
/** /**
Instead of delete trigger function for hs_admin_partner_rv. Instead of delete trigger function for hs_office_partner_rv.
Checks if the current subject (user / assumed role) has the permission to delete the row. Checks if the current subject (user / assumed role) has the permission to delete the row.
*/ */
create or replace function deleteHsAdminPartner() create or replace function deleteHsOfficePartner()
returns trigger returns trigger
language plpgsql as $$ language plpgsql as $$
begin begin
if hasGlobalRoleGranted(currentUserUuid()) or if hasGlobalRoleGranted(currentUserUuid()) or
old.uuid in (select queryAccessibleObjectUuidsOfSubjectIds('delete', 'hs_admin_partner', currentSubjectsUuids())) then old.uuid in (select queryAccessibleObjectUuidsOfSubjectIds('delete', 'hs_office_partner', currentSubjectsUuids())) then
delete from hs_admin_partner c where c.uuid = old.uuid; delete from hs_office_partner c where c.uuid = old.uuid;
return old; return old;
end if; end if;
raise exception '[403] User % not allowed to delete partner uuid %', currentUser(), old.uuid; raise exception '[403] User % not allowed to delete partner uuid %', currentUser(), old.uuid;
end; $$; end; $$;
/* /*
Creates an instead of delete trigger for the hs_admin_partner_rv view. Creates an instead of delete trigger for the hs_office_partner_rv view.
*/ */
create trigger deleteHsAdminPartner_Trigger create trigger deleteHsOfficePartner_Trigger
instead of delete instead of delete
on hs_admin_partner_rv on hs_office_partner_rv
for each row for each row
execute function deleteHsAdminPartner(); execute function deleteHsOfficePartner();
--/ --/
-- ============================================================================ -- ============================================================================
--changeset hs-admin-partner-rbac-NEW-CONTACT:1 endDelimiter:--// --changeset hs-office-partner-rbac-NEW-CONTACT:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
/* /*
Creates a global permission for new-partner and assigns it to the hostsharing admins role. Creates a global permission for new-partner and assigns it to the hostsharing admins role.
@ -244,7 +244,7 @@ $$;
/** /**
Used by the trigger to prevent the add-customer to current user respectively assumed roles. Used by the trigger to prevent the add-customer to current user respectively assumed roles.
*/ */
create or replace function addHsAdminPartnerNotAllowedForCurrentSubjects() create or replace function addHsOfficePartnerNotAllowedForCurrentSubjects()
returns trigger returns trigger
language PLPGSQL language PLPGSQL
as $$ as $$
@ -256,12 +256,12 @@ end; $$;
/** /**
Checks if the user or assumed roles are allowed to create a new customer. Checks if the user or assumed roles are allowed to create a new customer.
*/ */
create trigger hs_admin_partner_insert_trigger create trigger hs_office_partner_insert_trigger
before insert before insert
on hs_admin_partner on hs_office_partner
for each row for each row
-- TODO.spec: who is allowed to create new partners -- TODO.spec: who is allowed to create new partners
when ( not hasAssumedRole() ) when ( not hasAssumedRole() )
execute procedure addHsAdminPartnerNotAllowedForCurrentSubjects(); execute procedure addHsOfficePartnerNotAllowedForCurrentSubjects();
--// --//

View File

@ -2,33 +2,33 @@
-- ============================================================================ -- ============================================================================
--changeset hs-admin-partner-TEST-DATA-GENERATOR:1 endDelimiter:--// --changeset hs-office-partner-TEST-DATA-GENERATOR:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
/* /*
Creates a single partner test record. Creates a single partner test record.
*/ */
create or replace procedure createHsAdminPartnerTestData( personTradeName varchar, contactLabel varchar ) create or replace procedure createHsOfficePartnerTestData( personTradeName varchar, contactLabel varchar )
language plpgsql as $$ language plpgsql as $$
declare declare
currentTask varchar; currentTask varchar;
idName varchar; idName varchar;
relatedPerson hs_admin_person; relatedPerson hs_office_person;
relatedContact hs_admin_contact; relatedContact hs_office_contact;
begin begin
idName := cleanIdentifier( personTradeName|| '-' || contactLabel); idName := cleanIdentifier( personTradeName|| '-' || contactLabel);
currentTask := 'creating RBAC test partner ' || idName; currentTask := 'creating RBAC test partner ' || idName;
call defineContext(currentTask, null, 'alex@hostsharing.net', 'global#global.admin'); call defineContext(currentTask, null, 'alex@hostsharing.net', 'global#global.admin');
execute format('set local hsadminng.currentTask to %L', currentTask); execute format('set local hsadminng.currentTask to %L', currentTask);
select p.* from hs_admin_person p where p.tradeName = personTradeName into relatedPerson; select p.* from hs_office_person p where p.tradeName = personTradeName into relatedPerson;
select c.* from hs_admin_contact c where c.label = contactLabel into relatedContact; select c.* from hs_office_contact c where c.label = contactLabel into relatedContact;
raise notice 'creating test partner: %', idName; raise notice 'creating test partner: %', idName;
raise notice '- using person (%): %', relatedPerson.uuid, relatedPerson; raise notice '- using person (%): %', relatedPerson.uuid, relatedPerson;
raise notice '- using contact (%): %', relatedContact.uuid, relatedContact; raise notice '- using contact (%): %', relatedContact.uuid, relatedContact;
insert insert
into hs_admin_partner (uuid, personuuid, contactuuid) into hs_office_partner (uuid, personuuid, contactuuid)
values (uuid_generate_v4(), relatedPerson.uuid, relatedContact.uuid); values (uuid_generate_v4(), relatedPerson.uuid, relatedContact.uuid);
end; $$; end; $$;
--// --//
@ -36,21 +36,21 @@ end; $$;
/* /*
Creates a range of test partner for mass data generation. Creates a range of test partner for mass data generation.
*/ */
create or replace procedure createTestContactTestData( create or replace procedure createHsOfficePartnerTestData(
startCount integer, -- count of auto generated rows before the run startCount integer, -- count of auto generated rows before the run
endCount integer -- count of auto generated rows after the run endCount integer -- count of auto generated rows after the run
) )
language plpgsql as $$ language plpgsql as $$
declare declare
person hs_admin_person; person hs_office_person;
contact hs_admin_contact; contact hs_office_contact;
begin begin
for t in startCount..endCount for t in startCount..endCount
loop loop
select p.* from hs_admin_person p where tradeName = intToVarChar(t, 4) into person; select p.* from hs_office_person p where tradeName = intToVarChar(t, 4) into person;
select c.* from hs_admin_contact c where c.label = intToVarChar(t, 4) || '#' || t into contact; select c.* from hs_office_contact c where c.label = intToVarChar(t, 4) || '#' || t into contact;
call createHsAdminPartnerTestData(person.uuid, contact.uuid); call createHsOfficePartnerTestData(person.uuid, contact.uuid);
commit; commit;
end loop; end loop;
end; $$; end; $$;
@ -58,16 +58,16 @@ end; $$;
-- ============================================================================ -- ============================================================================
--changeset hs-admin-partner-TEST-DATA-GENERATION:1 context=dev,tc endDelimiter:--// --changeset hs-office-partner-TEST-DATA-GENERATION:1 context=dev,tc endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
do language plpgsql $$ do language plpgsql $$
begin begin
call createHsAdminPartnerTestData('First Impressions GmbH', 'first contact'); call createHsOfficePartnerTestData('First Impressions GmbH', 'first contact');
call createHsAdminPartnerTestData('Rockshop e.K.', 'second contact'); call createHsOfficePartnerTestData('Rockshop e.K.', 'second contact');
call createHsAdminPartnerTestData('Ostfriesische Kuhhandel OHG', 'third contact'); call createHsOfficePartnerTestData('Ostfriesische Kuhhandel OHG', 'third contact');
end; end;
$$; $$;
--// --//

View File

@ -46,20 +46,20 @@ databaseChangeLog:
- include: - include:
file: db/changelog/138-test-domain-test-data.sql file: db/changelog/138-test-domain-test-data.sql
- include: - include:
file: db/changelog/200-hs-admin-contact.sql file: db/changelog/200-hs-office-contact.sql
- include: - include:
file: db/changelog/203-hs-admin-contact-rbac.sql file: db/changelog/203-hs-office-contact-rbac.sql
- include: - include:
file: db/changelog/208-hs-admin-contact-test-data.sql file: db/changelog/208-hs-office-contact-test-data.sql
- include: - include:
file: db/changelog/210-hs-admin-person.sql file: db/changelog/210-hs-office-person.sql
- include: - include:
file: db/changelog/213-hs-admin-person-rbac.sql file: db/changelog/213-hs-office-person-rbac.sql
- include: - include:
file: db/changelog/218-hs-admin-person-test-data.sql file: db/changelog/218-hs-office-person-test-data.sql
- include: - include:
file: db/changelog/220-hs-admin-partner.sql file: db/changelog/220-hs-office-partner.sql
- include: - include:
file: db/changelog/223-hs-admin-partner-rbac.sql file: db/changelog/223-hs-office-partner-rbac.sql
- include: - include:
file: db/changelog/228-hs-admin-partner-test-data.sql file: db/changelog/228-hs-office-partner-test-data.sql

View File

@ -53,16 +53,16 @@ public class ArchTest {
@com.tngtech.archunit.junit.ArchTest @com.tngtech.archunit.junit.ArchTest
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static final ArchRule hsAdminPackagesRule = classes() public static final ArchRule hsAdminPackagesRule = classes()
.that().resideInAPackage("..hs.admin.(*)..") .that().resideInAPackage("..hs.office.(*)..")
.should().onlyBeAccessed().byClassesThat() .should().onlyBeAccessed().byClassesThat()
.resideInAnyPackage("..hs.admin.(*).."); .resideInAnyPackage("..hs.office.(*)..");
@com.tngtech.archunit.junit.ArchTest @com.tngtech.archunit.junit.ArchTest
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static final ArchRule hsAdminPartnerPackageRule = classes() public static final ArchRule HsOfficePartnerPackageRule = classes()
.that().resideInAPackage("..hs.admin.partner..") .that().resideInAPackage("..hs.office.partner..")
.should().onlyBeAccessed().byClassesThat() .should().onlyBeAccessed().byClassesThat()
.resideInAnyPackage("..hs.admin.partner.."); .resideInAnyPackage("..hs.office.partner..");
@com.tngtech.archunit.junit.ArchTest @com.tngtech.archunit.junit.ArchTest
@SuppressWarnings("unused") @SuppressWarnings("unused")

View File

@ -1,17 +0,0 @@
package net.hostsharing.hsadminng.hs.admin.contact;
import java.util.UUID;
public class TestHsAdminContact {
public static final HsAdminContactEntity someContact = hsAdminContact("some contact", "some-contact@example.com");
static public HsAdminContactEntity hsAdminContact(final String label, final String emailAddr) {
return HsAdminContactEntity.builder()
.uuid(UUID.randomUUID())
.label(label)
.postalAddress("address of " + label)
.emailAddresses(emailAddr)
.build();
}
}

View File

@ -1,26 +0,0 @@
package net.hostsharing.hsadminng.hs.admin.partner;
import net.hostsharing.hsadminng.hs.admin.contact.HsAdminContactEntity;
import net.hostsharing.hsadminng.hs.admin.person.HsAdminPersonEntity;
import java.util.UUID;
import static net.hostsharing.hsadminng.hs.admin.person.HsAdminPersonType.LEGAL;
public class TestHsAdminPartner {
public static final HsAdminPartnerEntity testLtd = hsAdminPartnerWithLegalPerson("Test Ltd.");
static public HsAdminPartnerEntity hsAdminPartnerWithLegalPerson(final String tradeName) {
return HsAdminPartnerEntity.builder()
.uuid(UUID.randomUUID())
.person(HsAdminPersonEntity.builder()
.personType(LEGAL)
.tradeName(tradeName)
.build())
.contact(HsAdminContactEntity.builder()
.label(tradeName)
.build())
.build();
}
}

View File

@ -1,16 +0,0 @@
package net.hostsharing.hsadminng.hs.admin.person;
import java.util.UUID;
public class TestHsAdminPerson {
public static final HsAdminPersonEntity somePerson = hsAdminPerson("some person");
static public HsAdminPersonEntity hsAdminPerson(final String tradeName) {
return HsAdminPersonEntity.builder()
.uuid(UUID.randomUUID())
.personType(HsAdminPersonType.NATURAL)
.tradeName(tradeName)
.build();
}
}

View File

@ -1,4 +1,4 @@
package net.hostsharing.hsadminng.hs.admin.contact; package net.hostsharing.hsadminng.hs.office.contact;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.context.ContextBasedTest; import net.hostsharing.hsadminng.context.ContextBasedTest;
@ -22,7 +22,7 @@ import javax.servlet.http.HttpServletRequest;
import java.util.List; import java.util.List;
import java.util.function.Supplier; import java.util.function.Supplier;
import static net.hostsharing.hsadminng.hs.admin.contact.TestHsAdminContact.hsAdminContact; import static net.hostsharing.hsadminng.hs.office.contact.TestHsOfficeContact.hsOfficeContact;
import static net.hostsharing.hsadminng.rbac.rbacgrant.RbacGrantDisplayExtractor.grantDisplaysOf; import static net.hostsharing.hsadminng.rbac.rbacgrant.RbacGrantDisplayExtractor.grantDisplaysOf;
import static net.hostsharing.hsadminng.rbac.rbacrole.RbacRoleNameExtractor.roleNamesOf; import static net.hostsharing.hsadminng.rbac.rbacrole.RbacRoleNameExtractor.roleNamesOf;
import static net.hostsharing.test.JpaAttempt.attempt; import static net.hostsharing.test.JpaAttempt.attempt;
@ -30,12 +30,12 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assumptions.assumeThat; import static org.assertj.core.api.Assumptions.assumeThat;
@DataJpaTest @DataJpaTest
@ComponentScan(basePackageClasses = { HsAdminContactRepository.class, Context.class, JpaAttempt.class }) @ComponentScan(basePackageClasses = { HsOfficeContactRepository.class, Context.class, JpaAttempt.class })
@DirtiesContext @DirtiesContext
class HsAdminContactRepositoryIntegrationTest extends ContextBasedTest { class HsOfficeContactRepositoryIntegrationTest extends ContextBasedTest {
@Autowired @Autowired
HsAdminContactRepository contactRepo; HsOfficeContactRepository contactRepo;
@Autowired @Autowired
RbacRoleRepository roleRepo; RbacRoleRepository roleRepo;
@ -67,11 +67,11 @@ class HsAdminContactRepositoryIntegrationTest extends ContextBasedTest {
// when // when
final var result = attempt(em, () -> contactRepo.save( final var result = attempt(em, () -> contactRepo.save(
hsAdminContact("a new contact", "contact-admin@www.example.com"))); hsOfficeContact("a new contact", "contact-admin@www.example.com")));
// then // then
result.assertSuccessful(); result.assertSuccessful();
assertThat(result.returnedValue()).isNotNull().extracting(HsAdminContactEntity::getUuid).isNotNull(); assertThat(result.returnedValue()).isNotNull().extracting(HsOfficeContactEntity::getUuid).isNotNull();
assertThatContactIsPersisted(result.returnedValue()); assertThatContactIsPersisted(result.returnedValue());
assertThat(contactRepo.count()).isEqualTo(count + 1); assertThat(contactRepo.count()).isEqualTo(count + 1);
} }
@ -84,11 +84,11 @@ class HsAdminContactRepositoryIntegrationTest extends ContextBasedTest {
// when // when
final var result = attempt(em, () -> contactRepo.save( final var result = attempt(em, () -> contactRepo.save(
hsAdminContact("another new contact", "another-new-contact@example.com"))); hsOfficeContact("another new contact", "another-new-contact@example.com")));
// then // then
result.assertSuccessful(); result.assertSuccessful();
assertThat(result.returnedValue()).isNotNull().extracting(HsAdminContactEntity::getUuid).isNotNull(); assertThat(result.returnedValue()).isNotNull().extracting(HsOfficeContactEntity::getUuid).isNotNull();
assertThatContactIsPersisted(result.returnedValue()); assertThatContactIsPersisted(result.returnedValue());
assertThat(contactRepo.count()).isEqualTo(count + 1); assertThat(contactRepo.count()).isEqualTo(count + 1);
} }
@ -103,7 +103,7 @@ class HsAdminContactRepositoryIntegrationTest extends ContextBasedTest {
// when // when
attempt(em, () -> contactRepo.save( attempt(em, () -> contactRepo.save(
hsAdminContact("another new contact", "another-new-contact@example.com")) hsOfficeContact("another new contact", "another-new-contact@example.com"))
).assumeSuccessful(); ).assumeSuccessful();
// then // then
@ -111,17 +111,17 @@ class HsAdminContactRepositoryIntegrationTest extends ContextBasedTest {
assertThat(roleNamesOf(roles)).containsExactlyInAnyOrder( assertThat(roleNamesOf(roles)).containsExactlyInAnyOrder(
Array.from( Array.from(
initialRoleNames, initialRoleNames,
"hs_admin_contact#anothernewcontact.owner", "hs_office_contact#anothernewcontact.owner",
"hs_admin_contact#anothernewcontact.admin", "hs_office_contact#anothernewcontact.admin",
"hs_admin_contact#anothernewcontact.tenant")); "hs_office_contact#anothernewcontact.tenant"));
final var grants = grantRepo.findAll(); final var grants = grantRepo.findAll();
assertThat(grantDisplaysOf(grants)).containsAll(List.of( assertThat(grantDisplaysOf(grants)).containsAll(List.of(
"{ grant assumed role hs_admin_contact#anothernewcontact.owner to user drew@hostsharing.org by role global#global.admin }")); "{ grant assumed role hs_office_contact#anothernewcontact.owner to user drew@hostsharing.org by role global#global.admin }"));
assertThat(grants.size()).as("invalid number of grants created") assertThat(grants.size()).as("invalid number of grants created")
.isEqualTo(initialGrantCount + 1); .isEqualTo(initialGrantCount + 1);
} }
private void assertThatContactIsPersisted(final HsAdminContactEntity saved) { private void assertThatContactIsPersisted(final HsOfficeContactEntity saved) {
final var found = contactRepo.findByUuid(saved.getUuid()); final var found = contactRepo.findByUuid(saved.getUuid());
assertThat(found).isNotEmpty().get().usingRecursiveComparison().isEqualTo(saved); assertThat(found).isNotEmpty().get().usingRecursiveComparison().isEqualTo(saved);
} }
@ -253,9 +253,9 @@ class HsAdminContactRepositoryIntegrationTest extends ContextBasedTest {
} }
} }
private HsAdminContactEntity givenSomeTemporaryContact( private HsOfficeContactEntity givenSomeTemporaryContact(
final String createdByUser, final String createdByUser,
Supplier<HsAdminContactEntity> entitySupplier) { Supplier<HsOfficeContactEntity> entitySupplier) {
return jpaAttempt.transacted(() -> { return jpaAttempt.transacted(() -> {
context(createdByUser); context(createdByUser);
return contactRepo.save(entitySupplier.get()); return contactRepo.save(entitySupplier.get());
@ -272,23 +272,23 @@ class HsAdminContactRepositoryIntegrationTest extends ContextBasedTest {
}); });
} }
private HsAdminContactEntity givenSomeTemporaryContact(final String createdByUser) { private HsOfficeContactEntity givenSomeTemporaryContact(final String createdByUser) {
final var random = RandomString.make(12); final var random = RandomString.make(12);
return givenSomeTemporaryContact(createdByUser, () -> return givenSomeTemporaryContact(createdByUser, () ->
hsAdminContact( hsOfficeContact(
"some temporary contact #" + random, "some temporary contact #" + random,
"some-temporary-contact" + random + "@example.com")); "some-temporary-contact" + random + "@example.com"));
} }
void exactlyTheseContactsAreReturned(final List<HsAdminContactEntity> actualResult, final String... contactLabels) { void exactlyTheseContactsAreReturned(final List<HsOfficeContactEntity> actualResult, final String... contactLabels) {
assertThat(actualResult) assertThat(actualResult)
.extracting(HsAdminContactEntity::getLabel) .extracting(HsOfficeContactEntity::getLabel)
.containsExactlyInAnyOrder(contactLabels); .containsExactlyInAnyOrder(contactLabels);
} }
void allTheseContactsAreReturned(final List<HsAdminContactEntity> actualResult, final String... contactLabels) { void allTheseContactsAreReturned(final List<HsOfficeContactEntity> actualResult, final String... contactLabels) {
assertThat(actualResult) assertThat(actualResult)
.extracting(HsAdminContactEntity::getLabel) .extracting(HsOfficeContactEntity::getLabel)
.contains(contactLabels); .contains(contactLabels);
} }
} }

View File

@ -0,0 +1,17 @@
package net.hostsharing.hsadminng.hs.office.contact;
import java.util.UUID;
public class TestHsOfficeContact {
public static final HsOfficeContactEntity someContact = hsOfficeContact("some contact", "some-contact@example.com");
static public HsOfficeContactEntity hsOfficeContact(final String label, final String emailAddr) {
return HsOfficeContactEntity.builder()
.uuid(UUID.randomUUID())
.label(label)
.postalAddress("address of " + label)
.emailAddresses(emailAddr)
.build();
}
}

View File

@ -1,4 +1,4 @@
package net.hostsharing.hsadminng.hs.admin.partner; package net.hostsharing.hsadminng.hs.office.partner;
import io.restassured.RestAssured; import io.restassured.RestAssured;
import io.restassured.http.ContentType; import io.restassured.http.ContentType;
@ -24,7 +24,7 @@ import static org.hamcrest.Matchers.*;
classes = HsadminNgApplication.class classes = HsadminNgApplication.class
) )
@Transactional @Transactional
class HsAdminPartnerControllerAcceptanceTest { class HsOfficePartnerControllerAcceptanceTest {
@LocalServerPort @LocalServerPort
private Integer port; private Integer port;
@ -35,7 +35,7 @@ class HsAdminPartnerControllerAcceptanceTest {
@Autowired @Autowired
Context contextMock; Context contextMock;
@Autowired @Autowired
HsAdminPartnerRepository partnerRepository; HsOfficePartnerRepository partnerRepository;
@Nested @Nested
@Accepts({ "Partner:F(Find)" }) @Accepts({ "Partner:F(Find)" })
@ -48,7 +48,7 @@ class HsAdminPartnerControllerAcceptanceTest {
.header("current-user", "mike@hostsharing.net") .header("current-user", "mike@hostsharing.net")
.port(port) .port(port)
.when() .when()
.get("http://localhost/api/hs/admin/partners") .get("http://localhost/api/hs/office/partners")
.then().assertThat() .then().assertThat()
.statusCode(200) .statusCode(200)
.contentType("application/json") .contentType("application/json")
@ -103,7 +103,7 @@ class HsAdminPartnerControllerAcceptanceTest {
.with("uuid", givenUUID.toString()).toString()) .with("uuid", givenUUID.toString()).toString())
.port(port) .port(port)
.when() .when()
.post("http://localhost/api/hs/admin/partners") .post("http://localhost/api/hs/office/partners")
.then().assertThat() .then().assertThat()
.statusCode(201) .statusCode(201)
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
@ -132,7 +132,7 @@ class HsAdminPartnerControllerAcceptanceTest {
.body(NEW_PARTNER_JSON_WITHOUT_UUID) .body(NEW_PARTNER_JSON_WITHOUT_UUID)
.port(port) .port(port)
.when() .when()
.post("http://localhost/api/hs/admin/partners") .post("http://localhost/api/hs/office/partners")
.then().assertThat() .then().assertThat()
.statusCode(201) .statusCode(201)
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
@ -166,7 +166,7 @@ class HsAdminPartnerControllerAcceptanceTest {
.header("current-user", "mike@hostsharing.net") .header("current-user", "mike@hostsharing.net")
.port(port) .port(port)
.when() .when()
.get("http://localhost/api/hs/admin/partners/" + givenPartnerUuid) .get("http://localhost/api/hs/office/partners/" + givenPartnerUuid)
.then().log().body().assertThat() .then().log().body().assertThat()
.statusCode(200) .statusCode(200)
.contentType("application/json") .contentType("application/json")
@ -186,7 +186,7 @@ class HsAdminPartnerControllerAcceptanceTest {
.header("current-user", "somebody@example.org") .header("current-user", "somebody@example.org")
.port(port) .port(port)
.when() .when()
.get("http://localhost/api/hs/admin/partners/" + givenPartnerUuid) .get("http://localhost/api/hs/office/partners/" + givenPartnerUuid)
.then().log().body().assertThat() .then().log().body().assertThat()
.statusCode(404); .statusCode(404);
// @formatter:on // @formatter:on

View File

@ -1,10 +1,10 @@
package net.hostsharing.hsadminng.hs.admin.partner; package net.hostsharing.hsadminng.hs.office.partner;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.context.ContextBasedTest; import net.hostsharing.hsadminng.context.ContextBasedTest;
import net.hostsharing.hsadminng.hs.admin.contact.HsAdminContactRepository; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository;
import net.hostsharing.hsadminng.hs.admin.person.HsAdminPersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.hs.admin.person.HsAdminPersonRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository; import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository;
import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository; import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository;
import net.hostsharing.test.Array; import net.hostsharing.test.Array;
@ -33,18 +33,18 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assumptions.assumeThat; import static org.assertj.core.api.Assumptions.assumeThat;
@DataJpaTest @DataJpaTest
@ComponentScan(basePackageClasses = { HsAdminPartnerRepository.class, Context.class, JpaAttempt.class }) @ComponentScan(basePackageClasses = { HsOfficePartnerRepository.class, Context.class, JpaAttempt.class })
@DirtiesContext @DirtiesContext
class HsAdminPartnerRepositoryIntegrationTest extends ContextBasedTest { class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTest {
@Autowired @Autowired
HsAdminPartnerRepository partnerRepo; HsOfficePartnerRepository partnerRepo;
@Autowired @Autowired
HsAdminPersonRepository personRepo; HsOfficePersonRepository personRepo;
@Autowired @Autowired
HsAdminContactRepository contactRepo; HsOfficeContactRepository contactRepo;
@Autowired @Autowired
RawRbacRoleRepository rawRoleRepo; RawRbacRoleRepository rawRoleRepo;
@ -61,7 +61,7 @@ class HsAdminPartnerRepositoryIntegrationTest extends ContextBasedTest {
@MockBean @MockBean
HttpServletRequest request; HttpServletRequest request;
Set<HsAdminPartnerEntity> tempPartners = new HashSet<>(); Set<HsOfficePartnerEntity> tempPartners = new HashSet<>();
@Nested @Nested
class CreatePartner { class CreatePartner {
@ -76,7 +76,7 @@ class HsAdminPartnerRepositoryIntegrationTest extends ContextBasedTest {
// when // when
final var result = attempt(em, () -> { final var result = attempt(em, () -> {
final var newPartner = HsAdminPartnerEntity.builder() final var newPartner = HsOfficePartnerEntity.builder()
.uuid(UUID.randomUUID()) .uuid(UUID.randomUUID())
.person(givenPerson) .person(givenPerson)
.contact(givenContact) .contact(givenContact)
@ -86,7 +86,7 @@ class HsAdminPartnerRepositoryIntegrationTest extends ContextBasedTest {
// then // then
result.assertSuccessful(); result.assertSuccessful();
assertThat(result.returnedValue()).isNotNull().extracting(HsAdminPartnerEntity::getUuid).isNotNull(); assertThat(result.returnedValue()).isNotNull().extracting(HsOfficePartnerEntity::getUuid).isNotNull();
assertThatPartnerIsPersisted(result.returnedValue()); assertThatPartnerIsPersisted(result.returnedValue());
assertThat(partnerRepo.count()).isEqualTo(count + 1); assertThat(partnerRepo.count()).isEqualTo(count + 1);
} }
@ -103,7 +103,7 @@ class HsAdminPartnerRepositoryIntegrationTest extends ContextBasedTest {
attempt(em, () -> { attempt(em, () -> {
final var givenPerson = personRepo.findPersonByOptionalNameLike("Erben Bessler").get(0); final var givenPerson = personRepo.findPersonByOptionalNameLike("Erben Bessler").get(0);
final var givenContact = contactRepo.findContactByOptionalLabelLike("forth contact").get(0); final var givenContact = contactRepo.findContactByOptionalLabelLike("forth contact").get(0);
final var newPartner = HsAdminPartnerEntity.builder() final var newPartner = HsOfficePartnerEntity.builder()
.uuid(UUID.randomUUID()) .uuid(UUID.randomUUID())
.person(givenPerson) .person(givenPerson)
.contact(givenContact) .contact(givenContact)
@ -114,24 +114,24 @@ class HsAdminPartnerRepositoryIntegrationTest extends ContextBasedTest {
// then // then
assertThat(roleNamesOf(rawRoleRepo.findAll())).containsExactlyInAnyOrder(Array.from( assertThat(roleNamesOf(rawRoleRepo.findAll())).containsExactlyInAnyOrder(Array.from(
initialRoleNames, initialRoleNames,
"hs_admin_partner#ErbenBesslerMelBessler-forthcontact.admin", "hs_office_partner#ErbenBesslerMelBessler-forthcontact.admin",
"hs_admin_partner#ErbenBesslerMelBessler-forthcontact.owner", "hs_office_partner#ErbenBesslerMelBessler-forthcontact.owner",
"hs_admin_partner#ErbenBesslerMelBessler-forthcontact.tenant")); "hs_office_partner#ErbenBesslerMelBessler-forthcontact.tenant"));
assertThat(grantDisplaysOf(rawGrantRepo.findAll())).containsAll(List.of( assertThat(grantDisplaysOf(rawGrantRepo.findAll())).containsAll(List.of(
"{ grant role hs_admin_partner#ErbenBesslerMelBessler-forthcontact.owner to role global#global.admin by system and assume }", "{ grant role hs_office_partner#ErbenBesslerMelBessler-forthcontact.owner to role global#global.admin by system and assume }",
"{ grant role hs_admin_partner#ErbenBesslerMelBessler-forthcontact.tenant to role hs_admin_contact#forthcontact.admin by system and assume }", "{ grant role hs_office_partner#ErbenBesslerMelBessler-forthcontact.tenant to role hs_office_contact#forthcontact.admin by system and assume }",
"{ grant perm edit on hs_admin_partner#ErbenBesslerMelBessler-forthcontact to role hs_admin_partner#ErbenBesslerMelBessler-forthcontact.admin by system and assume }", "{ grant perm edit on hs_office_partner#ErbenBesslerMelBessler-forthcontact to role hs_office_partner#ErbenBesslerMelBessler-forthcontact.admin by system and assume }",
"{ grant role hs_admin_partner#ErbenBesslerMelBessler-forthcontact.tenant to role hs_admin_partner#ErbenBesslerMelBessler-forthcontact.admin by system and assume }", "{ grant role hs_office_partner#ErbenBesslerMelBessler-forthcontact.tenant to role hs_office_partner#ErbenBesslerMelBessler-forthcontact.admin by system and assume }",
"{ grant perm * on hs_admin_partner#ErbenBesslerMelBessler-forthcontact to role hs_admin_partner#ErbenBesslerMelBessler-forthcontact.owner by system and assume }", "{ grant perm * on hs_office_partner#ErbenBesslerMelBessler-forthcontact to role hs_office_partner#ErbenBesslerMelBessler-forthcontact.owner by system and assume }",
"{ grant role hs_admin_partner#ErbenBesslerMelBessler-forthcontact.admin to role hs_admin_partner#ErbenBesslerMelBessler-forthcontact.owner by system and assume }", "{ grant role hs_office_partner#ErbenBesslerMelBessler-forthcontact.admin to role hs_office_partner#ErbenBesslerMelBessler-forthcontact.owner by system and assume }",
"{ grant perm view on hs_admin_partner#ErbenBesslerMelBessler-forthcontact to role hs_admin_partner#ErbenBesslerMelBessler-forthcontact.tenant by system and assume }", "{ grant perm view on hs_office_partner#ErbenBesslerMelBessler-forthcontact to role hs_office_partner#ErbenBesslerMelBessler-forthcontact.tenant by system and assume }",
"{ grant role hs_admin_contact#forthcontact.tenant to role hs_admin_partner#ErbenBesslerMelBessler-forthcontact.tenant by system and assume }", "{ grant role hs_office_contact#forthcontact.tenant to role hs_office_partner#ErbenBesslerMelBessler-forthcontact.tenant by system and assume }",
"{ grant role hs_admin_person#ErbenBesslerMelBessler.tenant to role hs_admin_partner#ErbenBesslerMelBessler-forthcontact.tenant by system and assume }", "{ grant role hs_office_person#ErbenBesslerMelBessler.tenant to role hs_office_partner#ErbenBesslerMelBessler-forthcontact.tenant by system and assume }",
"{ grant role hs_admin_partner#ErbenBesslerMelBessler-forthcontact.tenant to role hs_admin_person#ErbenBesslerMelBessler.admin by system and assume }")) "{ grant role hs_office_partner#ErbenBesslerMelBessler-forthcontact.tenant to role hs_office_person#ErbenBesslerMelBessler.admin by system and assume }"))
.as("invalid number of grants created").hasSize(initialGrantCount + 10); .as("invalid number of grants created").hasSize(initialGrantCount + 10);
} }
private void assertThatPartnerIsPersisted(final HsAdminPartnerEntity saved) { private void assertThatPartnerIsPersisted(final HsOfficePartnerEntity saved) {
final var found = partnerRepo.findByUuid(saved.getUuid()); final var found = partnerRepo.findByUuid(saved.getUuid());
assertThat(found).isNotEmpty().get().usingRecursiveComparison().isEqualTo(saved); assertThat(found).isNotEmpty().get().usingRecursiveComparison().isEqualTo(saved);
} }
@ -249,7 +249,7 @@ class HsAdminPartnerRepositoryIntegrationTest extends ContextBasedTest {
// then // then
result.assertSuccessful(); result.assertSuccessful();
jpaAttempt.transacted(() -> { jpaAttempt.transacted(() -> {
final var remainingPartner = em.createNativeQuery("select p.uuid from hs_admin_partner p where p.uuid=?1") final var remainingPartner = em.createNativeQuery("select p.uuid from hs_office_partner p where p.uuid=?1")
.setParameter(1, givenPartner.getUuid()).getResultList(); .setParameter(1, givenPartner.getUuid()).getResultList();
assertThat(remainingPartner).isEmpty(); assertThat(remainingPartner).isEmpty();
final var remainingObject = em.createNativeQuery("select o.uuid from RbacObject o where o.uuid=?1") final var remainingObject = em.createNativeQuery("select o.uuid from RbacObject o where o.uuid=?1")
@ -261,21 +261,21 @@ class HsAdminPartnerRepositoryIntegrationTest extends ContextBasedTest {
context("customer-admin@forthcontact.example.com"); context("customer-admin@forthcontact.example.com");
assertThat(grantDisplaysOf(rawGrantRepo.findAll())).doesNotContain( assertThat(grantDisplaysOf(rawGrantRepo.findAll())).doesNotContain(
"{ grant assumed role hs_admin_contact#forthcontact.owner to user customer-admin@forthcontact.example.com by role global#global.admin }"); "{ grant assumed role hs_office_contact#forthcontact.owner to user customer-admin@forthcontact.example.com by role global#global.admin }");
context("person-ErbenBesslerMelBessler@example.com"); context("person-ErbenBesslerMelBessler@example.com");
assertThat(grantDisplaysOf(rawGrantRepo.findAll())).doesNotContain( assertThat(grantDisplaysOf(rawGrantRepo.findAll())).doesNotContain(
"{ grant assumed role hs_admin_person#ErbenBesslerMelBessler.owner to user person-ErbenBesslerMelBessl@example.com by role global#global.admin }"); "{ grant assumed role hs_office_person#ErbenBesslerMelBessler.owner to user person-ErbenBesslerMelBessl@example.com by role global#global.admin }");
}).assertSuccessful(); }).assertSuccessful();
} }
} }
private HsAdminPartnerEntity givenSomeTemporaryPartnerBessler() { private HsOfficePartnerEntity givenSomeTemporaryPartnerBessler() {
return jpaAttempt.transacted(() -> { return jpaAttempt.transacted(() -> {
context("alex@hostsharing.net"); context("alex@hostsharing.net");
final var givenPerson = personRepo.findPersonByOptionalNameLike("Erben Bessler").get(0); final var givenPerson = personRepo.findPersonByOptionalNameLike("Erben Bessler").get(0);
final var givenContact = contactRepo.findContactByOptionalLabelLike("forth contact").get(0); final var givenContact = contactRepo.findContactByOptionalLabelLike("forth contact").get(0);
final var newPartner = HsAdminPartnerEntity.builder() final var newPartner = HsOfficePartnerEntity.builder()
.uuid(UUID.randomUUID()) .uuid(UUID.randomUUID())
.person(givenPerson) .person(givenPerson)
.contact(givenContact) .contact(givenContact)
@ -285,7 +285,7 @@ class HsAdminPartnerRepositoryIntegrationTest extends ContextBasedTest {
}).assertSuccessful().returnedValue(); }).assertSuccessful().returnedValue();
} }
private HsAdminPartnerEntity toCleanup(final HsAdminPartnerEntity tempPartner) { private HsOfficePartnerEntity toCleanup(final HsOfficePartnerEntity tempPartner) {
tempPartners.add(tempPartner); tempPartners.add(tempPartner);
return tempPartner; return tempPartner;
} }
@ -300,18 +300,18 @@ class HsAdminPartnerRepositoryIntegrationTest extends ContextBasedTest {
}); });
} }
void exactlyThesePartnersAreReturned(final List<HsAdminPartnerEntity> actualResult, final String... partnerTradeNames) { void exactlyThesePartnersAreReturned(final List<HsOfficePartnerEntity> actualResult, final String... partnerTradeNames) {
assertThat(actualResult) assertThat(actualResult)
.hasSize(partnerTradeNames.length) .hasSize(partnerTradeNames.length)
.extracting(HsAdminPartnerEntity::getPerson) .extracting(HsOfficePartnerEntity::getPerson)
.extracting(HsAdminPersonEntity::getTradeName) .extracting(HsOfficePersonEntity::getTradeName)
.containsExactlyInAnyOrder(partnerTradeNames); .containsExactlyInAnyOrder(partnerTradeNames);
} }
void allThesePartnersAreReturned(final List<HsAdminPartnerEntity> actualResult, final String... partnerTradeNames) { void allThesePartnersAreReturned(final List<HsOfficePartnerEntity> actualResult, final String... partnerTradeNames) {
assertThat(actualResult) assertThat(actualResult)
.extracting(HsAdminPartnerEntity::getPerson) .extracting(HsOfficePartnerEntity::getPerson)
.extracting(HsAdminPersonEntity::getTradeName) .extracting(HsOfficePersonEntity::getTradeName)
.contains(partnerTradeNames); .contains(partnerTradeNames);
} }
} }

View File

@ -0,0 +1,26 @@
package net.hostsharing.hsadminng.hs.office.partner;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import java.util.UUID;
import static net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType.LEGAL;
public class TestHsOfficePartner {
public static final HsOfficePartnerEntity testLtd = HsOfficePartnerWithLegalPerson("Test Ltd.");
static public HsOfficePartnerEntity HsOfficePartnerWithLegalPerson(final String tradeName) {
return HsOfficePartnerEntity.builder()
.uuid(UUID.randomUUID())
.person(HsOfficePersonEntity.builder()
.personType(LEGAL)
.tradeName(tradeName)
.build())
.contact(HsOfficeContactEntity.builder()
.label(tradeName)
.build())
.build();
}
}

View File

@ -1,14 +1,14 @@
package net.hostsharing.hsadminng.hs.admin.person; package net.hostsharing.hsadminng.hs.office.person;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
class HsAdminPersonEntityUnitTest { class HsOfficePersonEntityUnitTest {
@Test @Test
void getDisplayReturnsTradeNameIfAvailable() { void getDisplayReturnsTradeNameIfAvailable() {
final var givenPersonEntity = HsAdminPersonEntity.builder() final var givenPersonEntity = HsOfficePersonEntity.builder()
.tradeName("some trade name") .tradeName("some trade name")
.build(); .build();
@ -19,7 +19,7 @@ class HsAdminPersonEntityUnitTest {
@Test @Test
void getDisplayReturnsFamilyAndGivenNameIfNoTradeNameAvailable() { void getDisplayReturnsFamilyAndGivenNameIfNoTradeNameAvailable() {
final var givenPersonEntity = HsAdminPersonEntity.builder() final var givenPersonEntity = HsOfficePersonEntity.builder()
.familyName("some family name") .familyName("some family name")
.givenName("some given name") .givenName("some given name")
.build(); .build();

View File

@ -1,4 +1,4 @@
package net.hostsharing.hsadminng.hs.admin.person; package net.hostsharing.hsadminng.hs.office.person;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.context.ContextBasedTest; import net.hostsharing.hsadminng.context.ContextBasedTest;
@ -21,7 +21,7 @@ import javax.servlet.http.HttpServletRequest;
import java.util.List; import java.util.List;
import java.util.function.Supplier; import java.util.function.Supplier;
import static net.hostsharing.hsadminng.hs.admin.person.TestHsAdminPerson.hsAdminPerson; import static net.hostsharing.hsadminng.hs.office.person.TestHsOfficePerson.hsOfficePerson;
import static net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantDisplayExtractor.grantDisplaysOf; import static net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantDisplayExtractor.grantDisplaysOf;
import static net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleNameExtractor.roleNamesOf; import static net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleNameExtractor.roleNamesOf;
import static net.hostsharing.test.JpaAttempt.attempt; import static net.hostsharing.test.JpaAttempt.attempt;
@ -29,12 +29,12 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assumptions.assumeThat; import static org.assertj.core.api.Assumptions.assumeThat;
@DataJpaTest @DataJpaTest
@ComponentScan(basePackageClasses = { HsAdminPersonRepository.class, Context.class, JpaAttempt.class }) @ComponentScan(basePackageClasses = { HsOfficePersonRepository.class, Context.class, JpaAttempt.class })
@DirtiesContext @DirtiesContext
class HsAdminPersonRepositoryIntegrationTest extends ContextBasedTest { class HsOfficePersonRepositoryIntegrationTest extends ContextBasedTest {
@Autowired @Autowired
HsAdminPersonRepository personRepo; HsOfficePersonRepository personRepo;
@Autowired @Autowired
RawRbacRoleRepository rawRoleRepo; RawRbacRoleRepository rawRoleRepo;
@ -63,11 +63,11 @@ class HsAdminPersonRepositoryIntegrationTest extends ContextBasedTest {
// when // when
final var result = attempt(em, () -> personRepo.save( final var result = attempt(em, () -> personRepo.save(
hsAdminPerson("a new person"))); hsOfficePerson("a new person")));
// then // then
result.assertSuccessful(); result.assertSuccessful();
assertThat(result.returnedValue()).isNotNull().extracting(HsAdminPersonEntity::getUuid).isNotNull(); assertThat(result.returnedValue()).isNotNull().extracting(HsOfficePersonEntity::getUuid).isNotNull();
assertThatPersonIsPersisted(result.returnedValue()); assertThatPersonIsPersisted(result.returnedValue());
assertThat(personRepo.count()).isEqualTo(count + 1); assertThat(personRepo.count()).isEqualTo(count + 1);
} }
@ -80,11 +80,11 @@ class HsAdminPersonRepositoryIntegrationTest extends ContextBasedTest {
// when // when
final var result = attempt(em, () -> personRepo.save( final var result = attempt(em, () -> personRepo.save(
hsAdminPerson("another new person"))); hsOfficePerson("another new person")));
// then // then
result.assertSuccessful(); result.assertSuccessful();
assertThat(result.returnedValue()).isNotNull().extracting(HsAdminPersonEntity::getUuid).isNotNull(); assertThat(result.returnedValue()).isNotNull().extracting(HsOfficePersonEntity::getUuid).isNotNull();
assertThatPersonIsPersisted(result.returnedValue()); assertThatPersonIsPersisted(result.returnedValue());
assertThat(personRepo.count()).isEqualTo(count + 1); assertThat(personRepo.count()).isEqualTo(count + 1);
} }
@ -99,31 +99,31 @@ class HsAdminPersonRepositoryIntegrationTest extends ContextBasedTest {
// when // when
attempt(em, () -> personRepo.save( attempt(em, () -> personRepo.save(
hsAdminPerson("another new person")) hsOfficePerson("another new person"))
).assumeSuccessful(); ).assumeSuccessful();
// then // then
assertThat(roleNamesOf(rawRoleRepo.findAll())).containsExactlyInAnyOrder( assertThat(roleNamesOf(rawRoleRepo.findAll())).containsExactlyInAnyOrder(
Array.from( Array.from(
initialRoleNames, initialRoleNames,
"hs_admin_person#anothernewperson.owner", "hs_office_person#anothernewperson.owner",
"hs_admin_person#anothernewperson.admin", "hs_office_person#anothernewperson.admin",
"hs_admin_person#anothernewperson.tenant" "hs_office_person#anothernewperson.tenant"
)); ));
assertThat(grantDisplaysOf(rawGrantRepo.findAll())).containsExactlyInAnyOrder( assertThat(grantDisplaysOf(rawGrantRepo.findAll())).containsExactlyInAnyOrder(
Array.from( Array.from(
initialGrantNames, initialGrantNames,
"{ grant role hs_admin_person#anothernewperson.owner to role global#global.admin by system and assume }", "{ grant role hs_office_person#anothernewperson.owner to role global#global.admin by system and assume }",
"{ grant perm edit on hs_admin_person#anothernewperson to role hs_admin_person#anothernewperson.admin by system and assume }", "{ grant perm edit on hs_office_person#anothernewperson to role hs_office_person#anothernewperson.admin by system and assume }",
"{ grant role hs_admin_person#anothernewperson.tenant to role hs_admin_person#anothernewperson.admin by system and assume }", "{ grant role hs_office_person#anothernewperson.tenant to role hs_office_person#anothernewperson.admin by system and assume }",
"{ grant perm * on hs_admin_person#anothernewperson to role hs_admin_person#anothernewperson.owner by system and assume }", "{ grant perm * on hs_office_person#anothernewperson to role hs_office_person#anothernewperson.owner by system and assume }",
"{ grant role hs_admin_person#anothernewperson.admin to role hs_admin_person#anothernewperson.owner by system and assume }", "{ grant role hs_office_person#anothernewperson.admin to role hs_office_person#anothernewperson.owner by system and assume }",
"{ grant perm view on hs_admin_person#anothernewperson to role hs_admin_person#anothernewperson.tenant by system and assume }", "{ grant perm view on hs_office_person#anothernewperson to role hs_office_person#anothernewperson.tenant by system and assume }",
"{ grant role hs_admin_person#anothernewperson.owner to user drew@hostsharing.org by global#global.admin and assume }" "{ grant role hs_office_person#anothernewperson.owner to user drew@hostsharing.org by global#global.admin and assume }"
)); ));
} }
private void assertThatPersonIsPersisted(final HsAdminPersonEntity saved) { private void assertThatPersonIsPersisted(final HsOfficePersonEntity saved) {
final var found = personRepo.findByUuid(saved.getUuid()); final var found = personRepo.findByUuid(saved.getUuid());
assertThat(found).isNotEmpty().get().usingRecursiveComparison().isEqualTo(saved); assertThat(found).isNotEmpty().get().usingRecursiveComparison().isEqualTo(saved);
} }
@ -271,29 +271,29 @@ class HsAdminPersonRepositoryIntegrationTest extends ContextBasedTest {
}); });
} }
private HsAdminPersonEntity givenSomeTemporaryPerson( private HsOfficePersonEntity givenSomeTemporaryPerson(
final String createdByUser, final String createdByUser,
Supplier<HsAdminPersonEntity> entitySupplier) { Supplier<HsOfficePersonEntity> entitySupplier) {
return jpaAttempt.transacted(() -> { return jpaAttempt.transacted(() -> {
context(createdByUser); context(createdByUser);
return personRepo.save(entitySupplier.get()); return personRepo.save(entitySupplier.get());
}).assumeSuccessful().returnedValue(); }).assumeSuccessful().returnedValue();
} }
private HsAdminPersonEntity givenSomeTemporaryPerson(final String createdByUser) { private HsOfficePersonEntity givenSomeTemporaryPerson(final String createdByUser) {
return givenSomeTemporaryPerson(createdByUser, () -> return givenSomeTemporaryPerson(createdByUser, () ->
hsAdminPerson("some temporary person #" + RandomString.make(12))); hsOfficePerson("some temporary person #" + RandomString.make(12)));
} }
void exactlyThesePersonsAreReturned(final List<HsAdminPersonEntity> actualResult, final String... personLabels) { void exactlyThesePersonsAreReturned(final List<HsOfficePersonEntity> actualResult, final String... personLabels) {
assertThat(actualResult) assertThat(actualResult)
.extracting(HsAdminPersonEntity::getTradeName) .extracting(HsOfficePersonEntity::getTradeName)
.containsExactlyInAnyOrder(personLabels); .containsExactlyInAnyOrder(personLabels);
} }
void allThesePersonsAreReturned(final List<HsAdminPersonEntity> actualResult, final String... personLabels) { void allThesePersonsAreReturned(final List<HsOfficePersonEntity> actualResult, final String... personLabels) {
assertThat(actualResult) assertThat(actualResult)
.extracting(HsAdminPersonEntity::getDisplayName) .extracting(HsOfficePersonEntity::getDisplayName)
.contains(personLabels); .contains(personLabels);
} }
} }

View File

@ -0,0 +1,16 @@
package net.hostsharing.hsadminng.hs.office.person;
import java.util.UUID;
public class TestHsOfficePerson {
public static final HsOfficePersonEntity somePerson = hsOfficePerson("some person");
static public HsOfficePersonEntity hsOfficePerson(final String tradeName) {
return HsOfficePersonEntity.builder()
.uuid(UUID.randomUUID())
.personType(HsOfficePersonType.NATURAL)
.tradeName(tradeName)
.build();
}
}

View File

@ -1,47 +1,47 @@
#!/bin/bash #!/bin/bash
mkdir -p src/test/java/net/hostsharing/hsadminng/hs/admin/partner mkdir -p src/test/java/net/hostsharing/hsadminng/hs/office/partner
sed -e 's/hs-admin-contact/hs-admin-partner/g' \ sed -e 's/hs-admin-contact/hs-office-partner/g' \
-e 's/hs_admin_contact/hs_admin_partner/g' \ -e 's/hs_admin_contact/hs_office_partner/g' \
-e 's/HsAdminContact/HsAdminPartner/g' \ -e 's/HsOfficeContact/HsOfficePartner/g' \
-e 's/hsAdminContact/hsAdminPartner/g' \ -e 's/HsOfficeContact/HsOfficePartner/g' \
-e 's/contact/partner/g' \ -e 's/contact/partner/g' \
<src/test/java/net/hostsharing/hsadminng/hs/admin/contact/HsAdminContactRepositoryIntegrationTest.java \ <src/test/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRepositoryIntegrationTest.java \
>src/test/java/net/hostsharing/hsadminng/hs/admin/partner/HsAdminPartnerRepositoryIntegrationTest.java >src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepositoryIntegrationTest.java
exit exit
sed -e 's/hs-admin-contact/hs-admin-partner/g' \ sed -e 's/hs-admin-contact/hs-office-partner/g' \
-e 's/hs_admin_contact/hs_admin_partner/g' \ -e 's/hs_admin_contact/hs_office_partner/g' \
<src/main/resources/db/changelog/200-hs-admin-contact.sql >src/main/resources/db/changelog/220-hs-admin-partner.sql <src/main/resources/db/changelog/200-hs-admin-contact.sql >src/main/resources/db/changelog/220-hs-office-partner.sql
sed -e 's/hs-admin-contact/hs-admin-partner/g' \ sed -e 's/hs-admin-contact/hs-office-partner/g' \
-e 's/hs_admin_contact/hs_admin_partner/g' \ -e 's/hs_admin_contact/hs_office_partner/g' \
-e 's/HsAdminCustomer/HsAdminPartner/g' \ -e 's/HsAdminCustomer/HsOfficePartner/g' \
-e 's/hsAdminContact/hsAdminPartner/g' \ -e 's/HsOfficeContact/HsOfficePartner/g' \
-e 's/contact/partner/g' \ -e 's/contact/partner/g' \
<src/main/resources/db/changelog/203-hs-admin-contact-rbac.sql >src/main/resources/db/changelog/223-hs-admin-partner-rbac.sql <src/main/resources/db/changelog/203-hs-admin-contact-rbac.sql >src/main/resources/db/changelog/223-hs-office-partner-rbac.sql
sed -e 's/hs-admin-contact/hs-admin-partner/g' \ sed -e 's/hs-admin-contact/hs-office-partner/g' \
-e 's/hs_admin_contact/hs_admin_partner/g' \ -e 's/hs_admin_contact/hs_office_partner/g' \
-e 's/HsAdminContact/HsAdminPartner/g' \ -e 's/HsOfficeContact/HsOfficePartner/g' \
-e 's/hsAdminContact/hsAdminPartner/g' \ -e 's/HsOfficeContact/HsOfficePartner/g' \
-e 's/contact/partner/g' \ -e 's/contact/partner/g' \
<src/main/resources/db/changelog/208-hs-admin-contact-test-data.sql >src/main/resources/db/changelog/228-hs-admin-partner-test-data.sql <src/main/resources/db/changelog/208-hs-admin-contact-test-data.sql >src/main/resources/db/changelog/228-hs-office-partner-test-data.sql
# mkdir -p src/main/java/net/hostsharing/hsadminng/hs/admin/partner # mkdir -p src/main/java/net/hostsharing/hsadminng/hs/office/partner
# #
# sed -e 's/HsAdminContactEntity/HsAdminPartnerEntity/g' \ # sed -e 's/HsOfficeContactEntity/HsOfficePartnerEntity/g' \
# sed -e 's/admin.contact/admin.partner/g' \ # sed -e 's/admin.contact/admin.partner/g' \
# <src/main/java/net/hostsharing/hsadminng/hs/admin/contact/HsAdminContactEntity.java >src/main/java/net/hostsharing/hsadminng/hs/admin/partner/HsAdminPartnerEntity.java # <src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactEntity.java >src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerEntity.java
cat >>src/main/resources/db/changelog/db.changelog-master.yaml <<EOF cat >>src/main/resources/db/changelog/db.changelog-master.yaml <<EOF
- include: - include:
file: db/changelog/220-hs-admin-partner.sql file: db/changelog/220-hs-office-partner.sql
- include: - include:
file: db/changelog/223-hs-admin-partner-rbac.sql file: db/changelog/223-hs-office-partner-rbac.sql
- include: - include:
file: db/changelog/228-hs-admin-partner-test-data.sql file: db/changelog/228-hs-office-partner-test-data.sql
EOF EOF