-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add migration for custom ACL actions (#1164)
Custom actions for events are now stored in DB with a new column. This is only the backend side of things, so they won't show up in the ACL UI yet. Part of #1004
- Loading branch information
Showing
5 changed files
with
93 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
-- Adds a field for custom actions to `events`. | ||
-- The field's entries are mappings of individual custom actions | ||
-- and the respective roles that are allowed to carry out that action. | ||
|
||
alter table events | ||
add column custom_action_roles jsonb; | ||
|
||
-- The following function verifies that the custom action column and its | ||
-- entries follow a predefined format. | ||
create or replace function check_custom_actions_format() returns trigger as $$ | ||
declare | ||
col text := 'events.custom_action_roles'; | ||
field record; | ||
element jsonb; | ||
begin | ||
if jsonb_typeof(new.custom_action_roles) <> 'object' then | ||
raise exception '% is %, but should be a JSON object', col, jsonb_typeof(new.custom_actions); | ||
end if; | ||
|
||
for field in select * from jsonb_each(new.custom_action_roles) loop | ||
if jsonb_typeof(field.value) <> 'array' then | ||
raise exception '%: type of field "%" is %, but should be an array', | ||
col, | ||
field.key, | ||
jsonb_typeof(field.value); | ||
end if; | ||
|
||
for element in select * from jsonb_array_elements(field.value) loop | ||
if jsonb_typeof(element) <> 'string' then | ||
raise exception '%: found non-string element "%" in field "%", but that field should be a string array', | ||
col, | ||
element, | ||
field.key; | ||
end if; | ||
end loop; | ||
end loop; | ||
|
||
return new; | ||
end; | ||
$$ language plpgsql; | ||
|
||
create trigger check_custom_actions_format_on_upsert | ||
before insert or update on events | ||
for each row | ||
execute procedure check_custom_actions_format(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters