From 3fb5e92f4407f754f962ae56a0f43aace4bbff8f Mon Sep 17 00:00:00 2001 From: Pere Lev Date: Tue, 21 May 2024 02:15:14 +0300 Subject: [PATCH] S2S: Project: Accept: When removing a child, revoke extensions to teams --- src/Vervis/Actor/Project.hs | 108 ++++++++++++++++++++++-------------- 1 file changed, 66 insertions(+), 42 deletions(-) diff --git a/src/Vervis/Actor/Project.hs b/src/Vervis/Actor/Project.hs index 76f4467..da9d543 100644 --- a/src/Vervis/Actor/Project.hs +++ b/src/Vervis/Actor/Project.hs @@ -82,11 +82,31 @@ import Vervis.Web.Collab -- Meaning: An actor accepted something -- Behavior: --- * Check if I know the activity that's being Accepted: +-- * == Collab mode == -- * Is it an Invite to be a collaborator in me? -- * Verify the Accept is by the Invite target -- * Is it a Join to be a collaborator in me? -- * Verify the Accept is authorized +-- +-- * In collab mode, verify the Collab isn't enabled yet +-- +-- * Insert the Accept to my inbox +-- +-- * In collab mode, record the Accept and enable the Collab in DB +-- +-- * Forward the Accept to my followers +-- +-- * Possibly send a Grant/Accept: +-- * For Invite-collab mode: +-- * Regular collaborator-Grant +-- * To: Accepter (i.e. Invite target) +-- * CC: Invite sender, Accepter's followers, my followers +-- * For Join-as-collab mode: +-- * Regular collaborator-Grant +-- * To: Join sender +-- * CC: Accept sender, Join sender's followers, my followers +-- +-- * == Component mode == -- * Is it an Invite to be a component of me? -- * Nothing to check at this point -- * Is it an Add to be a component of me? @@ -96,6 +116,40 @@ import Vervis.Web.Collab -- * Verify I've seen the component-Accept for this Add -- * Verify the new Accept is authorized -- +-- * In component mode, verify the Component isn't enabled yet +-- +-- * Insert the Accept to my inbox +-- +-- * In Invite-component mode, +-- * If sender is component, record the Accept and enable the Component +-- in DB +-- * Otherwise, nothing at this point +-- * In Add-component mode, +-- * If the sender is the component, record the Accept into the +-- Component record in DB +-- * Otherwise, i.e. sender isn't the component, record the Accept and +-- enable the Component in DB +-- +-- * Forward the Accept to my followers +-- +-- * Possibly send a Grant/Accept: +-- * For Invite-component mode: +-- * Only if sender is the component +-- * delegator-Grant +-- * To: Component +-- * CC: +-- - Component's followers +-- - My followers +-- * For Add-component mode: +-- * Only if sender isn't the component +-- * delegator-Grant +-- * To: Component +-- * CC: +-- - Component's followers +-- - My followers +-- - The Accept's sender +-- +-- * == Child-parent mode == -- * Give me a new child active SourceOriginUs -- * Verify we haven't yet seen child's Accept -- * Give me a new child passive SourceOriginThem @@ -113,24 +167,8 @@ import Vervis.Web.Collab -- * Verify the accept is authorized -- * Otherwise respond with error, no Accept is needed -- --- * If it's none of these, respond with error --- --- * In collab mode, verify the Collab isn't enabled yet --- * In component mode, verify the Component isn't enabled yet --- -- * Insert the Accept to my inbox -- --- * In collab mode, record the Accept and enable the Collab in DB --- * In Invite-component mode, --- * If sender is component, record the Accept and enable the Component --- in DB --- * Otherwise, nothing at this point --- * In Add-component mode, --- * If the sender is the component, record the Accept into the --- Component record in DB --- * Otherwise, i.e. sender isn't the component, record the Accept and --- enable the Component in DB --- -- * In child-active mode, -- * If sender is the child, record the Accept into the Source record -- * Prepare to send degelator-Grant @@ -147,30 +185,6 @@ import Vervis.Web.Collab -- * Forward the Accept to my followers -- -- * Possibly send a Grant/Accept: --- * For Invite-collab mode: --- * Regular collaborator-Grant --- * To: Accepter (i.e. Invite target) --- * CC: Invite sender, Accepter's followers, my followers --- * For Join-as-collab mode: --- * Regular collaborator-Grant --- * To: Join sender --- * CC: Accept sender, Join sender's followers, my followers --- * For Invite-component mode: --- * Only if sender is the component --- * delegator-Grant --- * To: Component --- * CC: --- - Component's followers --- - My followers --- * For Add-component mode: --- * Only if sender isn't the component --- * delegator-Grant --- * To: Component --- * CC: --- - Component's followers --- - My followers --- - The Accept's sender --- -- * Child-active -- * If sender is the child -- * delegator-Grant @@ -1212,6 +1226,7 @@ projectAccept now projectID (Verse authorIdMsig body) accept = do -- Grab extension-Grants that I'm about to revoke gathers <- selectList [SourceUsGatherSource ==. sendID] [] leafs <- selectList [SourceUsLeafSource ==. sendID] [] + conveys <- selectList [SourceUsConveySource ==. sendID] [] -- Delete the whole Source record deleteWhere [SourceRemoveSend ==. sendID] @@ -1225,6 +1240,10 @@ projectAccept now projectID (Verse authorIdMsig body) accept = do deleteWhere [SourceUsLeafToLocalLeaf <-. leafIDs] deleteWhere [SourceUsLeafToRemoteLeaf <-. leafIDs] deleteWhere [SourceUsLeafId <-. leafIDs] + let conveyIDs = map entityKey conveys + deleteWhere [SourceUsConveyFromLocalConvey <-. conveyIDs] + deleteWhere [SourceUsConveyFromRemoteConvey <-. conveyIDs] + deleteWhere [SourceUsConveyId <-. conveyIDs] case child of Left (localID, _) -> do acceptID <- getKeyByJust $ UniqueSourceThemAcceptLocal localID @@ -1297,7 +1316,12 @@ projectAccept now projectID (Verse authorIdMsig body) accept = do recip , grantID ) - revokes <- for (revokesG ++ revokesL) $ \ (actor, grantID) -> do + revokesC <- for conveys $ \ (Entity _ (SourceUsConvey _ startID grantID)) -> do + SquadUsStart acceptID _ <- getJust startID + SquadUsAccept squadID _ <- getJust acceptID + team <- bimap (LocalActorGroup . snd) snd <$> getSquadTeam squadID + return (team, grantID) + revokes <- for (revokesG ++ revokesL ++ revokesC) $ \ (actor, grantID) -> do ext@(actionExt, _, _, _) <- prepareExtRevoke actor grantID let recipByKey = LocalActorProject projectID extID <- insertEmptyOutboxItem' (actorOutbox actorRecip) now