-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(authz): introduce an owner relationship when creating an entity (#…
- Loading branch information
Showing
23 changed files
with
610 additions
and
359 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
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
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
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
54 changes: 54 additions & 0 deletions
54
search-service/src/main/resources/db/migration/V0_41__migrate_to_creator_right.sql
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,54 @@ | ||
-- rename exiting authz rights | ||
UPDATE entity_access_rights | ||
SET access_right = | ||
CASE | ||
WHEN access_right = 'rCanAdmin' THEN 'canAdmin' | ||
WHEN access_right = 'rCanWrite' THEN 'canWrite' | ||
WHEN access_right = 'rCanReadm' THEN 'canRead' | ||
END; | ||
|
||
WITH entities AS ( | ||
SELECT entity_id, count(*) as admin_right_count | ||
FROM entity_access_rights | ||
WHERE access_right = 'canAdmin' | ||
GROUP BY entity_id | ||
) | ||
UPDATE entity_access_rights | ||
SET access_right = 'isOwner' | ||
WHERE entity_id IN (select entity_id from entities where admin_right_count = 1) | ||
AND access_right = 'canAdmin'; | ||
|
||
-- set isOwner for entities with more than admin right | ||
WITH entities AS ( | ||
SELECT entity_id, count(*) as admin_right_count | ||
FROM entity_access_rights | ||
WHERE access_right = 'canAdmin' | ||
GROUP BY entity_id | ||
), entities_more_than_one_admin AS ( | ||
SELECT entity_id | ||
FROM entities | ||
WHERE admin_right_count > 1 | ||
), entities_with_oldest_date AS ( | ||
SELECT entity_id, min(created_at) as created_at | ||
FROM temporal_entity_attribute | ||
WHERE entity_id IN (select entity_id from entities_more_than_one_admin) | ||
GROUP BY entity_id | ||
), entities_with_oldest_sub AS ( | ||
select distinct tea.entity_id, sub | ||
from temporal_entity_attribute tea, entities_with_oldest_date | ||
inner join lateral ( | ||
select sub | ||
from attribute_instance_audit | ||
where temporal_entity_attribute = tea.id | ||
and time_property = 'CREATED_AT' | ||
and sub is not null | ||
) l on true | ||
where tea.entity_id = entities_with_oldest_date.entity_id | ||
and tea.created_at = entities_with_oldest_date.created_at | ||
) | ||
update entity_access_rights | ||
set access_right = 'isOwner', | ||
subject_id = entities_with_oldest_sub.sub | ||
from entities_with_oldest_sub | ||
where entity_access_rights.entity_id = entities_with_oldest_sub.entity_id | ||
and entity_access_rights.access_right = 'canAdmin'; |
Oops, something went wrong.