DB: Permit: Use Resource instead of Actor in extension resource

This commit is contained in:
Pere Lev 2024-04-20 04:15:59 +03:00
parent acdce58fc6
commit 4881154579
No known key found for this signature in database
GPG key ID: 5252C5C863E5E57D
11 changed files with 23 additions and 23 deletions

View file

@ -900,9 +900,10 @@ personGrant now recipPersonID (Verse authorIdMsig body) grant = do
AP.RXRole r -> pure r
AP.RXDelegator -> throwE "I've been delegated a Grant with role being delegate"
resourceDB <- bitraverse
(\ la ->
withDBExcept $ localActorID <$>
getLocalActorEntityE la "Extension-Grant resource not found in DB"
(\ la -> do
lr <- fromMaybeE (actorToResource la) "Got an extension-Grant with resource being a local Person"
withDBExcept $ localResourceID <$>
getLocalResourceEntityE lr "Extension-Grant resource not found in DB"
)
(\ (ObjURI h lu) -> do
manager <- asksEnv envHttpManager
@ -1057,7 +1058,7 @@ personGrant now recipPersonID (Verse authorIdMsig body) grant = do
return extendID
_ -> error "personGrant impossible 2"
lift $ case resourceDB of
Left actorID -> insert_ $ PermitTopicExtendResourceLocal extendID actorID
Left resourceID -> insert_ $ PermitTopicExtendResourceLocal extendID resourceID
Right actorID -> insert_ $ PermitTopicExtendResourceRemote extendID actorID
)

View file

@ -495,13 +495,13 @@ fillPermitRecords = do
(_doc, g) <- getGrantActivityBody ext
return $ AP.grantContext g
result <- runExceptT $ do
a <- parseActorURI uResource
a <- parseResourceURI uResource
case a of
Left la -> runSiteDBExcept $ do
actorID <-
localActorID <$>
getLocalActorEntityE la "Extension-Grant resource not found in DB"
lift $ insert_ $ PermitTopicExtendResourceLocal extendID actorID
Left lr -> runSiteDBExcept $ do
resourceID <-
localResourceID <$>
getLocalResourceEntityE lr "Extension-Grant resource not found in DB"
lift $ insert_ $ PermitTopicExtendResourceLocal extendID resourceID
Right (ObjURI h lu) -> do
actorID <- do
manager <- asksSite appHttpManager

View file

@ -261,7 +261,7 @@ getDeckTicketsR deckHash = selectRep $ do
mp <- maybeAuthId
case mp of
Nothing -> pure []
Just personID -> runDB $ getPermitsForResource personID (Left $ deckActor deck)
Just personID -> runDB $ getPermitsForResource personID (Left $ deckResource deck)
case mpage of
Nothing -> redirectFirstPage here
Just (rows, navModel) ->

View file

@ -170,7 +170,7 @@ getGroupR groupHash = do
permits <-
case mp of
Nothing -> pure []
Just personID -> getPermitsForResource personID (Left aid)
Just personID -> getPermitsForResource personID (Left $ groupResource g)
return (g, a, sigKeys, permits)
encodeRouteLocal <- getEncodeRouteLocal

View file

@ -215,7 +215,7 @@ getLoomClothsR loomHash = selectRep $ do
mp <- maybeAuthId
case mp of
Nothing -> pure []
Just personID -> runDB $ getPermitsForResource personID (Left $ loomActor loom)
Just personID -> runDB $ getPermitsForResource personID (Left $ loomResource loom)
case mpage of
Nothing -> redirectFirstPage here
Just (rows, navModel) ->

View file

@ -134,7 +134,7 @@ getProjectR projectHash = do
permits <-
case mp of
Nothing -> pure []
Just personID -> getPermitsForResource personID (Left aid)
Just personID -> getPermitsForResource personID (Left $ projectResource d)
return (d, a, sigKeys, permits)
encodeRouteLocal <- getEncodeRouteLocal

View file

@ -3464,7 +3464,6 @@ changes hLocal ctx =
"resource"
"Resource"
-- 609
{-
, addFieldRefRequired''
"PermitTopicExtendResourceLocal"
(do inboxID <- insert Inbox604
@ -3488,7 +3487,8 @@ changes hLocal ctx =
)
"resource"
"Resource"
-}
-- 610
, removeField "PermitTopicExtendResourceLocal" "actor"
]
migrateDB

View file

@ -1067,7 +1067,7 @@ getGrantActivityBody k = do
getPermitsForResource
:: MonadIO m
=> PersonId
-> Either ActorId RemoteActorId
-> Either ResourceId RemoteActorId
-> ReaderT SqlBackend m
[ ( Either (LocalActorBy Key, OutboxItemId) FedURI
, AP.Role
@ -1079,7 +1079,7 @@ getPermitsForResource
getPermitsForResource personID actor = do
exts <-
case actor of
Left actorID ->
Left resourceID ->
E.select $ E.from $ \ (permit `E.InnerJoin` gesture `E.InnerJoin` send `E.InnerJoin` extend `E.InnerJoin` resource) -> do
E.on $ extend E.^. PermitTopicExtendId E.==. resource E.^. PermitTopicExtendResourceLocalPermit
E.on $ send E.^. PermitPersonSendDelegatorId E.==. extend E.^. PermitTopicExtendPermit
@ -1087,7 +1087,7 @@ getPermitsForResource personID actor = do
E.on $ permit E.^. PermitId E.==. gesture E.^. PermitPersonGesturePermit
E.where_ $
permit E.^. PermitPerson E.==. E.val personID E.&&.
resource E.^. PermitTopicExtendResourceLocalActor E.==. E.val actorID
resource E.^. PermitTopicExtendResourceLocalResource E.==. E.val resourceID
return
( permit E.^. PermitId
, extend E.^. PermitTopicExtendId

View file

@ -101,7 +101,7 @@ getDarcsRepoSource repository actor repo dir loomIDs = do
mp <- maybeAuthId
case mp of
Nothing -> pure []
Just personID -> runDB $ getPermitsForResource personID (Left $ repoActor repository)
Just personID -> runDB $ getPermitsForResource personID (Left $ repoResource repository)
defaultLayout $ do
hashLoom <- getEncodeKeyHashid
host <- asksSite siteInstanceHost

View file

@ -116,7 +116,7 @@ getGitRepoSource repository actor repo ref dir loomIDs = do
mp <- maybeAuthId
case mp of
Nothing -> pure []
Just personID -> runDB $ getPermitsForResource personID (Left $ repoActor repository)
Just personID -> runDB $ getPermitsForResource personID (Left $ repoResource repository)
defaultLayout $ do
hashLoom <- getEncodeKeyHashid
host <- asksSite siteInstanceHost

View file

@ -947,8 +947,7 @@ PermitTopicExtendRemote
PermitTopicExtendResourceLocal
permit PermitTopicExtendId
actor ActorId
--resource ResourceId
resource ResourceId
UniquePermitTopicExtendResourceLocal permit