hs.admin.partner from API via Controller to Entity
This commit is contained in:
16
src/main/resources/api-definition/hs-admin/api-mappings.yaml
Normal file
16
src/main/resources/api-definition/hs-admin/api-mappings.yaml
Normal file
@ -0,0 +1,16 @@
|
||||
openapi-processor-mapping: v2
|
||||
|
||||
options:
|
||||
package-name: net.hostsharing.hsadminng.hs.admin.generated.api.v1
|
||||
model-name-suffix: Resource
|
||||
|
||||
map:
|
||||
result: org.springframework.http.ResponseEntity
|
||||
|
||||
types:
|
||||
- type: array => java.util.List
|
||||
- type: string:uuid => java.util.UUID
|
||||
|
||||
paths:
|
||||
/api/hs/admin/partners/{packageUUID}:
|
||||
null: org.openapitools.jackson.nullable.JsonNullable
|
1
src/main/resources/api-definition/hs-admin/auth.yaml
Symbolic link
1
src/main/resources/api-definition/hs-admin/auth.yaml
Symbolic link
@ -0,0 +1 @@
|
||||
../auth.yaml
|
1
src/main/resources/api-definition/hs-admin/error-responses.yaml
Symbolic link
1
src/main/resources/api-definition/hs-admin/error-responses.yaml
Symbolic link
@ -0,0 +1 @@
|
||||
../error-responses.yaml
|
@ -0,0 +1,28 @@
|
||||
|
||||
components:
|
||||
|
||||
schemas:
|
||||
|
||||
HsAdminContactBase:
|
||||
type: object
|
||||
properties:
|
||||
label:
|
||||
type: string
|
||||
postalAddress:
|
||||
type: string
|
||||
emailAddresses:
|
||||
type: string
|
||||
phoneNumbers:
|
||||
type: string
|
||||
|
||||
HsAdminContact:
|
||||
allOf:
|
||||
- type: object
|
||||
properties:
|
||||
uuid:
|
||||
type: string
|
||||
format: uuid
|
||||
- $ref: '#/components/schemas/HsAdminContactBase'
|
||||
|
||||
HsAdminContactUpdate:
|
||||
$ref: '#/components/schemas/HsAdminContactBase'
|
@ -0,0 +1,45 @@
|
||||
|
||||
components:
|
||||
|
||||
schemas:
|
||||
|
||||
HsAdminPartnerBase:
|
||||
type: object
|
||||
properties:
|
||||
registrationOffice:
|
||||
type: string
|
||||
registrationNumber:
|
||||
type: string
|
||||
birthName:
|
||||
type: string
|
||||
birthday:
|
||||
type: string
|
||||
format: date
|
||||
dateOfDeath:
|
||||
type: string
|
||||
format: date
|
||||
|
||||
HsAdminPartner:
|
||||
allOf:
|
||||
- type: object
|
||||
properties:
|
||||
uuid:
|
||||
type: string
|
||||
format: uuid
|
||||
person:
|
||||
$ref: './hs-admin-person-schemas.yaml#/components/schemas/HsAdminPerson'
|
||||
contact:
|
||||
$ref: './hs-admin-contact-schemas.yaml#/components/schemas/HsAdminContact'
|
||||
- $ref: '#/components/schemas/HsAdminPartnerBase'
|
||||
|
||||
HsAdminPartnerUpdate:
|
||||
allOf:
|
||||
- type: object
|
||||
properties:
|
||||
personUuid:
|
||||
type: string
|
||||
format: uuid
|
||||
contactUuid:
|
||||
type: string
|
||||
format: uuid
|
||||
- $ref: '#/components/schemas/HsAdminPartnerBase'
|
@ -0,0 +1,81 @@
|
||||
get:
|
||||
tags:
|
||||
- hs-admin-partners
|
||||
description: 'Fetch a single business partner by its uuid, if visible for the current subject.'
|
||||
operationId: getPartnerByUuid
|
||||
parameters:
|
||||
- $ref: './auth.yaml#/components/parameters/currentUser'
|
||||
- $ref: './auth.yaml#/components/parameters/assumedRoles'
|
||||
- name: partnerUUID
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
format: uuid
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: './hs-admin-partner-schemas.yaml#/components/schemas/HsAdminPartner'
|
||||
|
||||
"401":
|
||||
$ref: './error-responses.yaml#/components/responses/Unauthorized'
|
||||
"403":
|
||||
$ref: './error-responses.yaml#/components/responses/Forbidden'
|
||||
|
||||
patch:
|
||||
tags:
|
||||
- hs-admin-partners
|
||||
operationId: updatePartner
|
||||
parameters:
|
||||
- $ref: './auth.yaml#/components/parameters/currentUser'
|
||||
- $ref: './auth.yaml#/components/parameters/assumedRoles'
|
||||
- name: partnerUUID
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
format: uuid
|
||||
requestBody:
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: './hs-admin-partner-schemas.yaml#/components/schemas/HsAdminPartnerUpdate'
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: './hs-admin-partner-schemas.yaml#/components/schemas/HsAdminPartner'
|
||||
"401":
|
||||
$ref: './error-responses.yaml#/components/responses/Unauthorized'
|
||||
"403":
|
||||
$ref: './error-responses.yaml#/components/responses/Forbidden'
|
||||
|
||||
|
||||
delete:
|
||||
tags:
|
||||
- hs-admin-partners
|
||||
operationId: deletePartnerByUuid
|
||||
parameters:
|
||||
- $ref: './auth.yaml#/components/parameters/currentUser'
|
||||
- $ref: './auth.yaml#/components/parameters/assumedRoles'
|
||||
- name: userUuid
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
format: uuid
|
||||
description: UUID of the user to delete.
|
||||
responses:
|
||||
"204":
|
||||
description: No Content
|
||||
"401":
|
||||
$ref: './error-responses.yaml#/components/responses/Unauthorized'
|
||||
"403":
|
||||
$ref: './error-responses.yaml#/components/responses/Forbidden'
|
||||
"404":
|
||||
$ref: './error-responses.yaml#/components/responses/NotFound'
|
@ -0,0 +1,56 @@
|
||||
get:
|
||||
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.
|
||||
tags:
|
||||
- hs-admin-partners
|
||||
operationId: listPartners
|
||||
parameters:
|
||||
- $ref: './auth.yaml#/components/parameters/currentUser'
|
||||
- $ref: './auth.yaml#/components/parameters/assumedRoles'
|
||||
- name: name
|
||||
in: query
|
||||
required: false
|
||||
schema:
|
||||
type: string
|
||||
description: Customer-prefix to filter the results. TODO
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: './hs-admin-partner-schemas.yaml#/components/schemas/HsAdminPartner'
|
||||
"401":
|
||||
$ref: './error-responses.yaml#/components/responses/Unauthorized'
|
||||
"403":
|
||||
$ref: './error-responses.yaml#/components/responses/Forbidden'
|
||||
|
||||
post:
|
||||
summary: Adds a new business partner.
|
||||
tags:
|
||||
- hs-admin-partners
|
||||
operationId: addPartner
|
||||
parameters:
|
||||
- $ref: './auth.yaml#/components/parameters/currentUser'
|
||||
- $ref: './auth.yaml#/components/parameters/assumedRoles'
|
||||
requestBody:
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: './hs-admin-partner-schemas.yaml#/components/schemas/HsAdminPartner'
|
||||
required: true
|
||||
responses:
|
||||
"201":
|
||||
description: Created
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: './hs-admin-partner-schemas.yaml#/components/schemas/HsAdminPartner'
|
||||
"401":
|
||||
$ref: './error-responses.yaml#/components/responses/Unauthorized'
|
||||
"403":
|
||||
$ref: './error-responses.yaml#/components/responses/Forbidden'
|
||||
"409":
|
||||
$ref: './error-responses.yaml#/components/responses/Conflict'
|
@ -0,0 +1,33 @@
|
||||
|
||||
components:
|
||||
|
||||
schemas:
|
||||
|
||||
HsAdminPersonBase:
|
||||
type: object
|
||||
properties:
|
||||
personType:
|
||||
type: string
|
||||
enum:
|
||||
- NATURAL # a human
|
||||
- LEGAL # e.g. Corp., Inc., AG, GmbH, eG
|
||||
- SOLE_REPRESENTATION # e.g. OHG, GbR
|
||||
- JOINT_REPRESENTATION # e.g. community of heirs
|
||||
tradeName:
|
||||
type: string
|
||||
givenName:
|
||||
type: string
|
||||
familyName:
|
||||
type: string
|
||||
|
||||
HsAdminPerson:
|
||||
allOf:
|
||||
- type: object
|
||||
properties:
|
||||
uuid:
|
||||
type: string
|
||||
format: uuid
|
||||
- $ref: '#/components/schemas/HsAdminPersonBase'
|
||||
|
||||
HsAdminPersonUpdate:
|
||||
$ref: '#/components/schemas/HsAdminPersonBase'
|
16
src/main/resources/api-definition/hs-admin/hs-admin.yaml
Normal file
16
src/main/resources/api-definition/hs-admin/hs-admin.yaml
Normal file
@ -0,0 +1,16 @@
|
||||
openapi: 3.0.1
|
||||
info:
|
||||
title: Hostsharing hsadmin-ng API
|
||||
version: v0
|
||||
servers:
|
||||
- url: http://localhost:8080
|
||||
description: Local development default URL.
|
||||
|
||||
paths:
|
||||
|
||||
/api/hs/admin/partners:
|
||||
$ref: "./hs-admin-partners.yaml"
|
||||
|
||||
/api/hs/admin/partners/{partnerUUID}:
|
||||
$ref: "./hs-admin-partners-with-uuid.yaml"
|
||||
|
83
src/main/resources/db/changelog/200-hs-base.sql
Normal file
83
src/main/resources/db/changelog/200-hs-base.sql
Normal file
@ -0,0 +1,83 @@
|
||||
--liquibase formatted sql
|
||||
|
||||
-- ============================================================================
|
||||
--changeset hs-base-GLOBAL-OBJECT:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
A single row to be referenced as a global object.
|
||||
*/
|
||||
begin transaction;
|
||||
call defineContext('initializing table "global"', null, null, null);
|
||||
insert
|
||||
into RbacObject (objecttable) values ('global');
|
||||
insert
|
||||
into Global (uuid, name) values ((select uuid from RbacObject where objectTable = 'global'), 'hostsharing');
|
||||
commit;
|
||||
--//
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset hs-base-ADMIN-ROLE:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
/*
|
||||
A global administrator role.
|
||||
*/
|
||||
create or replace function hsHostsharingAdmin()
|
||||
returns RbacRoleDescriptor
|
||||
returns null on null input
|
||||
stable leakproof
|
||||
language sql as $$
|
||||
select 'global', (select uuid from RbacObject where objectTable = 'global'), 'admin'::RbacRoleType;
|
||||
$$;
|
||||
|
||||
begin transaction;
|
||||
call defineContext('creating Hostsharing admin role', null, null, null);
|
||||
select createRole(hsHostsharingAdmin());
|
||||
commit;
|
||||
|
||||
-- ============================================================================
|
||||
--changeset hs-base-ADMIN-USERS:1 context:dev,tc endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
/*
|
||||
Create two users and assign both to the administrators role.
|
||||
*/
|
||||
do language plpgsql $$
|
||||
declare
|
||||
admins uuid ;
|
||||
begin
|
||||
call defineContext('creating fake Hostsharing admin users', null, null, null);
|
||||
|
||||
admins = findRoleId(hsHostsharingAdmin());
|
||||
call grantRoleToUserUnchecked(admins, admins, createRbacUser('mike@hostsharing.net'));
|
||||
call grantRoleToUserUnchecked(admins, admins, createRbacUser('sven@hostsharing.net'));
|
||||
end;
|
||||
$$;
|
||||
--//
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset hs-base-hostsharing-TEST:1 context:dev,tc runAlways:true endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
Tests if currentUserUuid() can fetch the user from the session variable.
|
||||
*/
|
||||
|
||||
do language plpgsql $$
|
||||
declare
|
||||
userName varchar;
|
||||
begin
|
||||
call defineContext('testing currentUserUuid', null, 'sven@hostsharing.net', null);
|
||||
select userName from RbacUser where uuid = currentUserUuid() into userName;
|
||||
if userName <> 'sven@hostsharing.net' then
|
||||
raise exception 'setting or fetching initial currentUser failed, got: %', userName;
|
||||
end if;
|
||||
|
||||
call defineContext('testing currentUserUuid', null, 'mike@hostsharing.net', null);
|
||||
select userName from RbacUser where uuid = currentUserUuid() into userName;
|
||||
if userName = 'mike@ehostsharing.net' then
|
||||
raise exception 'currentUser should not change in one transaction, but did change, got: %', userName;
|
||||
end if;
|
||||
end; $$;
|
||||
--//
|
Reference in New Issue
Block a user