From 5d0f707c55f7620d20cad0f382af466eaf0c7f05 Mon Sep 17 00:00:00 2001 From: Pere Lev Date: Tue, 21 Nov 2023 20:44:09 +0200 Subject: [PATCH] DB: Allow to record the delegator-Grant sent by people to projects/teams --- migrations/552_2023-11-21_collab_deleg.model | 17 ++++ migrations/553_2023-11-21_collab_deleg.model | 91 ++++++++++++++++++++ src/Vervis/Migration.hs | 17 ++++ src/Vervis/Migration/Entities.hs | 4 + src/Vervis/Migration/Model.hs | 3 + th/models | 38 ++++++-- 6 files changed, 163 insertions(+), 7 deletions(-) create mode 100644 migrations/552_2023-11-21_collab_deleg.model create mode 100644 migrations/553_2023-11-21_collab_deleg.model diff --git a/migrations/552_2023-11-21_collab_deleg.model b/migrations/552_2023-11-21_collab_deleg.model new file mode 100644 index 0000000..9b3bc77 --- /dev/null +++ b/migrations/552_2023-11-21_collab_deleg.model @@ -0,0 +1,17 @@ +CollabDelegLocal + enable CollabEnableId + recip CollabRecipLocalId + grant OutboxItemId + + UniqueCollabDelegLocal enable + UniqueCollabDelegLocalRecip recip + UniqueCollabDelegLocalGrant grant + +CollabDelegRemote + enable CollabEnableId + recip CollabRecipRemoteId + grant RemoteActivityId + + UniqueCollabDelegRemote enable + UniqueCollabDelegRemoteRecip recip + UniqueCollabDelegRemoteGrant grant diff --git a/migrations/553_2023-11-21_collab_deleg.model b/migrations/553_2023-11-21_collab_deleg.model new file mode 100644 index 0000000..99e93fa --- /dev/null +++ b/migrations/553_2023-11-21_collab_deleg.model @@ -0,0 +1,91 @@ +Inbox +FollowerSet + +Outbox + +OutboxItem + outbox OutboxId + activity PersistJSONObject + published UTCTime + +Actor + name Text + desc Text + createdAt UTCTime + inbox InboxId + outbox OutboxId + followers FollowerSetId + justCreatedBy ActorId Maybe + + UniqueActorInbox inbox + UniqueActorOutbox outbox + UniqueActorFollowers followers + +Person + username Username + login Text + passphraseHash ByteString + email EmailAddress + verified Bool + verifiedKey Text + verifiedKeyCreated UTCTime + resetPassKey Text + resetPassKeyCreated UTCTime + actor ActorId +-- reviewFollow Bool + + UniquePersonUsername username + UniquePersonLogin login + UniquePersonEmail email + UniquePersonActor actor + +Collab + role Role + +CollabTopicProject + collab CollabId + project ProjectId + + UniqueCollabTopicProject collab + +Project + actor ActorId + create OutboxItemId + + UniqueProjectActor actor + UniqueProjectCreate create + +CollabTopicGroup + collab CollabId + group GroupId + + UniqueCollabTopicGroup collab + +Group + actor ActorId + create OutboxItemId + + UniqueGroupActor actor + UniqueGroupCreate create + +CollabRecipLocal + collab CollabId + person PersonId + + UniqueCollabRecipLocal collab + +CollabEnable + collab CollabId + grant OutboxItemId + + UniqueCollabEnable collab + UniqueCollabEnableGrant grant + +CollabDelegLocal + enable CollabEnableId + recip CollabRecipLocalId + grant OutboxItemId + + UniqueCollabDelegLocal enable + UniqueCollabDelegLocalRecip recip + UniqueCollabDelegLocalGrant grant diff --git a/src/Vervis/Migration.hs b/src/Vervis/Migration.hs index 9fe65e2..a5a2d02 100644 --- a/src/Vervis/Migration.hs +++ b/src/Vervis/Migration.hs @@ -3049,6 +3049,23 @@ changes hLocal ctx = , addUnique' "Group" "Create" ["create"] -- 551 , addEntities model_551_group_collab + -- 552 + , addEntities model_552_collab_deleg + -- 553 + , unchecked $ lift $ do + collabIDs <- + liftA2 (++) + (map (collabTopicProject553Collab . entityVal) <$> selectList [] []) + (map (collabTopicGroup553Collab . entityVal) <$> selectList [] []) + let doc = persistJSONObjectFromDoc $ Doc hLocal emptyActivity + for_ collabIDs $ \ collabID -> do + e <- getKeyBy $ UniqueCollabEnable553 collabID + r <- getBy $ UniqueCollabRecipLocal553 collabID + for_ e $ \ enableID -> for_ r $ \ (Entity recipID (CollabRecipLocal553 _ personID)) -> do + actorID <- person553Actor <$> getJust personID + outboxID <- actor553Outbox <$> getJust actorID + itemID <- insert $ OutboxItem553 outboxID doc defaultTime + insert_ $ CollabDelegLocal553 enableID recipID itemID ] migrateDB diff --git a/src/Vervis/Migration/Entities.hs b/src/Vervis/Migration/Entities.hs index c4e7247..a0c4963 100644 --- a/src/Vervis/Migration/Entities.hs +++ b/src/Vervis/Migration/Entities.hs @@ -65,6 +65,7 @@ module Vervis.Migration.Entities , model_541_project , model_542_component , model_551_group_collab + , model_552_collab_deleg ) where @@ -252,3 +253,6 @@ model_542_component = $(schema "542_2023-06-26_component") model_551_group_collab :: [Entity SqlBackend] model_551_group_collab = $(schema "551_2023-11-21_group_collab") + +model_552_collab_deleg :: [Entity SqlBackend] +model_552_collab_deleg = $(schema "552_2023-11-21_collab_deleg") diff --git a/src/Vervis/Migration/Model.hs b/src/Vervis/Migration/Model.hs index 172c8c6..1763406 100644 --- a/src/Vervis/Migration/Model.hs +++ b/src/Vervis/Migration/Model.hs @@ -531,3 +531,6 @@ makeEntitiesMigration "547" makeEntitiesMigration "549" $(modelFile "migrations/549_2023-11-21_group_create.model") + +makeEntitiesMigration "553" + $(modelFile "migrations/553_2023-11-21_collab_deleg.model") diff --git a/th/models b/th/models index af3205c..7d69a8d 100644 --- a/th/models +++ b/th/models @@ -682,13 +682,6 @@ CollabTopicGroup UniqueCollabTopicGroup collab -CollabEnable - collab CollabId - grant OutboxItemId - - UniqueCollabEnable collab - UniqueCollabEnableGrant grant - -------------------------------- Collab recipient ---------------------------- CollabRecipLocal @@ -721,6 +714,37 @@ CollabRecipRemoteAccept UniqueCollabRecipRemoteAcceptInvite invite UniqueCollabRecipRemoteAcceptAccept accept +-------------------------------- Collab enable ------------------------------- + +CollabEnable + collab CollabId + grant OutboxItemId + + UniqueCollabEnable collab + UniqueCollabEnableGrant grant + +-- Component: N/A +-- Project/Team: Witnesses that using the above Grant, the collaborator has +-- sent me a delegator-Grant, which I can now use to extend chains to them + +CollabDelegLocal + enable CollabEnableId + recip CollabRecipLocalId + grant OutboxItemId + + UniqueCollabDelegLocal enable + UniqueCollabDelegLocalRecip recip + UniqueCollabDelegLocalGrant grant + +CollabDelegRemote + enable CollabEnableId + recip CollabRecipRemoteId + grant RemoteActivityId + + UniqueCollabDelegRemote enable + UniqueCollabDelegRemoteRecip recip + UniqueCollabDelegRemoteGrant grant + ------------------------------------------------------------------------------ -- Components, from project perspective ------------------------------------------------------------------------------