From 05d3a1eaefa6154cf3e7472ee00baacfb4bb7fdd Mon Sep 17 00:00:00 2001 From: Pere Lev Date: Wed, 22 Nov 2023 18:11:07 +0200 Subject: [PATCH] DB: Tables for the person side of Collabs (i.e. direct-Grants they got) Until now I've managed to avoid having to implement this piece quite easily. The only temptation to implement it has been pseudo-client features, which are basically just a workaround until Vervis gets a separate client app. But now, Person actors need to be able to automatically send delegator-Grants when they receive a direct-Grant from a resource they either asked to Join or got an Invite to. So, this creates a need to track these joins and invites on the server side. I'm not checking the exact minimal pieces necessary for delegator-Grants. Instead, I'm starting a full implementation of the person-side of Collab records (AKA direct-Grants), called Permit records. This will also allow very convenient display of these Grants and the extensions received through them, as well as UI buttons such as accepting/rejecting a received Join or Invite. --- migrations/564_2023-11-22_permit.model | 182 +++++++++++++++++++++++ src/Vervis/Migration.hs | 2 + src/Vervis/Migration/Entities.hs | 4 + th/models | 190 ++++++++++++++++++++++++- 4 files changed, 377 insertions(+), 1 deletion(-) create mode 100644 migrations/564_2023-11-22_permit.model diff --git a/migrations/564_2023-11-22_permit.model b/migrations/564_2023-11-22_permit.model new file mode 100644 index 0000000..6851563 --- /dev/null +++ b/migrations/564_2023-11-22_permit.model @@ -0,0 +1,182 @@ +Permit + person PersonId + role Role + +-------------------------------- Permit topic -------------------------------- + +PermitTopicLocal + permit PermitId + + UniquePermitTopicLocal permit + +PermitTopicRepo + permit PermitTopicLocalId + repo RepoId + + UniquePermitTopicRepo permit + +PermitTopicDeck + permit PermitTopicLocalId + deck DeckId + + UniquePermitTopicDeck permit + +PermitTopicLoom + permit PermitTopicLocalId + loom LoomId + + UniquePermitTopicLoom permit + +PermitTopicProject + permit PermitTopicLocalId + project ProjectId + + UniquePermitTopicProject permit + +PermitTopicGroup + permit PermitTopicLocalId + group GroupId + + UniquePermitTopicGroup permit + +PermitTopicRemote + permit PermitId + actor RemoteActorId + + UniquePermitTopicRemote permit + +------------------------------- Permit reason -------------------------------- + +PermitFulfillsTopicCreation + permit PermitId + + UniquePermitFulfillsTopicCreation permit + +PermitFulfillsInvite + permit PermitId + + UniquePermitFulfillsInvite permit + +PermitFulfillsJoin + permit PermitId + + UniquePermitFulfillsJoin permit + +-- Person's gesture +-- +-- Join: Witnesses the initial Join that started the sequence +-- Invite: Witnesses their approval, seeing the topic's accept, and then +-- sending their own accept +-- Create: Records the Create activity that created the topic + +PermitPersonGesture + permit PermitId + activity OutboxItemId + + UniquePermitPersonGesture permit + UniquePermitPersonGestureActivity activity + +-- Topic collaborator's gesture +-- +-- Join: N/A (it happens but we don't record it) +-- Invite: Witnesses the initial Invite that started the sequence + +PermitTopicGestureLocal + fulfills PermitFulfillsInviteId + invite OutboxItemId + + UniquePermitTopicGestureLocal fulfills + UniquePermitTopicGestureLocalInvite invite + +PermitTopicGestureRemote + fulfills PermitFulfillsInviteId + actor RemoteActorId + invite RemoteActivityId + + UniquePermitTopicGestureRemote fulfills + UniquePermitTopicGestureRemoteInvite invite + +-- Topic's accept +-- +-- Join: N/A +-- Invite: Witnesses that the topic saw and approved the Invite + +PermitTopicAcceptLocal + fulfills PermitFulfillsInviteId + topic PermitTopicLocalId + accept OutboxItemId + + UniquePermitTopicAcceptLocal fulfills + UniquePermitTopicAcceptLocalTopic topic + UniquePermitTopicAcceptLocalAccept accept + +PermitTopicAcceptRemote + fulfills PermitFulfillsInviteId + topic PermitTopicRemoteId + accept RemoteActivityId + + UniquePermitTopicAcceptRemote fulfills + UniquePermitTopicAcceptRemoteTopic topic + UniquePermitTopicAcceptRemoteAccept accept + +-------------------------------- Permit enable ------------------------------- + +-- Topic's grant +-- +-- Join: Seeing the new-collaborator's Join and existing-collaborator's Accept, +-- the topic has made the link official and sent a direct-grant +-- Invite: Seeing existing-collaborator's Invite and new-collaborator's Accept, +-- the topic has made the link official and sent a direct-grant + +PermitTopicEnableLocal + permit PermitPersonGestureId + topic PermitTopicLocalId + grant OutboxItemId + + UniquePermitTopicEnableLocal permit + UniquePermitTopicEnableLocalTopic topic + UniquePermitTopicEnableLocalGrant grant + +PermitTopicEnableRemote + permit PermitPersonGestureId + topic PermitTopicRemoteId + grant RemoteActivityId + + UniquePermitTopicEnableRemote permit + UniquePermitTopicEnableRemoteTopic topic + UniquePermitTopicEnableRemoteGrant grant + +----------------------- Permit delegator+extension --------------------------- + +-- This section is only for Project or Team topics +-- Person sends delegator-Grant, topic starts sending extension-Grants + +-- Witnesses that the person used the direct-Grant to send a delegator-Grant to +-- the topic +PermitPersonSendDelegator + permit PermitPersonGestureId + grant OutboxItemId + + UniquePermitPersonSendDelegator permit + UniquePermitPersonSendDelegatorGrant grant + +-- Witnesses extension-Grants that the topic has sent, extending chains from +-- its components/subprojects or projects/superteams + +PermitTopicExtendLocal + permit PermitPersonSendDelegatorId + topic PermitTopicEnableLocalId + grant OutboxItemId + + UniquePermitTopicExtendLocal permit + UniquePermitTopicExtendLocalTopic topic + UniquePermitTopicExtendLocalGrant grant + +PermitTopicExtendRemote + permit PermitPersonSendDelegatorId + topic PermitTopicEnableRemoteId + grant RemoteActivityId + + UniquePermitTopicExtendRemote permit + UniquePermitTopicExtendRemoteTopic topic + UniquePermitTopicExtendRemoteGrant grant diff --git a/src/Vervis/Migration.hs b/src/Vervis/Migration.hs index 4331fb4..97dd4ce 100644 --- a/src/Vervis/Migration.hs +++ b/src/Vervis/Migration.hs @@ -3119,6 +3119,8 @@ changes hLocal ctx = , renameField "ComponentFurtherRemote" "collabNew" "collab" -- 563 , addUnique' "ComponentFurtherRemote" "" ["component", "collab"] + -- 564 + , addEntities model_564_permit ] migrateDB diff --git a/src/Vervis/Migration/Entities.hs b/src/Vervis/Migration/Entities.hs index a0c4963..c84d222 100644 --- a/src/Vervis/Migration/Entities.hs +++ b/src/Vervis/Migration/Entities.hs @@ -66,6 +66,7 @@ module Vervis.Migration.Entities , model_542_component , model_551_group_collab , model_552_collab_deleg + , model_564_permit ) where @@ -256,3 +257,6 @@ 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") + +model_564_permit :: [Entity SqlBackend] +model_564_permit = $(schema "564_2023-11-22_permit") diff --git a/th/models b/th/models index 2b5e02f..4da41c9 100644 --- a/th/models +++ b/th/models @@ -577,7 +577,7 @@ RemoteMessage ------------------------------------------------------------------------------ --- Collaborators +-- Collaborators, from resource perspective ------------------------------------------------------------------------------ Collab @@ -745,6 +745,194 @@ CollabDelegRemote UniqueCollabDelegRemoteRecip recip UniqueCollabDelegRemoteGrant grant +------------------------------------------------------------------------------ +-- Collaborators, from person perspective +------------------------------------------------------------------------------ + +Permit + person PersonId + role Role + +-------------------------------- Permit topic -------------------------------- + +PermitTopicLocal + permit PermitId + + UniquePermitTopicLocal permit + +PermitTopicRepo + permit PermitTopicLocalId + repo RepoId + + UniquePermitTopicRepo permit + +PermitTopicDeck + permit PermitTopicLocalId + deck DeckId + + UniquePermitTopicDeck permit + +PermitTopicLoom + permit PermitTopicLocalId + loom LoomId + + UniquePermitTopicLoom permit + +PermitTopicProject + permit PermitTopicLocalId + project ProjectId + + UniquePermitTopicProject permit + +PermitTopicGroup + permit PermitTopicLocalId + group GroupId + + UniquePermitTopicGroup permit + +PermitTopicRemote + permit PermitId + actor RemoteActorId + + UniquePermitTopicRemote permit + +------------------------------- Permit reason -------------------------------- + +PermitFulfillsTopicCreation + permit PermitId + + UniquePermitFulfillsTopicCreation permit + +PermitFulfillsInvite + permit PermitId + + UniquePermitFulfillsInvite permit + +PermitFulfillsJoin + permit PermitId + + UniquePermitFulfillsJoin permit + +-- Person's gesture +-- +-- Join: Witnesses the initial Join that started the sequence +-- Invite: Witnesses their approval, seeing the topic's accept, and then +-- sending their own accept +-- Create: Records the Create activity that created the topic + +PermitPersonGesture + permit PermitId + activity OutboxItemId + + UniquePermitPersonGesture permit + UniquePermitPersonGestureActivity activity + +-- Topic collaborator's gesture +-- +-- Join: N/A (it happens but we don't record it) +-- Invite: Witnesses the initial Invite that started the sequence + +PermitTopicGestureLocal + fulfills PermitFulfillsInviteId + invite OutboxItemId + + UniquePermitTopicGestureLocal fulfills + UniquePermitTopicGestureLocalInvite invite + +PermitTopicGestureRemote + fulfills PermitFulfillsInviteId + actor RemoteActorId + invite RemoteActivityId + + UniquePermitTopicGestureRemote fulfills + UniquePermitTopicGestureRemoteInvite invite + +-- Topic's accept +-- +-- Join: N/A +-- Invite: Witnesses that the topic saw and approved the Invite + +PermitTopicAcceptLocal + fulfills PermitFulfillsInviteId + topic PermitTopicLocalId + accept OutboxItemId + + UniquePermitTopicAcceptLocal fulfills + UniquePermitTopicAcceptLocalTopic topic + UniquePermitTopicAcceptLocalAccept accept + +PermitTopicAcceptRemote + fulfills PermitFulfillsInviteId + topic PermitTopicRemoteId + accept RemoteActivityId + + UniquePermitTopicAcceptRemote fulfills + UniquePermitTopicAcceptRemoteTopic topic + UniquePermitTopicAcceptRemoteAccept accept + +-------------------------------- Permit enable ------------------------------- + +-- Topic's grant +-- +-- Join: Seeing the new-collaborator's Join and existing-collaborator's Accept, +-- the topic has made the link official and sent a direct-grant +-- Invite: Seeing existing-collaborator's Invite and new-collaborator's Accept, +-- the topic has made the link official and sent a direct-grant +-- Create: Upon being created, topic has sent its creator an admin-Grant + +PermitTopicEnableLocal + permit PermitPersonGestureId + topic PermitTopicLocalId + grant OutboxItemId + + UniquePermitTopicEnableLocal permit + UniquePermitTopicEnableLocalTopic topic + UniquePermitTopicEnableLocalGrant grant + +PermitTopicEnableRemote + permit PermitPersonGestureId + topic PermitTopicRemoteId + grant RemoteActivityId + + UniquePermitTopicEnableRemote permit + UniquePermitTopicEnableRemoteTopic topic + UniquePermitTopicEnableRemoteGrant grant + +----------------------- Permit delegator+extension --------------------------- + +-- This section is only for Project or Team topics +-- Person sends delegator-Grant, topic starts sending extension-Grants + +-- Witnesses that the person used the direct-Grant to send a delegator-Grant to +-- the topic +PermitPersonSendDelegator + permit PermitPersonGestureId + grant OutboxItemId + + UniquePermitPersonSendDelegator permit + UniquePermitPersonSendDelegatorGrant grant + +-- Witnesses extension-Grants that the topic has sent, extending chains from +-- its components/subprojects or projects/superteams + +PermitTopicExtendLocal + permit PermitPersonSendDelegatorId + topic PermitTopicEnableLocalId + grant OutboxItemId + + UniquePermitTopicExtendLocal permit + UniquePermitTopicExtendLocalTopic topic + UniquePermitTopicExtendLocalGrant grant + +PermitTopicExtendRemote + permit PermitPersonSendDelegatorId + topic PermitTopicEnableRemoteId + grant RemoteActivityId + + UniquePermitTopicExtendRemote permit + UniquePermitTopicExtendRemoteTopic topic + UniquePermitTopicExtendRemoteGrant grant + ------------------------------------------------------------------------------ -- Components, from project perspective ------------------------------------------------------------------------------