UI: In my-grants-for-given-resource display, list direct grants as well

Previously, only extensions were being displayed. Adding direct grants
required DB schema changes, which the previous huge commit did.
This commit is contained in:
Pere Lev 2024-04-26 03:00:59 +03:00
parent 888a30e989
commit 07d9f9adab
No known key found for this signature in database
GPG key ID: 5252C5C863E5E57D
2 changed files with 90 additions and 38 deletions

View file

@ -960,12 +960,57 @@ getPermitsForResource
-> ReaderT SqlBackend m -> ReaderT SqlBackend m
[ ( Either (LocalActorBy Key, OutboxItemId) FedURI [ ( Either (LocalActorBy Key, OutboxItemId) FedURI
, AP.Role , AP.Role
, Either , Maybe
(Either
(LocalActorBy Key, Actor) (LocalActorBy Key, Actor)
(Instance, RemoteObject, RemoteActor) (Instance, RemoteObject, RemoteActor)
) )
)
] ]
getPermitsForResource personID actor = do getPermitsForResource personID actor = do
direct <-
bitraverse
(\ resourceID ->
fmap (resourceID,) $
E.select $ E.from $ \ (permit `E.InnerJoin` topic `E.InnerJoin` enable) -> do
E.on $ topic E.^. PermitTopicLocalId E.==. enable E.^. PermitTopicEnableLocalTopic
E.on $ permit E.^. PermitId E.==. topic E.^. PermitTopicLocalPermit
E.where_ $
permit E.^. PermitPerson E.==. E.val personID E.&&.
topic E.^. PermitTopicLocalTopic E.==. E.val resourceID
return
( permit E.^. PermitRole
, enable E.^. PermitTopicEnableLocalGrant
)
)
(\ actorID ->
E.select $ E.from $ \ (permit `E.InnerJoin` topic `E.InnerJoin` enable) -> do
E.on $ topic E.^. PermitTopicRemoteId E.==. enable E.^. PermitTopicEnableRemoteTopic
E.on $ permit E.^. PermitId E.==. topic E.^. PermitTopicRemotePermit
E.where_ $
permit E.^. PermitPerson E.==. E.val personID E.&&.
topic E.^. PermitTopicRemoteActor E.==. E.val actorID
return
( permit E.^. PermitRole
, enable E.^. PermitTopicEnableRemoteGrant
)
)
actor
directsFinal <-
case direct of
Left (resourceID, ds) -> do
lr <- getLocalResource resourceID
let la = resourceToActor lr
return $
map
(\ (E.Value role, E.Value grantID) ->
(Left (la, grantID), role, Nothing)
)
ds
Right ds -> for ds $ \ (E.Value role, E.Value grantID) -> do
grant <- getJust grantID
u <- getRemoteActivityURI grant
return (Right u, role, Nothing)
exts <- exts <-
case actor of case actor of
Left resourceID -> Left resourceID ->
@ -996,6 +1041,7 @@ getPermitsForResource personID actor = do
, extend E.^. PermitTopicExtendId , extend E.^. PermitTopicExtendId
, extend E.^. PermitTopicExtendRole , extend E.^. PermitTopicExtendRole
) )
extsFinal <-
for exts $ \ (E.Value permitID, E.Value extendID, E.Value role) -> do for exts $ \ (E.Value permitID, E.Value extendID, E.Value role) -> do
sender <- sender <-
requireEitherAlt requireEitherAlt
@ -1026,4 +1072,5 @@ getPermitsForResource personID actor = do
grant <- getJust grantID grant <- getJust grantID
u <- getRemoteActivityURI grant u <- getRemoteActivityURI grant
return (Right u, Right (inztance, remoteObject, remoteActor)) return (Right u, Right (inztance, remoteObject, remoteActor))
return (uExt, role, via) return (uExt, role, Just via)
return $ directsFinal ++ extsFinal

View file

@ -182,7 +182,11 @@ actorLinkFedW (Right (inztance, object, actor)) =
personPermitsForResourceW personPermitsForResourceW
:: [ ( Either (LocalActorBy Key, OutboxItemId) FedURI :: [ ( Either (LocalActorBy Key, OutboxItemId) FedURI
, AP.Role , AP.Role
, Either (LocalActorBy Key, Actor) (Instance, RemoteObject, RemoteActor) , Maybe
(Either
(LocalActorBy Key, Actor)
(Instance, RemoteObject, RemoteActor)
)
) )
] ]
-> Widget -> Widget
@ -194,7 +198,7 @@ personPermitsForResourceW permits = do
[whamlet| [whamlet|
<h3>My access <h3>My access
<ul> <ul>
$forall (u, role, via) <- permits $forall (u, role, mvia) <- permits
<li> <li>
$case u $case u
$of Left (la, i) $of Left (la, i)
@ -204,6 +208,7 @@ personPermitsForResourceW permits = do
<a href="#{renderObjURI u'}"> <a href="#{renderObjURI u'}">
Grant Grant
[ #{show role} ] # [ #{show role} ] #
$maybe via <- mvia
\ via # \ via #
[ ^{actorLinkFedW via} ] [ ^{actorLinkFedW via} ]
|] |]