S2S: Person Grant handler: Handle component-mode Grants too

This commit is contained in:
Pere Lev 2023-09-09 17:01:18 +03:00
parent 4ac73a9515
commit fa43a49b16
No known key found for this signature in database
GPG key ID: 5252C5C863E5E57D

View file

@ -438,6 +438,36 @@ personCreateNote now recipPersonID (Verse authorIdMsig body) note = do
-- Access -- Access
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
-- Meaning: Someone is adding something to something
-- Behavior:
-- * Insert to my inbox
personAdd
:: UTCTime
-> PersonId
-> Verse
-> AP.Add URIMode
-> ActE (Text, Act (), Next)
personAdd now recipPersonID (Verse authorIdMsig body) add = do
-- Check input
let author = bimap (view _1) (remoteAuthorURI . view _1) authorIdMsig
_ <- parseAdd author add
maybeNew <- withDBExcept $ do
-- Grab me from DB
(personRecip, actorRecip) <- lift $ do
p <- getJust recipPersonID
(p,) <$> getJust (personActor p)
maybeAddDB <- lift $ insertToInbox now authorIdMsig body (actorInbox actorRecip) True
for maybeAddDB $ \ _addDB ->
return $ personActor personRecip
case maybeNew of
Nothing -> done "I already have this activity in my inbox"
Just _actorID -> done "Inserted this Add to my inbox"
-- Meaning: Someone invited someone to a resource -- Meaning: Someone invited someone to a resource
-- Behavior: -- Behavior:
-- * Insert to my inbox -- * Insert to my inbox
@ -579,10 +609,11 @@ personGrant now recipPersonID (Verse authorIdMsig body) grant = do
-- Check input -- Check input
target <- do target <- do
h <- lift $ objUriAuthority <$> getActorURI authorIdMsig --h <- lift $ objUriAuthority <$> getActorURI authorIdMsig
(_role, resource, recip, _mresult, _mstart, _mend) <- parseGrant h grant (_role, resource, recip, _mresult, _mstart, _mend, _usage, _mdeleg) <-
parseGrant' grant
case (recip, authorIdMsig) of case (recip, authorIdMsig) of
(Left (GrantRecipPerson p), Left (LocalActorPerson p', _, _)) (Left (GrantRecipPerson' p), Left (LocalActorPerson p', _, _))
| p == p' -> | p == p' ->
throwE "Grant sender and target are the same local Person" throwE "Grant sender and target are the same local Person"
(Right uRecip, Right (author, _, _)) (Right uRecip, Right (author, _, _))
@ -606,7 +637,7 @@ personGrant now recipPersonID (Verse authorIdMsig body) grant = do
Just _actorID -> do Just _actorID -> do
let targetIsRecip = let targetIsRecip =
case target of case target of
Left (GrantRecipPerson p) -> p == recipPersonID Left (GrantRecipPerson' p) -> p == recipPersonID
_ -> False _ -> False
if not targetIsRecip if not targetIsRecip
then done "I'm not the target; Inserted to inbox" then done "I'm not the target; Inserted to inbox"
@ -643,6 +674,7 @@ personBehavior :: UTCTime -> PersonId -> VerseExt -> ActE (Text, Act (), Next)
personBehavior now personID (Left verse@(Verse _authorIdMsig body)) = personBehavior now personID (Left verse@(Verse _authorIdMsig body)) =
case AP.activitySpecific $ actbActivity body of case AP.activitySpecific $ actbActivity body of
AP.AcceptActivity accept -> personAccept now personID verse accept AP.AcceptActivity accept -> personAccept now personID verse accept
AP.AddActivity add -> personAdd now personID verse add
AP.CreateActivity (AP.Create obj mtarget) -> AP.CreateActivity (AP.Create obj mtarget) ->
case obj of case obj of
AP.CreateNote _ note -> AP.CreateNote _ note ->