Web.ActivityPub: Add Grant startTime and endTime
This commit is contained in:
parent
a22aeb85d0
commit
ba02d62eb5
5 changed files with 29 additions and 6 deletions
|
@ -366,6 +366,8 @@ acceptC (Entity senderPersonID senderPerson) senderActor maybeCap localRecips re
|
||||||
, grantContext = encodeRouteLocal $ renderLocalActor topicHash
|
, grantContext = encodeRouteLocal $ renderLocalActor topicHash
|
||||||
, grantTarget = encodeRouteHome $ PersonR recipHash
|
, grantTarget = encodeRouteHome $ PersonR recipHash
|
||||||
, grantResult = Nothing
|
, grantResult = Nothing
|
||||||
|
, grantStart = Nothing
|
||||||
|
, grantEnd = Nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1152,6 +1154,8 @@ createPatchTrackerC (Entity pidUser personUser) senderActor maybeCap localRecips
|
||||||
, grantContext = encodeRouteLocal $ LoomR loomHash
|
, grantContext = encodeRouteLocal $ LoomR loomHash
|
||||||
, grantTarget = encodeRouteHome $ PersonR adminHash
|
, grantTarget = encodeRouteHome $ PersonR adminHash
|
||||||
, grantResult = Nothing
|
, grantResult = Nothing
|
||||||
|
, grantStart = Nothing
|
||||||
|
, grantEnd = Nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1376,6 +1380,8 @@ createRepositoryC (Entity pidUser personUser) senderActor maybeCap localRecips r
|
||||||
, grantContext = encodeRouteLocal $ RepoR repoHash
|
, grantContext = encodeRouteLocal $ RepoR repoHash
|
||||||
, grantTarget = encodeRouteHome $ PersonR adminHash
|
, grantTarget = encodeRouteHome $ PersonR adminHash
|
||||||
, grantResult = Nothing
|
, grantResult = Nothing
|
||||||
|
, grantStart = Nothing
|
||||||
|
, grantEnd = Nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1626,6 +1632,8 @@ createTicketTrackerC (Entity pidUser personUser) senderActor maybeCap localRecip
|
||||||
, grantContext = encodeRouteLocal $ DeckR deckHash
|
, grantContext = encodeRouteLocal $ DeckR deckHash
|
||||||
, grantTarget = encodeRouteHome $ PersonR adminHash
|
, grantTarget = encodeRouteHome $ PersonR adminHash
|
||||||
, grantResult = Nothing
|
, grantResult = Nothing
|
||||||
|
, grantStart = Nothing
|
||||||
|
, grantEnd = Nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -165,7 +165,7 @@ personGrant now recipPersonID author body mfwd luGrant grant = do
|
||||||
-- Check input
|
-- Check input
|
||||||
(_remoteResource, recipient) <- do
|
(_remoteResource, recipient) <- do
|
||||||
let u@(ObjURI h _) = remoteAuthorURI author
|
let u@(ObjURI h _) = remoteAuthorURI author
|
||||||
(resource, recip, _mresult) <- parseGrant h grant
|
(resource, recip, _mresult, _mstart, _mend) <- parseGrant h grant
|
||||||
resourceURI <-
|
resourceURI <-
|
||||||
case resource of
|
case resource of
|
||||||
Right r -> return (u, r)
|
Right r -> return (u, r)
|
||||||
|
|
|
@ -41,6 +41,7 @@ import Database.Persist.Types
|
||||||
import GHC.Generics
|
import GHC.Generics
|
||||||
|
|
||||||
import Control.Concurrent.Actor
|
import Control.Concurrent.Actor
|
||||||
|
import Data.Time.Clock
|
||||||
import Network.FedURI
|
import Network.FedURI
|
||||||
import Web.Actor
|
import Web.Actor
|
||||||
import Web.Actor.Persist
|
import Web.Actor.Persist
|
||||||
|
@ -162,10 +163,12 @@ parseGrant
|
||||||
( Either (GrantResourceBy Key) LocalURI
|
( Either (GrantResourceBy Key) LocalURI
|
||||||
, Either (GrantRecipBy Key) FedURI
|
, Either (GrantRecipBy Key) FedURI
|
||||||
, Maybe (LocalURI, Maybe Int)
|
, Maybe (LocalURI, Maybe Int)
|
||||||
|
, Maybe UTCTime
|
||||||
|
, Maybe UTCTime
|
||||||
)
|
)
|
||||||
parseGrant h (AP.Grant object context target mresult) = do
|
parseGrant h (AP.Grant object context target mresult mstart mend) = do
|
||||||
verifyRole object
|
verifyRole object
|
||||||
(,,)
|
(,,,,)
|
||||||
<$> parseContext context
|
<$> parseContext context
|
||||||
<*> parseTarget target
|
<*> parseTarget target
|
||||||
<*> pure
|
<*> pure
|
||||||
|
@ -173,6 +176,8 @@ parseGrant h (AP.Grant object context target mresult) = do
|
||||||
(\ (lu, md) -> (lu, (\ (AP.Duration i) -> i) <$> md))
|
(\ (lu, md) -> (lu, (\ (AP.Duration i) -> i) <$> md))
|
||||||
mresult
|
mresult
|
||||||
)
|
)
|
||||||
|
<*> pure mstart
|
||||||
|
<*> pure mend
|
||||||
where
|
where
|
||||||
verifyRole (Left AP.RoleAdmin) = pure ()
|
verifyRole (Left AP.RoleAdmin) = pure ()
|
||||||
verifyRole (Right _) =
|
verifyRole (Right _) =
|
||||||
|
|
|
@ -552,6 +552,8 @@ topicAcceptF topicActor topicResource now recipHash author body mfwd luAccept ac
|
||||||
, AP.grantContext = encodeRouteLocal $ renderLocalActor topicByHash
|
, AP.grantContext = encodeRouteLocal $ renderLocalActor topicByHash
|
||||||
, AP.grantTarget = remoteAuthorURI author
|
, AP.grantTarget = remoteAuthorURI author
|
||||||
, AP.grantResult = Nothing
|
, AP.grantResult = Nothing
|
||||||
|
, AP.grantStart = Nothing
|
||||||
|
, AP.grantEnd = Nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1675,6 +1675,8 @@ data Grant u = Grant
|
||||||
, grantContext :: LocalURI
|
, grantContext :: LocalURI
|
||||||
, grantTarget :: ObjURI u
|
, grantTarget :: ObjURI u
|
||||||
, grantResult :: Maybe (LocalURI, Maybe Duration)
|
, grantResult :: Maybe (LocalURI, Maybe Duration)
|
||||||
|
, grantStart :: Maybe UTCTime
|
||||||
|
, grantEnd :: Maybe UTCTime
|
||||||
}
|
}
|
||||||
|
|
||||||
parseGrant :: UriMode u => Authority u -> Object -> Parser (Grant u)
|
parseGrant :: UriMode u => Authority u -> Object -> Parser (Grant u)
|
||||||
|
@ -1683,24 +1685,30 @@ parseGrant h o =
|
||||||
<$> o .:+ "object"
|
<$> o .:+ "object"
|
||||||
<*> withAuthorityO h (o .: "context")
|
<*> withAuthorityO h (o .: "context")
|
||||||
<*> o .: "target"
|
<*> o .: "target"
|
||||||
<*> do mres <- o .:+? "result"
|
<*> (do mres <- o .:+? "result"
|
||||||
for mres $ \case
|
for mres $ \case
|
||||||
Left u -> (,Nothing) <$> withAuthorityO h (pure u)
|
Left u -> (,Nothing) <$> withAuthorityO h (pure u)
|
||||||
Right r ->
|
Right r ->
|
||||||
(,) <$> withAuthorityO h (r .: "id") <*> r .:? "duration"
|
(,) <$> withAuthorityO h (r .: "id") <*> r .:? "duration"
|
||||||
|
)
|
||||||
|
<*> o .:? "startTime"
|
||||||
|
<*> o .:? "endTime"
|
||||||
|
|
||||||
encodeGrant :: UriMode u => Authority u -> Grant u -> Series
|
encodeGrant :: UriMode u => Authority u -> Grant u -> Series
|
||||||
encodeGrant h (Grant obj context target mresult)
|
encodeGrant h (Grant obj context target mresult mstart mend)
|
||||||
= "object" .=+ obj
|
= "object" .=+ obj
|
||||||
<> "context" .= ObjURI h context
|
<> "context" .= ObjURI h context
|
||||||
<> "target" .= target
|
<> "target" .= target
|
||||||
<> case mresult of
|
<> (case mresult of
|
||||||
Nothing -> mempty
|
Nothing -> mempty
|
||||||
Just (result, mduration) ->
|
Just (result, mduration) ->
|
||||||
"result" `pair` pairs
|
"result" `pair` pairs
|
||||||
( "id" .= ObjURI h result
|
( "id" .= ObjURI h result
|
||||||
<> "duration" .=? mduration
|
<> "duration" .=? mduration
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
<> "startTime" .=? mstart
|
||||||
|
<> "endTime" .=? mend
|
||||||
|
|
||||||
data Invite u = Invite
|
data Invite u = Invite
|
||||||
{ inviteInstrument :: Either Role (ObjURI u)
|
{ inviteInstrument :: Either Role (ObjURI u)
|
||||||
|
|
Loading…
Reference in a new issue