2022-07-29 12:37:40 +02:00
|
|
|
--liquibase formatted sql
|
|
|
|
|
|
|
|
-- ============================================================================
|
2022-09-16 15:25:58 +02:00
|
|
|
--changeset test-package-rbac-OBJECT:1 endDelimiter:--//
|
2022-07-29 12:37:40 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
2022-09-16 15:25:58 +02:00
|
|
|
call generateRelatedRbacObject('test_package');
|
2022-07-29 12:37:40 +02:00
|
|
|
--//
|
2022-07-22 13:31:37 +02:00
|
|
|
|
|
|
|
|
2022-07-29 12:37:40 +02:00
|
|
|
-- ============================================================================
|
2022-08-31 09:42:40 +02:00
|
|
|
--changeset test-package-rbac-ROLE-DESCRIPTORS:1 endDelimiter:--//
|
2022-07-29 12:37:40 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
2022-09-16 15:25:58 +02:00
|
|
|
call generateRbacRoleDescriptors('testPackage', 'test_package');
|
2022-07-29 12:37:40 +02:00
|
|
|
--//
|
2022-07-25 16:38:21 +02:00
|
|
|
|
|
|
|
|
2022-07-29 12:37:40 +02:00
|
|
|
-- ============================================================================
|
2022-08-31 09:42:40 +02:00
|
|
|
--changeset test-package-rbac-ROLES-CREATION:1 endDelimiter:--//
|
2022-07-29 12:37:40 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
Creates the roles and their assignments for a new package for the AFTER INSERT TRIGGER.
|
|
|
|
*/
|
2022-08-31 09:42:40 +02:00
|
|
|
create or replace function createRbacRolesForTestPackage()
|
2022-07-29 08:46:04 +02:00
|
|
|
returns trigger
|
|
|
|
language plpgsql
|
|
|
|
strict as $$
|
|
|
|
declare
|
2022-08-31 09:42:40 +02:00
|
|
|
parentCustomer test_customer;
|
2022-07-29 08:46:04 +02:00
|
|
|
begin
|
|
|
|
if TG_OP <> 'INSERT' then
|
|
|
|
raise exception 'invalid usage of TRIGGER AFTER INSERT';
|
|
|
|
end if;
|
2022-07-22 13:31:37 +02:00
|
|
|
|
2024-02-24 09:04:07 +01:00
|
|
|
call enterTriggerForObjectUuid(NEW.uuid);
|
|
|
|
|
2022-08-31 09:42:40 +02:00
|
|
|
select * from test_customer as c where c.uuid = NEW.customerUuid into parentCustomer;
|
2022-07-22 13:31:37 +02:00
|
|
|
|
2022-07-25 16:38:21 +02:00
|
|
|
-- an owner role is created and assigned to the customer's admin role
|
2022-10-12 15:48:56 +02:00
|
|
|
perform createRoleWithGrants(
|
|
|
|
testPackageOwner(NEW),
|
|
|
|
permissions => array ['*'],
|
|
|
|
incomingSuperRoles => array[testCustomerAdmin(parentCustomer)]
|
2022-07-25 16:38:21 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
-- an owner role is created and assigned to the package owner role
|
2022-10-12 15:48:56 +02:00
|
|
|
perform createRoleWithGrants(
|
|
|
|
testPackageAdmin(NEW),
|
|
|
|
permissions => array ['add-domain'],
|
|
|
|
incomingSuperRoles => array[testPackageOwner(NEW)]
|
2022-07-25 16:38:21 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
-- and a package tenant role is created and assigned to the package admin as well
|
2022-10-12 15:48:56 +02:00
|
|
|
perform createRoleWithGrants(
|
|
|
|
testPackageTenant(NEW),
|
|
|
|
permissions => array['view'],
|
|
|
|
incomingsuperroles => array[testPackageAdmin(NEW)],
|
|
|
|
outgoingSubRoles => array[testCustomerTenant(parentCustomer)]
|
2022-07-25 16:38:21 +02:00
|
|
|
);
|
2022-07-22 13:31:37 +02:00
|
|
|
|
2024-02-24 09:04:07 +01:00
|
|
|
call leaveTriggerForObjectUuid(NEW.uuid);
|
2022-07-29 08:46:04 +02:00
|
|
|
return NEW;
|
|
|
|
end; $$;
|
2022-07-22 13:31:37 +02:00
|
|
|
|
2022-07-29 12:37:40 +02:00
|
|
|
/*
|
|
|
|
An AFTER INSERT TRIGGER which creates the role structure for a new package.
|
|
|
|
*/
|
|
|
|
|
2022-08-31 09:42:40 +02:00
|
|
|
create trigger createRbacRolesForTestPackage_Trigger
|
2022-07-29 08:46:04 +02:00
|
|
|
after insert
|
2022-08-31 09:42:40 +02:00
|
|
|
on test_package
|
2022-07-29 08:46:04 +02:00
|
|
|
for each row
|
2022-08-31 09:42:40 +02:00
|
|
|
execute procedure createRbacRolesForTestPackage();
|
2022-07-29 12:37:40 +02:00
|
|
|
--//
|
|
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
2022-08-31 09:42:40 +02:00
|
|
|
--changeset test-package-rbac-IDENTITY-VIEW:1 endDelimiter:--//
|
2022-07-29 16:25:46 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
2022-09-19 20:43:14 +02:00
|
|
|
call generateRbacIdentityView('test_package', 'target.name');
|
2022-07-29 16:25:46 +02:00
|
|
|
--//
|
|
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
2022-08-31 09:42:40 +02:00
|
|
|
--changeset test-package-rbac-RESTRICTED-VIEW:1 endDelimiter:--//
|
2022-07-29 12:37:40 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/*
|
|
|
|
Creates a view to the customer main table which maps the identifying name
|
|
|
|
(in this case, the prefix) to the objectUuid.
|
|
|
|
*/
|
2022-09-19 20:43:14 +02:00
|
|
|
-- drop view if exists test_package_rv;
|
|
|
|
-- create or replace view test_package_rv as
|
|
|
|
-- select target.*
|
|
|
|
-- from test_package as target
|
|
|
|
-- where target.uuid in (select queryAccessibleObjectUuidsOfSubjectIds('view', 'test_package', currentSubjectsUuids()))
|
|
|
|
-- order by target.name;
|
2024-01-23 15:11:23 +01:00
|
|
|
-- grant all privileges on test_package_rv to ${HSADMINNG_POSTGRES_RESTRICTED_USERNAME};
|
2022-09-19 20:43:14 +02:00
|
|
|
|
|
|
|
call generateRbacRestrictedView('test_package', 'target.name',
|
|
|
|
$updates$
|
|
|
|
version = new.version,
|
|
|
|
customerUuid = new.customerUuid,
|
|
|
|
name = new.name,
|
|
|
|
description = new.description
|
|
|
|
$updates$);
|
|
|
|
|
2022-07-29 12:37:40 +02:00
|
|
|
--//
|
2022-09-19 20:43:14 +02:00
|
|
|
|
|
|
|
|