2022-10-18 17:29:36 +02:00
|
|
|
--liquibase formatted sql
|
2024-04-02 11:04:56 +02:00
|
|
|
-- This code generated was by RbacViewPostgresGenerator, do not amend manually.
|
|
|
|
|
2022-10-18 17:29:36 +02:00
|
|
|
|
|
|
|
-- ============================================================================
|
2024-09-16 15:36:37 +02:00
|
|
|
--changeset RbacObjectGenerator:hs-office-coopsharestransaction-rbac-OBJECT endDelimiter:--//
|
2022-10-18 17:29:36 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
2024-09-16 15:36:37 +02:00
|
|
|
call rbac.generateRelatedRbacObject('hs_office_coopsharestransaction');
|
2022-10-18 17:29:36 +02:00
|
|
|
--//
|
|
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
2024-09-16 15:36:37 +02:00
|
|
|
--changeset RbacRoleDescriptorsGenerator:hs-office-coopsharestransaction-rbac-ROLE-DESCRIPTORS endDelimiter:--//
|
2022-10-18 17:29:36 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
2024-09-16 15:36:37 +02:00
|
|
|
call rbac.generateRbacRoleDescriptors('hsOfficeCoopSharesTransaction', 'hs_office_coopsharestransaction');
|
2022-10-18 17:29:36 +02:00
|
|
|
--//
|
|
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
2024-09-16 15:36:37 +02:00
|
|
|
--changeset RolesGrantsAndPermissionsGenerator:hs-office-coopsharestransaction-rbac-insert-trigger endDelimiter:--//
|
2022-10-18 17:29:36 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/*
|
2024-04-02 11:04:56 +02:00
|
|
|
Creates the roles, grants and permission for the AFTER INSERT TRIGGER.
|
2022-10-18 17:29:36 +02:00
|
|
|
*/
|
|
|
|
|
2024-04-02 11:04:56 +02:00
|
|
|
create or replace procedure buildRbacSystemForHsOfficeCoopSharesTransaction(
|
|
|
|
NEW hs_office_coopsharestransaction
|
|
|
|
)
|
|
|
|
language plpgsql as $$
|
|
|
|
|
2022-10-18 17:29:36 +02:00
|
|
|
declare
|
2024-04-02 11:04:56 +02:00
|
|
|
newMembership hs_office_membership;
|
|
|
|
|
2022-10-18 17:29:36 +02:00
|
|
|
begin
|
2024-09-16 15:36:37 +02:00
|
|
|
call rbac.enterTriggerForObjectUuid(NEW.uuid);
|
2022-10-18 17:29:36 +02:00
|
|
|
|
2024-04-02 11:04:56 +02:00
|
|
|
SELECT * FROM hs_office_membership WHERE uuid = NEW.membershipUuid INTO newMembership;
|
|
|
|
assert newMembership.uuid is not null, format('newMembership must not be null for NEW.membershipUuid = %s', NEW.membershipUuid);
|
2022-10-18 17:29:36 +02:00
|
|
|
|
2024-09-16 15:36:37 +02:00
|
|
|
call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'SELECT'), hsOfficeMembershipAGENT(newMembership));
|
|
|
|
call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'UPDATE'), hsOfficeMembershipADMIN(newMembership));
|
2022-10-18 17:29:36 +02:00
|
|
|
|
2024-09-16 15:36:37 +02:00
|
|
|
call rbac.leaveTriggerForObjectUuid(NEW.uuid);
|
2022-10-18 17:29:36 +02:00
|
|
|
end; $$;
|
|
|
|
|
|
|
|
/*
|
2024-04-02 11:04:56 +02:00
|
|
|
AFTER INSERT TRIGGER to create the role+grant structure for a new hs_office_coopsharestransaction row.
|
2022-10-18 17:29:36 +02:00
|
|
|
*/
|
|
|
|
|
2024-04-02 11:04:56 +02:00
|
|
|
create or replace function insertTriggerForHsOfficeCoopSharesTransaction_tf()
|
|
|
|
returns trigger
|
|
|
|
language plpgsql
|
|
|
|
strict as $$
|
|
|
|
begin
|
|
|
|
call buildRbacSystemForHsOfficeCoopSharesTransaction(NEW);
|
|
|
|
return NEW;
|
|
|
|
end; $$;
|
2022-10-18 17:29:36 +02:00
|
|
|
|
2024-04-02 11:04:56 +02:00
|
|
|
create trigger insertTriggerForHsOfficeCoopSharesTransaction_tg
|
|
|
|
after insert on hs_office_coopsharestransaction
|
|
|
|
for each row
|
|
|
|
execute procedure insertTriggerForHsOfficeCoopSharesTransaction_tf();
|
2022-10-18 17:29:36 +02:00
|
|
|
--//
|
|
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
2024-09-16 15:36:37 +02:00
|
|
|
--changeset InsertTriggerGenerator:hs-office-coopsharestransaction-rbac-GRANTING-INSERT-PERMISSION endDelimiter:--//
|
2022-10-18 17:29:36 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
|
|
|
|
2024-04-29 11:43:49 +02:00
|
|
|
-- granting INSERT permission to hs_office_membership ----------------------------
|
|
|
|
|
2022-10-18 17:29:36 +02:00
|
|
|
/*
|
2024-04-29 11:43:49 +02:00
|
|
|
Grants INSERT INTO hs_office_coopsharestransaction permissions to specified role of pre-existing hs_office_membership rows.
|
2022-10-18 17:29:36 +02:00
|
|
|
*/
|
|
|
|
do language plpgsql $$
|
|
|
|
declare
|
2024-04-02 11:04:56 +02:00
|
|
|
row hs_office_membership;
|
2022-10-18 17:29:36 +02:00
|
|
|
begin
|
2024-09-16 15:36:37 +02:00
|
|
|
call base.defineContext('create INSERT INTO hs_office_coopsharestransaction permissions for pre-exising hs_office_membership rows');
|
2024-04-02 11:04:56 +02:00
|
|
|
|
|
|
|
FOR row IN SELECT * FROM hs_office_membership
|
2024-04-29 11:43:49 +02:00
|
|
|
-- unconditional for all rows in that table
|
2024-04-02 11:04:56 +02:00
|
|
|
LOOP
|
2024-09-16 15:36:37 +02:00
|
|
|
call rbac.grantPermissionToRole(
|
|
|
|
rbac.createPermission(row.uuid, 'INSERT', 'hs_office_coopsharestransaction'),
|
2024-04-29 11:43:49 +02:00
|
|
|
hsOfficeMembershipADMIN(row));
|
2024-04-02 11:04:56 +02:00
|
|
|
END LOOP;
|
2024-04-29 11:43:49 +02:00
|
|
|
end;
|
2022-10-18 17:29:36 +02:00
|
|
|
$$;
|
|
|
|
|
|
|
|
/**
|
2024-04-29 11:43:49 +02:00
|
|
|
Grants hs_office_coopsharestransaction INSERT permission to specified role of new hs_office_membership rows.
|
2024-04-02 11:04:56 +02:00
|
|
|
*/
|
2024-09-16 15:36:37 +02:00
|
|
|
create or replace function new_hsof_coopsharetx_grants_insert_to_hsof_membership_tf()
|
2022-10-18 17:29:36 +02:00
|
|
|
returns trigger
|
2024-04-02 11:04:56 +02:00
|
|
|
language plpgsql
|
|
|
|
strict as $$
|
2022-10-18 17:29:36 +02:00
|
|
|
begin
|
2024-04-29 11:43:49 +02:00
|
|
|
-- unconditional for all rows in that table
|
2024-09-16 15:36:37 +02:00
|
|
|
call rbac.grantPermissionToRole(
|
|
|
|
rbac.createPermission(NEW.uuid, 'INSERT', 'hs_office_coopsharestransaction'),
|
2024-04-02 12:01:37 +02:00
|
|
|
hsOfficeMembershipADMIN(NEW));
|
2024-04-29 11:43:49 +02:00
|
|
|
-- end.
|
2024-04-02 11:04:56 +02:00
|
|
|
return NEW;
|
2022-10-18 17:29:36 +02:00
|
|
|
end; $$;
|
|
|
|
|
2024-04-02 11:04:56 +02:00
|
|
|
-- z_... is to put it at the end of after insert triggers, to make sure the roles exist
|
2024-09-16 15:36:37 +02:00
|
|
|
create trigger z_new_hs_office_coopsharestransaction_grants_after_insert_tg
|
2024-04-02 11:04:56 +02:00
|
|
|
after insert on hs_office_membership
|
|
|
|
for each row
|
2024-09-16 15:36:37 +02:00
|
|
|
execute procedure new_hsof_coopsharetx_grants_insert_to_hsof_membership_tf();
|
2024-04-02 11:04:56 +02:00
|
|
|
|
|
|
|
|
2024-04-29 11:43:49 +02:00
|
|
|
-- ============================================================================
|
2024-09-16 15:36:37 +02:00
|
|
|
--changeset InsertTriggerGenerator:hs_office_coopsharestransaction-rbac-CHECKING-INSERT-PERMISSION endDelimiter:--//
|
2024-04-29 11:43:49 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
Checks if the user respectively the assumed roles are allowed to insert a row to hs_office_coopsharestransaction.
|
2024-04-02 11:04:56 +02:00
|
|
|
*/
|
2024-04-29 11:43:49 +02:00
|
|
|
create or replace function hs_office_coopsharestransaction_insert_permission_check_tf()
|
2024-04-02 11:04:56 +02:00
|
|
|
returns trigger
|
|
|
|
language plpgsql as $$
|
2024-04-29 11:43:49 +02:00
|
|
|
declare
|
|
|
|
superObjectUuid uuid;
|
2024-04-02 11:04:56 +02:00
|
|
|
begin
|
2024-04-29 11:43:49 +02:00
|
|
|
-- check INSERT permission via direct foreign key: NEW.membershipUuid
|
2024-09-16 15:36:37 +02:00
|
|
|
if rbac.hasInsertPermission(NEW.membershipUuid, 'hs_office_coopsharestransaction') then
|
2024-04-29 11:43:49 +02:00
|
|
|
return NEW;
|
|
|
|
end if;
|
|
|
|
|
2024-08-05 11:48:33 +02:00
|
|
|
raise exception '[403] insert into hs_office_coopsharestransaction values(%) not allowed for current subjects % (%)',
|
2024-09-16 15:36:37 +02:00
|
|
|
NEW, base.currentSubjects(), rbac.currentSubjectOrAssumedRolesUuids();
|
2024-04-02 11:04:56 +02:00
|
|
|
end; $$;
|
|
|
|
|
|
|
|
create trigger hs_office_coopsharestransaction_insert_permission_check_tg
|
|
|
|
before insert on hs_office_coopsharestransaction
|
2022-10-18 17:29:36 +02:00
|
|
|
for each row
|
2024-04-29 11:43:49 +02:00
|
|
|
execute procedure hs_office_coopsharestransaction_insert_permission_check_tf();
|
2024-04-02 11:04:56 +02:00
|
|
|
--//
|
|
|
|
|
2024-04-29 11:43:49 +02:00
|
|
|
|
2024-04-02 11:04:56 +02:00
|
|
|
-- ============================================================================
|
2024-09-16 15:36:37 +02:00
|
|
|
--changeset RbacIdentityViewGenerator:hs-office-coopsharestransaction-rbac-IDENTITY-VIEW endDelimiter:--//
|
2024-04-02 11:04:56 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
|
|
|
|
2024-09-16 15:36:37 +02:00
|
|
|
call rbac.generateRbacIdentityViewFromProjection('hs_office_coopsharestransaction',
|
2024-04-02 11:04:56 +02:00
|
|
|
$idName$
|
|
|
|
reference
|
|
|
|
$idName$);
|
|
|
|
--//
|
|
|
|
|
2024-04-29 11:43:49 +02:00
|
|
|
|
2024-04-02 11:04:56 +02:00
|
|
|
-- ============================================================================
|
2024-09-16 15:36:37 +02:00
|
|
|
--changeset RbacRestrictedViewGenerator:hs-office-coopsharestransaction-rbac-RESTRICTED-VIEW endDelimiter:--//
|
2024-04-02 11:04:56 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
2024-09-16 15:36:37 +02:00
|
|
|
call rbac.generateRbacRestrictedView('hs_office_coopsharestransaction',
|
2024-04-02 11:04:56 +02:00
|
|
|
$orderBy$
|
|
|
|
reference
|
|
|
|
$orderBy$,
|
|
|
|
$updates$
|
|
|
|
comment = new.comment
|
|
|
|
$updates$);
|
2022-10-18 17:29:36 +02:00
|
|
|
--//
|
|
|
|
|