1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2024-12-27 03:24:52 +09:00

Web.ActivityPub: Add Grant 'allows' & 'delegates' fields

This commit is contained in:
Pere Lev 2023-05-30 14:34:37 +03:00
parent 621275e257
commit cc135692c0
No known key found for this signature in database
GPG key ID: 5252C5C863E5E57D
4 changed files with 43 additions and 2 deletions

View file

@ -368,6 +368,8 @@ acceptC (Entity senderPersonID senderPerson) senderActor maybeCap localRecips re
, grantResult = Nothing
, grantStart = Nothing
, grantEnd = Nothing
, grantAllows = Invoke
, grantDelegates = Nothing
}
}
@ -1156,6 +1158,8 @@ createPatchTrackerC (Entity pidUser personUser) senderActor maybeCap localRecips
, grantResult = Nothing
, grantStart = Nothing
, grantEnd = Nothing
, grantAllows = Invoke
, grantDelegates = Nothing
}
}
@ -1384,6 +1388,8 @@ createRepositoryC (Entity pidUser personUser) senderActor maybeCap localRecips r
, grantResult = Nothing
, grantStart = Nothing
, grantEnd = Nothing
, grantAllows = Invoke
, grantDelegates = Nothing
}
}
@ -1638,6 +1644,8 @@ createTicketTrackerC (Entity pidUser personUser) senderActor maybeCap localRecip
, grantResult = Nothing
, grantStart = Nothing
, grantEnd = Nothing
, grantAllows = Invoke
, grantDelegates = Nothing
}
}

View file

@ -166,8 +166,14 @@ parseGrant
, Maybe UTCTime
, Maybe UTCTime
)
parseGrant h (AP.Grant object context target mresult mstart mend) = do
parseGrant h (AP.Grant object context target mresult mstart mend allows deleg) = do
verifyRole object
case allows of
AP.Invoke -> pure ()
_ -> throwE "Grant.allows isn't invoke"
case deleg of
Nothing -> pure ()
Just _ -> throwE "Grant.delegates is specified"
(,,,,)
<$> parseContext context
<*> parseTarget target

View file

@ -554,6 +554,8 @@ topicAcceptF topicActor topicResource now recipHash author body mfwd luAccept ac
, AP.grantResult = Nothing
, AP.grantStart = Nothing
, AP.grantEnd = Nothing
, AP.grantAllows = AP.Invoke
, AP.grantDelegates = Nothing
}
}

View file

@ -63,6 +63,7 @@ module Web.ActivityPub
, Branch (..)
, Role (..)
, Duration (..)
, Usage (..)
-- * Activity
, Accept (..)
@ -1548,6 +1549,24 @@ instance ToJSON Duration where
toEncoding (Duration i) =
toEncoding $ T.concat ["PT", T.pack $ show i, "S"]
data Usage = GatherAndConvey | Distribute | Invoke deriving Eq
instance FromJSON Usage where
parseJSON = withText "Usage" parse
where
parse "gatherAndConvey" = pure GatherAndConvey
parse "distribute" = pure Distribute
parse "invoke" = pure Invoke
parse t = fail $ "Unknown usage: " ++ T.unpack t
instance ToJSON Usage where
toJSON = error "toJSON Usage"
toEncoding u =
toEncoding $ case u of
GatherAndConvey -> "gatherAndConvey" :: Text
Distribute -> "distribute"
Invoke -> "invoke"
data Accept u = Accept
{ acceptObject :: ObjURI u
, acceptResult :: Maybe LocalURI
@ -1710,6 +1729,8 @@ data Grant u = Grant
, grantResult :: Maybe (LocalURI, Maybe Duration)
, grantStart :: Maybe UTCTime
, grantEnd :: Maybe UTCTime
, grantAllows :: Usage
, grantDelegates :: Maybe (ObjURI u)
}
parseGrant :: UriMode u => Authority u -> Object -> Parser (Grant u)
@ -1726,9 +1747,11 @@ parseGrant h o =
)
<*> o .:? "startTime"
<*> o .:? "endTime"
<*> o .: "allows"
<*> o .:? "delegates"
encodeGrant :: UriMode u => Authority u -> Grant u -> Series
encodeGrant h (Grant obj context target mresult mstart mend)
encodeGrant h (Grant obj context target mresult mstart mend allows mdelegates)
= "object" .=+ obj
<> "context" .= ObjURI h context
<> "target" .= target
@ -1742,6 +1765,8 @@ encodeGrant h (Grant obj context target mresult mstart mend)
)
<> "startTime" .=? mstart
<> "endTime" .=? mend
<> "allows" .= allows
<> "delegates" .=? mdelegates
data Invite u = Invite
{ inviteInstrument :: Either Role (ObjURI u)