Compare commits
No commits in common. "77aba67af985c496b1c9085cb42f7c0e082f4c29" and "5f00a093e41689437e6bd62259c07e35c088231e" have entirely different histories.
77aba67af9
...
5f00a093e4
@ -110,7 +110,7 @@ end; $$;
|
||||
/*
|
||||
Returns the current user as defined by `basis.defineContext(...)`.
|
||||
*/
|
||||
create or replace function basis.currentUser()
|
||||
create or replace function currentUser()
|
||||
returns varchar(63)
|
||||
stable -- leakproof
|
||||
language plpgsql as $$
|
||||
@ -134,7 +134,7 @@ end; $$;
|
||||
Returns assumed role names as set in `hsadminng.assumedRoles`
|
||||
or empty array, if not set.
|
||||
*/
|
||||
create or replace function basis.assumedRoles()
|
||||
create or replace function assumedRoles()
|
||||
returns varchar(1023)[]
|
||||
stable -- leakproof
|
||||
language plpgsql as $$
|
||||
@ -213,11 +213,11 @@ create or replace function currentSubjects()
|
||||
declare
|
||||
assumedRoles varchar(1023)[];
|
||||
begin
|
||||
assumedRoles := basis.assumedRoles();
|
||||
assumedRoles := assumedRoles();
|
||||
if array_length(assumedRoles, 1) > 0 then
|
||||
return assumedRoles;
|
||||
else
|
||||
return array [basis.currentUser()]::varchar(1023)[];
|
||||
return array [currentUser()]::varchar(1023)[];
|
||||
end if;
|
||||
end; $$;
|
||||
|
||||
@ -226,7 +226,7 @@ create or replace function hasAssumedRole()
|
||||
stable -- leakproof
|
||||
language plpgsql as $$
|
||||
begin
|
||||
return array_length(basis.assumedRoles(), 1) > 0;
|
||||
return array_length(assumedRoles(), 1) > 0;
|
||||
end; $$;
|
||||
--//
|
||||
|
||||
|
@ -84,7 +84,7 @@ begin
|
||||
insert
|
||||
into basis.tx_context (txId, txTimestamp, currentUser, assumedRoles, currentTask, currentRequest)
|
||||
values ( curTxId, now(),
|
||||
basis.currentUser(), basis.assumedRoles(), curTask, basis.currentRequest())
|
||||
currentUser(), assumedRoles(), curTask, basis.currentRequest())
|
||||
on conflict do nothing;
|
||||
|
||||
case tg_op
|
||||
|
@ -3,7 +3,7 @@
|
||||
-- ============================================================================
|
||||
--changeset hs-global-historization-tx-history-txid:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
create or replace function basis.tx_history_txid()
|
||||
create or replace function tx_history_txid()
|
||||
returns xid8 stable
|
||||
language plpgsql as $$
|
||||
declare
|
||||
@ -12,18 +12,18 @@ declare
|
||||
historicalTxId xid8;
|
||||
historicalTimestamp timestamp;
|
||||
begin
|
||||
select coalesce(current_setting('hsadminng.basis.tx_history_txid', true), '') into historicalTxIdSetting;
|
||||
select coalesce(current_setting('hsadminng.tx_history_txid', true), '') into historicalTxIdSetting;
|
||||
select coalesce(current_setting('hsadminng.tx_history_timestamp', true), '') into historicalTimestampSetting;
|
||||
if historicalTxIdSetting > '' and historicalTimestampSetting > '' then
|
||||
raise exception 'either hsadminng.basis.tx_history_txid or hsadminng.tx_history_timestamp must be set, but both are set: (%, %)',
|
||||
raise exception 'either hsadminng.tx_history_txid or hsadminng.tx_history_timestamp must be set, but both are set: (%, %)',
|
||||
historicalTxIdSetting, historicalTimestampSetting;
|
||||
end if;
|
||||
if historicalTxIdSetting = '' and historicalTimestampSetting = '' then
|
||||
raise exception 'either hsadminng.basis.tx_history_txid or hsadminng.tx_history_timestamp must be set, but both are unset or empty: (%, %)',
|
||||
raise exception 'either hsadminng.tx_history_txid or hsadminng.tx_history_timestamp must be set, but both are unset or empty: (%, %)',
|
||||
historicalTxIdSetting, historicalTimestampSetting;
|
||||
end if;
|
||||
-- just for debugging / making sure the function is only called once per query
|
||||
-- raise notice 'basis.tx_history_txid() called with: (%, %)', historicalTxIdSetting, historicalTimestampSetting;
|
||||
-- raise notice 'tx_history_txid() called with: (%, %)', historicalTxIdSetting, historicalTimestampSetting;
|
||||
|
||||
if historicalTxIdSetting is null or historicalTxIdSetting = '' then
|
||||
select historicalTimestampSetting::timestamp into historicalTimestamp;
|
||||
@ -40,7 +40,7 @@ end; $$;
|
||||
--changeset hs-global-historization-tx-historicize-tf:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
create type basis.tx_operation as enum ('INSERT', 'UPDATE', 'DELETE', 'TRUNCATE');
|
||||
create type "tx_operation" as enum ('INSERT', 'UPDATE', 'DELETE', 'TRUNCATE');
|
||||
|
||||
create or replace function tx_historicize_tf()
|
||||
returns trigger
|
||||
@ -95,7 +95,7 @@ end; $$;
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
create or replace procedure basis.tx_create_historicization(baseTable varchar)
|
||||
create or replace procedure tx_create_historicization(baseTable varchar)
|
||||
language plpgsql as $$
|
||||
declare
|
||||
createHistTableSql varchar;
|
||||
@ -111,7 +111,7 @@ begin
|
||||
'CREATE TABLE ' || baseTable || '_ex (' ||
|
||||
' version_id serial PRIMARY KEY,' ||
|
||||
' txid xid8 NOT NULL REFERENCES basis.tx_context(txid),' ||
|
||||
' trigger_op basis.tx_operation NOT NULL,' ||
|
||||
' trigger_op tx_operation NOT NULL,' ||
|
||||
' alive boolean not null,' ||
|
||||
' LIKE ' || baseTable ||
|
||||
' EXCLUDING CONSTRAINTS' ||
|
||||
@ -132,7 +132,7 @@ begin
|
||||
'CREATE OR REPLACE VIEW %1$s AS' ||
|
||||
'(' ||
|
||||
-- make sure the function is only called once, not for every matching row in basis.tx_context
|
||||
' WITH txh AS (SELECT basis.tx_history_txid() AS txid) ' ||
|
||||
' WITH txh AS (SELECT tx_history_txid() AS txid) ' ||
|
||||
' SELECT %2$s' ||
|
||||
' FROM %3$s' ||
|
||||
' WHERE alive = TRUE' ||
|
||||
|
@ -12,8 +12,8 @@ declare
|
||||
currentSubjectsUuids uuid[];
|
||||
begin
|
||||
-- exactly one role must be assumed, not none not more than one
|
||||
if cardinality(basis.assumedRoles()) <> 1 then
|
||||
raise exception '[400] Granting roles to user is only possible if exactly one role is assumed, given: %', basis.assumedRoles();
|
||||
if cardinality(assumedRoles()) <> 1 then
|
||||
raise exception '[400] Granting roles to user is only possible if exactly one role is assumed, given: %', assumedRoles();
|
||||
end if;
|
||||
|
||||
currentSubjectsUuids := currentSubjectsUuids();
|
||||
|
@ -66,10 +66,10 @@ begin
|
||||
and r.roleType = roleTypeToAssume
|
||||
into roleUuidToAssume;
|
||||
if roleUuidToAssume is null then
|
||||
raise exception '[403] role % does not exist or is not accessible for user %', roleName, basis.currentUser();
|
||||
raise exception '[403] role % does not exist or is not accessible for user %', roleName, currentUser();
|
||||
end if;
|
||||
if not isGranted(currentUserUuid, roleUuidToAssume) then
|
||||
raise exception '[403] user % has no permission to assume role %', basis.currentUser(), roleName;
|
||||
raise exception '[403] user % has no permission to assume role %', currentUser(), roleName;
|
||||
end if;
|
||||
roleIdsToAssume := roleIdsToAssume || roleUuidToAssume;
|
||||
end loop;
|
||||
@ -132,7 +132,7 @@ begin
|
||||
currentUserUuid := null;
|
||||
end;
|
||||
if (currentUserUuid is null or currentUserUuid = '') then
|
||||
currentUserName := basis.currentUser();
|
||||
currentUserName := currentUser();
|
||||
if (length(currentUserName) > 0) then
|
||||
raise exception '[401] currentUserUuid cannot be determined, unknown user name "%"', currentUserName;
|
||||
else
|
||||
@ -166,7 +166,7 @@ begin
|
||||
currentSubjectsUuids := null;
|
||||
end;
|
||||
if (currentSubjectsUuids is null or length(currentSubjectsUuids) = 0 ) then
|
||||
currentUserName := basis.currentUser();
|
||||
currentUserName := currentUser();
|
||||
if (length(currentUserName) > 0) then
|
||||
raise exception '[401] currentSubjectsUuids (%) cannot be determined, unknown user name "%"', currentSubjectsUuids, currentUserName;
|
||||
else
|
||||
|
@ -241,7 +241,7 @@ create or replace view RbacUser_rv as
|
||||
union
|
||||
select users.*
|
||||
from RbacUser as users
|
||||
where cardinality(basis.assumedRoles()) = 0 and
|
||||
where cardinality(assumedRoles()) = 0 and
|
||||
(currentUserUuid() = users.uuid or hasGlobalRoleGranted(currentUserUuid()))
|
||||
|
||||
) as unordered
|
||||
@ -303,7 +303,7 @@ begin
|
||||
delete from RbacUser where uuid = old.uuid;
|
||||
return old;
|
||||
end if;
|
||||
raise exception '[403] User % not allowed to delete user uuid %', basis.currentUser(), old.uuid;
|
||||
raise exception '[403] User % not allowed to delete user uuid %', currentUser(), old.uuid;
|
||||
end; $$;
|
||||
|
||||
/*
|
||||
@ -354,7 +354,7 @@ begin
|
||||
currentUserUuid := currentUserUuid();
|
||||
|
||||
if hasGlobalRoleGranted(targetUserUuid) and not hasGlobalRoleGranted(currentUserUuid) then
|
||||
raise exception '[403] permissions of user "%" are not accessible to user "%"', targetUserUuid, basis.currentUser();
|
||||
raise exception '[403] permissions of user "%" are not accessible to user "%"', targetUserUuid, currentUser();
|
||||
end if;
|
||||
|
||||
return query select
|
||||
|
@ -25,5 +25,5 @@ call basis.create_journal('hs_booking_project');
|
||||
-- ============================================================================
|
||||
--changeset hs-booking-project-MAIN-TABLE-HISTORIZATION:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
call basis.tx_create_historicization('hs_booking_project');
|
||||
call tx_create_historicization('hs_booking_project');
|
||||
--//
|
||||
|
@ -42,6 +42,6 @@ call basis.create_journal('hs_booking_item');
|
||||
-- ============================================================================
|
||||
--changeset hs-booking-item-MAIN-TABLE-HISTORIZATION:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
call basis.tx_create_historicization('hs_booking_item');
|
||||
call tx_create_historicization('hs_booking_item');
|
||||
--//
|
||||
|
||||
|
@ -173,7 +173,7 @@ call basis.create_journal('hs_hosting_asset');
|
||||
-- ============================================================================
|
||||
--changeset hs-hosting-asset-MAIN-TABLE-HISTORIZATION:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
call basis.tx_create_historicization('hs_hosting_asset');
|
||||
call tx_create_historicization('hs_hosting_asset');
|
||||
--//
|
||||
|
||||
|
||||
|
@ -52,7 +52,7 @@ public abstract class ContextBasedTest {
|
||||
protected void historicalContext(final Long txId) {
|
||||
// set local cannot be used with query parameters
|
||||
em.createNativeQuery("""
|
||||
set local hsadminng.basis.tx_history_txid to ':txid';
|
||||
set local hsadminng.tx_history_txid to ':txid';
|
||||
""".replace(":txid", txId.toString())).executeUpdate();
|
||||
em.createNativeQuery("""
|
||||
set local hsadminng.tx_history_timestamp to '';
|
||||
@ -66,7 +66,7 @@ public abstract class ContextBasedTest {
|
||||
set local hsadminng.tx_history_timestamp to ':timestamp';
|
||||
""".replace(":timestamp", txTimestamp.toString())).executeUpdate();
|
||||
em.createNativeQuery("""
|
||||
set local hsadminng.basis.tx_history_txid to '';
|
||||
set local hsadminng.tx_history_txid to '';
|
||||
""").executeUpdate();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user