DB: Add a Resource table, and use it in all local Actors except Person

This commit is contained in:
Pere Lev 2024-04-20 03:52:34 +03:00
parent fc9d56dd34
commit acdce58fc6
No known key found for this signature in database
GPG key ID: 5252C5C863E5E57D
12 changed files with 547 additions and 8 deletions

View file

@ -0,0 +1,4 @@
Resource
actor ActorId
UniqueResource actor

View file

@ -0,0 +1,84 @@
OutboxItem
Workflow
PermitTopicExtend
Inbox
Outbox
FollowerSet
Actor
name Text
desc Text
createdAt UTCTime
inbox InboxId
outbox OutboxId
followers FollowerSetId
justCreatedBy ActorId Maybe
UniqueActorInbox inbox
UniqueActorOutbox outbox
UniqueActorFollowers followers
Resource
actor ActorId
UniqueResource actor
Group
actor ActorId
resource ResourceId
create OutboxItemId
UniqueGroupActor actor
UniqueGroupCreate create
Project
actor ActorId
resource ResourceId
create OutboxItemId
UniqueProjectActor actor
UniqueProjectCreate create
Deck
actor ActorId
resource ResourceId
workflow WorkflowId
nextTicket Int
wiki RepoId Maybe
create OutboxItemId
UniqueDeckActor actor
UniqueDeckCreate create
Loom
nextTicket Int
actor ActorId
resource ResourceId
repo RepoId
create OutboxItemId
UniqueLoomActor actor
UniqueLoomRepo repo
UniqueLoomCreate create
Repo
vcs VersionControlSystem
project DeckId Maybe
mainBranch Text
actor ActorId
resource ResourceId
create OutboxItemId
loom LoomId Maybe
UniqueRepoActor actor
UniqueRepoCreate create
PermitTopicExtendResourceLocal
permit PermitTopicExtendId
actor ActorId
resource ResourceId
UniquePermitTopicExtendResourceLocal permit

View file

@ -1131,9 +1131,11 @@ createPatchTrackerC (Entity pidUser personUser) senderActor maybeCap localRecips
insertLoom now name msummary obiidCreate repoID = do insertLoom now name msummary obiidCreate repoID = do
actor@(Entity actorID _) <- actor@(Entity actorID _) <-
insertActor now name (fromMaybe "" msummary) (Just $ personActor personUser) insertActor now name (fromMaybe "" msummary) (Just $ personActor personUser)
resourceID <- insert $ Resource actorID
loomID <- insert Loom loomID <- insert Loom
{ loomNextTicket = 1 { loomNextTicket = 1
, loomActor = actorID , loomActor = actorID
, loomResource = resourceID
, loomRepo = repoID , loomRepo = repoID
, loomCreate = obiidCreate , loomCreate = obiidCreate
} }
@ -1367,11 +1369,13 @@ createRepositoryC (Entity pidUser personUser) senderActor maybeCap localRecips r
insertRepo now name msummary createID = do insertRepo now name msummary createID = do
actor@(Entity actorID _) <- actor@(Entity actorID _) <-
insertActor now name (fromMaybe "" msummary) (Just $ personActor personUser) insertActor now name (fromMaybe "" msummary) (Just $ personActor personUser)
resourceID <- insert $ Resource actorID
repoID <- insert Repo repoID <- insert Repo
{ repoVcs = vcs { repoVcs = vcs
, repoProject = Nothing , repoProject = Nothing
, repoMainBranch = "main" , repoMainBranch = "main"
, repoActor = actorID , repoActor = actorID
, repoResource = resourceID
, repoCreate = createID , repoCreate = createID
, repoLoom = Nothing , repoLoom = Nothing
} }

View file

@ -1,6 +1,7 @@
{- This file is part of Vervis. {- This file is part of Vervis.
- -
- Written in 2019, 2020, 2022, 2023 by fr33domlover <fr33domlover@riseup.net>. - Written in 2019, 2020, 2022, 2023, 2024
- by fr33domlover <fr33domlover@riseup.net>.
- -
- Copying is an act of love. Please copy, reuse and share. - Copying is an act of love. Please copy, reuse and share.
- -
@ -24,7 +25,10 @@
module Vervis.Actor module Vervis.Actor
( -- * Local actors ( -- * Local actors
LocalActorBy (..) LocalActorBy (..)
, LocalResourceBy (..)
, LocalActor , LocalActor
, actorToResource
, resourceToActor
-- * Converting between KeyHashid, Key, Identity and Entity -- * Converting between KeyHashid, Key, Identity and Entity
-- --
@ -40,6 +44,17 @@ module Vervis.Actor
, unhashLocalActorE , unhashLocalActorE
, unhashLocalActor404 , unhashLocalActor404
, hashLocalResourcePure
, getHashLocalResource
, hashLocalResource
, unhashLocalResourcePure
, unhashLocalResource
, unhashLocalResourceF
, unhashLocalResourceM
, unhashLocalResourceE
, unhashLocalResource404
-- * Local recipient set -- * Local recipient set
, TicketRoutes (..) , TicketRoutes (..)
, ClothRoutes (..) , ClothRoutes (..)
@ -147,6 +162,14 @@ data LocalActorBy f
| LocalActorProject (f Project) | LocalActorProject (f Project)
deriving (Generic, FunctorB, ConstraintsB) deriving (Generic, FunctorB, ConstraintsB)
data LocalResourceBy f
= LocalResourceGroup (f Group)
| LocalResourceRepo (f Repo)
| LocalResourceDeck (f Deck)
| LocalResourceLoom (f Loom)
| LocalResourceProject (f Project)
deriving (Generic, FunctorB, ConstraintsB)
deriving instance AllBF Eq f LocalActorBy => Eq (LocalActorBy f) deriving instance AllBF Eq f LocalActorBy => Eq (LocalActorBy f)
deriving instance AllBF Ord f LocalActorBy => Ord (LocalActorBy f) deriving instance AllBF Ord f LocalActorBy => Ord (LocalActorBy f)
deriving instance AllBF Hashable f LocalActorBy => Hashable (LocalActorBy f) deriving instance AllBF Hashable f LocalActorBy => Hashable (LocalActorBy f)
@ -154,6 +177,21 @@ deriving instance AllBF Show f LocalActorBy => Show (LocalActorBy f)
type LocalActor = LocalActorBy KeyHashid type LocalActor = LocalActorBy KeyHashid
actorToResource = \case
LocalActorPerson _ -> Nothing
LocalActorGroup g -> Just $ LocalResourceGroup g
LocalActorRepo r -> Just $ LocalResourceRepo r
LocalActorDeck d -> Just $ LocalResourceDeck d
LocalActorLoom l -> Just $ LocalResourceLoom l
LocalActorProject j -> Just $ LocalResourceProject j
resourceToActor = \case
LocalResourceGroup g -> LocalActorGroup g
LocalResourceRepo r -> LocalActorRepo r
LocalResourceDeck d -> LocalActorDeck d
LocalResourceLoom l -> LocalActorLoom l
LocalResourceProject j -> LocalActorProject j
hashLocalActorPure hashLocalActorPure
:: HashidsContext -> LocalActorBy Key -> LocalActorBy KeyHashid :: HashidsContext -> LocalActorBy Key -> LocalActorBy KeyHashid
hashLocalActorPure ctx = f hashLocalActorPure ctx = f
@ -227,6 +265,77 @@ unhashLocalActor404 actor = maybe notFound return =<< unhashLocalActor actor
ctx <- asksSite siteHashidsContext ctx <- asksSite siteHashidsContext
return $ unhashLocalActorPure ctx byHash return $ unhashLocalActorPure ctx byHash
hashLocalResourcePure
:: HashidsContext -> LocalResourceBy Key -> LocalResourceBy KeyHashid
hashLocalResourcePure ctx = f
where
f (LocalResourceGroup g) = LocalResourceGroup $ encodeKeyHashidPure ctx g
f (LocalResourceRepo r) = LocalResourceRepo $ encodeKeyHashidPure ctx r
f (LocalResourceDeck d) = LocalResourceDeck $ encodeKeyHashidPure ctx d
f (LocalResourceLoom l) = LocalResourceLoom $ encodeKeyHashidPure ctx l
f (LocalResourceProject j) = LocalResourceProject $ encodeKeyHashidPure ctx j
getHashLocalResource
:: (MonadActor m, StageHashids (ActorEnv m))
=> m (LocalResourceBy Key -> LocalResourceBy KeyHashid)
getHashLocalResource = do
ctx <- asksEnv stageHashidsContext
return $ hashLocalResourcePure ctx
hashLocalResource
:: (MonadActor m, StageHashids (ActorEnv m))
=> LocalResourceBy Key -> m (LocalResourceBy KeyHashid)
hashLocalResource actor = do
hash <- getHashLocalResource
return $ hash actor
unhashLocalResourcePure
:: HashidsContext -> LocalResourceBy KeyHashid -> Maybe (LocalResourceBy Key)
unhashLocalResourcePure ctx = f
where
f (LocalResourceGroup g) = LocalResourceGroup <$> decodeKeyHashidPure ctx g
f (LocalResourceRepo r) = LocalResourceRepo <$> decodeKeyHashidPure ctx r
f (LocalResourceDeck d) = LocalResourceDeck <$> decodeKeyHashidPure ctx d
f (LocalResourceLoom l) = LocalResourceLoom <$> decodeKeyHashidPure ctx l
f (LocalResourceProject j) = LocalResourceProject <$> decodeKeyHashidPure ctx j
unhashLocalResource
:: (MonadActor m, StageHashids (ActorEnv m))
=> LocalResourceBy KeyHashid -> m (Maybe (LocalResourceBy Key))
unhashLocalResource actor = do
ctx <- asksEnv stageHashidsContext
return $ unhashLocalResourcePure ctx actor
unhashLocalResourceF
:: (F.MonadFail m, MonadActor m, StageHashids (ActorEnv m))
=> LocalResourceBy KeyHashid -> String -> m (LocalResourceBy Key)
unhashLocalResourceF actor e = maybe (F.fail e) return =<< unhashLocalResource actor
unhashLocalResourceM
:: (MonadActor m, StageHashids (ActorEnv m))
=> LocalResourceBy KeyHashid -> MaybeT m (LocalResourceBy Key)
unhashLocalResourceM = MaybeT . unhashLocalResource
unhashLocalResourceE
:: (MonadActor m, StageHashids (ActorEnv m))
=> LocalResourceBy KeyHashid -> e -> ExceptT e m (LocalResourceBy Key)
unhashLocalResourceE actor e =
ExceptT $ maybe (Left e) Right <$> unhashLocalResource actor
unhashLocalResource404
:: ( MonadSite m
, MonadHandler m
, HandlerSite m ~ SiteEnv m
, YesodHashids (HandlerSite m)
)
=> LocalResourceBy KeyHashid
-> m (LocalResourceBy Key)
unhashLocalResource404 actor = maybe notFound return =<< unhashLocalResource actor
where
unhashLocalResource byHash = do
ctx <- asksSite siteHashidsContext
return $ unhashLocalResourcePure ctx byHash
data TicketRoutes = TicketRoutes data TicketRoutes = TicketRoutes
{ routeTicketFollowers :: Bool { routeTicketFollowers :: Bool
} }

View file

@ -473,8 +473,10 @@ clientCreateDeck now personMeID (ClientMsg maybeCap localRecips remoteRecips fwd
, actorFollowers = fsid , actorFollowers = fsid
, actorJustCreatedBy = Just actorMeID , actorJustCreatedBy = Just actorMeID
} }
rid <- insert $ Resource aid
did <- insert Deck did <- insert Deck
{ deckActor = aid { deckActor = aid
, deckResource = rid
, deckWorkflow = wid , deckWorkflow = wid
, deckNextTicket = 1 , deckNextTicket = 1
, deckWiki = Nothing , deckWiki = Nothing
@ -641,8 +643,10 @@ clientCreateProject now personMeID (ClientMsg maybeCap localRecips remoteRecips
, actorFollowers = fsid , actorFollowers = fsid
, actorJustCreatedBy = Just actorMeID , actorJustCreatedBy = Just actorMeID
} }
rid <- insert $ Resource aid
did <- insert Project did <- insert Project
{ projectActor = aid { projectActor = aid
, projectResource = rid
, projectCreate = obiidCreate , projectCreate = obiidCreate
} }
return (did, fsid) return (did, fsid)
@ -806,8 +810,10 @@ clientCreateTeam now personMeID (ClientMsg maybeCap localRecips remoteRecips fwd
, actorFollowers = fsid , actorFollowers = fsid
, actorJustCreatedBy = Just actorMeID , actorJustCreatedBy = Just actorMeID
} }
rid <- insert $ Resource aid
gid <- insert Group gid <- insert Group
{ groupActor = aid { groupActor = aid
, groupResource = rid
, groupCreate = obiidCreate , groupCreate = obiidCreate
} }
return (gid, fsid) return (gid, fsid)

View file

@ -22,12 +22,17 @@ module Vervis.Data.Actor
, stampRoute , stampRoute
, parseStampRoute , parseStampRoute
, localActorID , localActorID
, localResourceID
, parseLocalURI , parseLocalURI
, parseFedURIOld , parseFedURIOld
, parseLocalActorE , parseLocalActorE
, parseLocalActorE' , parseLocalActorE'
, parseLocalResourceE
, parseLocalResourceE'
, parseActorURI , parseActorURI
, parseActorURI' , parseActorURI'
, parseResourceURI
, parseResourceURI'
) )
where where
@ -175,6 +180,13 @@ localActorID (LocalActorDeck (Entity _ d)) = deckActor d
localActorID (LocalActorLoom (Entity _ l)) = loomActor l localActorID (LocalActorLoom (Entity _ l)) = loomActor l
localActorID (LocalActorProject (Entity _ r)) = projectActor r localActorID (LocalActorProject (Entity _ r)) = projectActor r
localResourceID :: LocalResourceBy Entity -> ResourceId
localResourceID (LocalResourceGroup (Entity _ g)) = groupResource g
localResourceID (LocalResourceRepo (Entity _ r)) = repoResource r
localResourceID (LocalResourceDeck (Entity _ d)) = deckResource d
localResourceID (LocalResourceLoom (Entity _ l)) = loomResource l
localResourceID (LocalResourceProject (Entity _ r)) = projectResource r
parseFedURIOld parseFedURIOld
:: ( MonadSite m :: ( MonadSite m
, SiteEnv m ~ site , SiteEnv m ~ site
@ -201,6 +213,18 @@ parseLocalActorE' route = do
actorByHash <- fromMaybeE (parseLocalActor route) "Not an actor route" actorByHash <- fromMaybeE (parseLocalActor route) "Not an actor route"
VA.unhashLocalActorE actorByHash "Invalid actor keyhashid" VA.unhashLocalActorE actorByHash "Invalid actor keyhashid"
parseLocalResourceE
:: (MonadSite m, YesodHashids (SiteEnv m))
=> Route App -> ExceptT Text m (LocalResourceBy Key)
parseLocalResourceE route = do
actorByHash <- fromMaybeE (parseLocalResource route) "Not a resource route"
unhashLocalResourceE actorByHash "Invalid resource keyhashid"
parseLocalResourceE' :: Route App -> VA.ActE (LocalResourceBy Key)
parseLocalResourceE' route = do
actorByHash <- fromMaybeE (parseLocalResource route) "Not a resource route"
VA.unhashLocalResourceE actorByHash "Invalid resource keyhashid"
parseActorURI parseActorURI
:: (MonadSite m, SiteEnv m ~ App) :: (MonadSite m, SiteEnv m ~ App)
=> FedURI => FedURI
@ -219,3 +243,22 @@ parseActorURI' u = do
parseLocalActorE' parseLocalActorE'
pure pure
routeOrRemote routeOrRemote
parseResourceURI
:: (MonadSite m, SiteEnv m ~ App)
=> FedURI
-> ExceptT Text m (Either (LocalResourceBy Key) FedURI)
parseResourceURI u = do
routeOrRemote <- parseFedURIOld u
bitraverse
parseLocalResourceE
pure
routeOrRemote
parseResourceURI' :: FedURI -> VA.ActE (Either (LocalResourceBy Key) FedURI)
parseResourceURI' u = do
routeOrRemote <- parseFedURI u
bitraverse
parseLocalResourceE'
pure
routeOrRemote

View file

@ -3341,6 +3341,154 @@ changes hLocal ctx =
, addEntities model_601_permit_extend_resource , addEntities model_601_permit_extend_resource
-- 602 -- 602
, addFieldPrimRequired "PermitTopicExtend" ("RoleAdmin" :: String) "role" , addFieldPrimRequired "PermitTopicExtend" ("RoleAdmin" :: String) "role"
-- 603
, addEntities model_603_resource
-- 604
, addFieldRefRequired''
"Repo"
(do inboxID <- insert Inbox604
outboxID <- insert Outbox604
followerSetID <- insert FollowerSet604
actorID <- insert $ Actor604 "" "" defaultTime inboxID outboxID followerSetID Nothing
insertEntity $ Resource604 actorID
)
(Just $ \ (Entity tempResourceID (Resource604 tempActorID)) -> do
l <- selectList [] []
for_ l $ \ (Entity k (Repo604 _ _ _ actorID _ _ _)) -> do
resourceID <- insert $ Resource604 actorID
update k [Repo604Resource =. resourceID]
Actor604 _ _ _ inboxID outboxID followerSetID _ <- getJust tempActorID
delete tempResourceID
delete tempActorID
delete inboxID
delete outboxID
delete followerSetID
)
"resource"
"Resource"
-- 605
, addFieldRefRequired''
"Deck"
(do inboxID <- insert Inbox604
outboxID <- insert Outbox604
followerSetID <- insert FollowerSet604
actorID <- insert $ Actor604 "" "" defaultTime inboxID outboxID followerSetID Nothing
insertEntity $ Resource604 actorID
)
(Just $ \ (Entity tempResourceID (Resource604 tempActorID)) -> do
l <- selectList [] []
for_ l $ \ (Entity k (Deck604 actorID _ _ _ _ _)) -> do
resourceID <- insert $ Resource604 actorID
update k [Deck604Resource =. resourceID]
Actor604 _ _ _ inboxID outboxID followerSetID _ <- getJust tempActorID
delete tempResourceID
delete tempActorID
delete inboxID
delete outboxID
delete followerSetID
)
"resource"
"Resource"
-- 606
, addFieldRefRequired''
"Loom"
(do inboxID <- insert Inbox604
outboxID <- insert Outbox604
followerSetID <- insert FollowerSet604
actorID <- insert $ Actor604 "" "" defaultTime inboxID outboxID followerSetID Nothing
insertEntity $ Resource604 actorID
)
(Just $ \ (Entity tempResourceID (Resource604 tempActorID)) -> do
l <- selectList [] []
for_ l $ \ (Entity k (Loom604 _ actorID _ _ _)) -> do
resourceID <- insert $ Resource604 actorID
update k [Loom604Resource =. resourceID]
Actor604 _ _ _ inboxID outboxID followerSetID _ <- getJust tempActorID
delete tempResourceID
delete tempActorID
delete inboxID
delete outboxID
delete followerSetID
)
"resource"
"Resource"
-- 607
, addFieldRefRequired''
"Project"
(do inboxID <- insert Inbox604
outboxID <- insert Outbox604
followerSetID <- insert FollowerSet604
actorID <- insert $ Actor604 "" "" defaultTime inboxID outboxID followerSetID Nothing
insertEntity $ Resource604 actorID
)
(Just $ \ (Entity tempResourceID (Resource604 tempActorID)) -> do
l <- selectList [] []
for_ l $ \ (Entity k (Project604 actorID _ _)) -> do
resourceID <- insert $ Resource604 actorID
update k [Project604Resource =. resourceID]
Actor604 _ _ _ inboxID outboxID followerSetID _ <- getJust tempActorID
delete tempResourceID
delete tempActorID
delete inboxID
delete outboxID
delete followerSetID
)
"resource"
"Resource"
-- 608
, addFieldRefRequired''
"Group"
(do inboxID <- insert Inbox604
outboxID <- insert Outbox604
followerSetID <- insert FollowerSet604
actorID <- insert $ Actor604 "" "" defaultTime inboxID outboxID followerSetID Nothing
insertEntity $ Resource604 actorID
)
(Just $ \ (Entity tempResourceID (Resource604 tempActorID)) -> do
l <- selectList [] []
for_ l $ \ (Entity k (Group604 actorID _ _)) -> do
resourceID <- insert $ Resource604 actorID
update k [Group604Resource =. resourceID]
Actor604 _ _ _ inboxID outboxID followerSetID _ <- getJust tempActorID
delete tempResourceID
delete tempActorID
delete inboxID
delete outboxID
delete followerSetID
)
"resource"
"Resource"
-- 609
{-
, addFieldRefRequired''
"PermitTopicExtendResourceLocal"
(do inboxID <- insert Inbox604
outboxID <- insert Outbox604
followerSetID <- insert FollowerSet604
actorID <- insert $ Actor604 "" "" defaultTime inboxID outboxID followerSetID Nothing
insertEntity $ Resource604 actorID
)
(Just $ \ (Entity tempResourceID (Resource604 tempActorID)) -> do
l <- selectList [] []
for_ l $ \ (Entity k (PermitTopicExtendResourceLocal604 _ actorID _)) -> do
resourceID <- getKeyByJust $ UniqueResource604 actorID
update k [PermitTopicExtendResourceLocal604Resource =. resourceID]
Actor604 _ _ _ inboxID outboxID followerSetID _ <- getJust tempActorID
delete tempResourceID
delete tempActorID
delete inboxID
delete outboxID
delete followerSetID
)
"resource"
"Resource"
-}
] ]
migrateDB migrateDB

View file

@ -74,6 +74,7 @@ module Vervis.Migration.Entities
, model_591_component_gather , model_591_component_gather
, model_592_permit_extend , model_592_permit_extend
, model_601_permit_extend_resource , model_601_permit_extend_resource
, model_603_resource
) )
where where
@ -289,3 +290,6 @@ model_592_permit_extend = $(schema "592_2024-04-18_permit_extend")
model_601_permit_extend_resource :: [Entity SqlBackend] model_601_permit_extend_resource :: [Entity SqlBackend]
model_601_permit_extend_resource = model_601_permit_extend_resource =
$(schema "601_2024-04-18_permit_extend_resource") $(schema "601_2024-04-18_permit_extend_resource")
model_603_resource :: [Entity SqlBackend]
model_603_resource = $(schema "603_2024-04-20_resource")

View file

@ -60,3 +60,6 @@ makeEntitiesMigration "584"
makeEntitiesMigration "593" makeEntitiesMigration "593"
$(modelFile "migrations/593_2024-04-18_permit_extend.model") $(modelFile "migrations/593_2024-04-18_permit_extend.model")
makeEntitiesMigration "604"
$(modelFile "migrations/604_2024-04-20_resource.model")

View file

@ -15,10 +15,15 @@
module Vervis.Persist.Actor module Vervis.Persist.Actor
( getLocalActor ( getLocalActor
, getLocalResource
, getLocalActorEnt , getLocalActorEnt
--, getLocalResourceEnt
, getLocalActorEntity , getLocalActorEntity
, getLocalActorEntityE , getLocalActorEntityE
, getLocalActorEntity404 , getLocalActorEntity404
, getLocalResourceEntity
, getLocalResourceEntityE
, getLocalResourceEntity404
, verifyLocalActivityExistsInDB , verifyLocalActivityExistsInDB
, getRemoteObjectURI , getRemoteObjectURI
, getRemoteActorURI , getRemoteActorURI
@ -68,6 +73,7 @@ import qualified Web.Actor as WA
import qualified Web.Actor.Persist as WAP import qualified Web.Actor.Persist as WAP
import Control.Monad.Trans.Except.Local import Control.Monad.Trans.Except.Local
import Data.Maybe.Local
import Database.Persist.Local import Database.Persist.Local
import Vervis.Data.Actor import Vervis.Data.Actor
@ -83,6 +89,10 @@ getLocalActor
:: MonadIO m => ActorId -> ReaderT SqlBackend m (LocalActorBy Key) :: MonadIO m => ActorId -> ReaderT SqlBackend m (LocalActorBy Key)
getLocalActor = fmap (bmap entityKey) . getLocalActorEnt getLocalActor = fmap (bmap entityKey) . getLocalActorEnt
getLocalResource
:: MonadIO m => ResourceId -> ReaderT SqlBackend m (LocalResourceBy Key)
getLocalResource = fmap (bmap entityKey) . getLocalResourceEnt
getLocalActorEnt getLocalActorEnt
:: MonadIO m => ActorId -> ReaderT SqlBackend m (LocalActorBy Entity) :: MonadIO m => ActorId -> ReaderT SqlBackend m (LocalActorBy Entity)
getLocalActorEnt actorID = do getLocalActorEnt actorID = do
@ -103,6 +113,23 @@ getLocalActorEnt actorID = do
(Nothing, Nothing, Nothing, Nothing, Nothing, Just j) -> LocalActorProject j (Nothing, Nothing, Nothing, Nothing, Nothing, Just j) -> LocalActorProject j
_ -> error "Multi-usage of an ActorId" _ -> error "Multi-usage of an ActorId"
getLocalResourceEnt
:: MonadIO m => ResourceId -> ReaderT SqlBackend m (LocalResourceBy Entity)
getLocalResourceEnt resourceID = do
Resource actorID <- getJust resourceID
options <-
sequence
[ fmap LocalResourceRepo <$> getBy (UniqueRepoActor actorID)
, fmap LocalResourceDeck <$> getBy (UniqueDeckActor actorID)
, fmap LocalResourceLoom <$> getBy (UniqueLoomActor actorID)
, fmap LocalResourceProject <$> getBy (UniqueProjectActor actorID)
, fmap LocalResourceGroup <$> getBy (UniqueGroupActor actorID)
]
exactlyOneJust
options
"Found Resource without specific actor"
"Found Resource with multiple actors"
getLocalActorEntity getLocalActorEntity
:: MonadIO m :: MonadIO m
=> LocalActorBy Key => LocalActorBy Key
@ -128,6 +155,29 @@ getLocalActorEntityE a e = do
getLocalActorEntity404 = maybe notFound return <=< getLocalActorEntity getLocalActorEntity404 = maybe notFound return <=< getLocalActorEntity
getLocalResourceEntity
:: MonadIO m
=> LocalResourceBy Key
-> ReaderT SqlBackend m (Maybe (LocalResourceBy Entity))
getLocalResourceEntity (LocalResourceGroup g) =
fmap (LocalResourceGroup . Entity g) <$> get g
getLocalResourceEntity (LocalResourceRepo r) =
fmap (LocalResourceRepo . Entity r) <$> get r
getLocalResourceEntity (LocalResourceDeck d) =
fmap (LocalResourceDeck . Entity d) <$> get d
getLocalResourceEntity (LocalResourceLoom l) =
fmap (LocalResourceLoom . Entity l) <$> get l
getLocalResourceEntity (LocalResourceProject r) =
fmap (LocalResourceProject . Entity r) <$> get r
getLocalResourceEntityE a e = do
m <- lift $ getLocalResourceEntity a
case m of
Nothing -> throwE e
Just a' -> return a'
getLocalResourceEntity404 = maybe notFound return <=< getLocalResourceEntity
verifyLocalActivityExistsInDB verifyLocalActivityExistsInDB
:: MonadIO m :: MonadIO m
=> LocalActorBy Key => LocalActorBy Key

View file

@ -1,6 +1,7 @@
{- This file is part of Vervis. {- This file is part of Vervis.
- -
- Written in 2019, 2020, 2022, 2023 by fr33domlover <fr33domlover@riseup.net>. - Written in 2019, 2020, 2022, 2023, 2024
- by fr33domlover <fr33domlover@riseup.net>.
- -
- Copying is an act of love. Please copy, reuse and share. - Copying is an act of love. Please copy, reuse and share.
- -
@ -22,9 +23,12 @@
module Vervis.Recipient module Vervis.Recipient
( -- * Local actors ( -- * Local actors
LocalActorBy (..) LocalActorBy (..)
, LocalResourceBy (..)
, LocalActor , LocalActor
, parseLocalActor , parseLocalActor
, renderLocalActor , renderLocalActor
, parseLocalResource
, renderLocalResource
-- * Local collections of (local and remote) actors -- * Local collections of (local and remote) actors
, LocalStageBy (..) , LocalStageBy (..)
@ -46,6 +50,17 @@ module Vervis.Recipient
, unhashLocalActorE , unhashLocalActorE
, unhashLocalActor404 , unhashLocalActor404
, hashLocalResourcePure
, getHashLocalResource
, hashLocalResource
, unhashLocalResourcePure
, unhashLocalResource
, unhashLocalResourceF
, unhashLocalResourceM
, unhashLocalResourceE
, unhashLocalResource404
, hashLocalStagePure , hashLocalStagePure
, getHashLocalStage , getHashLocalStage
, hashLocalStage , hashLocalStage
@ -143,6 +158,12 @@ import Vervis.Actor hiding
, unhashLocalActorF , unhashLocalActorF
, unhashLocalActorM , unhashLocalActorM
, unhashLocalActorE , unhashLocalActorE
, getHashLocalResource
, hashLocalResource
, unhashLocalResource
, unhashLocalResourceF
, unhashLocalResourceM
, unhashLocalResourceE
) )
import Vervis.FedURI import Vervis.FedURI
import Vervis.Foundation import Vervis.Foundation
@ -204,6 +225,21 @@ renderLocalActor (LocalActorDeck dkhid) = DeckR dkhid
renderLocalActor (LocalActorLoom lkhid) = LoomR lkhid renderLocalActor (LocalActorLoom lkhid) = LoomR lkhid
renderLocalActor (LocalActorProject jkhid) = ProjectR jkhid renderLocalActor (LocalActorProject jkhid) = ProjectR jkhid
parseLocalResource :: Route App -> Maybe (LocalResourceBy KeyHashid)
parseLocalResource (GroupR gkhid) = Just $ LocalResourceGroup gkhid
parseLocalResource (RepoR rkhid) = Just $ LocalResourceRepo rkhid
parseLocalResource (DeckR dkhid) = Just $ LocalResourceDeck dkhid
parseLocalResource (LoomR lkhid) = Just $ LocalResourceLoom lkhid
parseLocalResource (ProjectR jkhid) = Just $ LocalResourceProject jkhid
parseLocalResource _ = Nothing
renderLocalResource :: LocalResourceBy KeyHashid -> Route App
renderLocalResource (LocalResourceGroup gkhid) = GroupR gkhid
renderLocalResource (LocalResourceRepo rkhid) = RepoR rkhid
renderLocalResource (LocalResourceDeck dkhid) = DeckR dkhid
renderLocalResource (LocalResourceLoom lkhid) = LoomR lkhid
renderLocalResource (LocalResourceProject jkhid) = ProjectR jkhid
data LocalStageBy f data LocalStageBy f
= LocalStagePersonFollowers (f Person) = LocalStagePersonFollowers (f Person)
@ -315,6 +351,43 @@ unhashLocalActorE
unhashLocalActorE actor e = unhashLocalActorE actor e =
ExceptT $ maybe (Left e) Right <$> unhashLocalActor actor ExceptT $ maybe (Left e) Right <$> unhashLocalActor actor
getHashLocalResource
:: (MonadSite m, YesodHashids (SiteEnv m))
=> m (LocalResourceBy Key -> LocalResourceBy KeyHashid)
getHashLocalResource = do
ctx <- asksSite siteHashidsContext
return $ hashLocalResourcePure ctx
hashLocalResource
:: (MonadSite m, YesodHashids (SiteEnv m))
=> LocalResourceBy Key -> m (LocalResourceBy KeyHashid)
hashLocalResource actor = do
hash <- getHashLocalResource
return $ hash actor
unhashLocalResource
:: (MonadSite m, YesodHashids (SiteEnv m))
=> LocalResourceBy KeyHashid -> m (Maybe (LocalResourceBy Key))
unhashLocalResource actor = do
ctx <- asksSite siteHashidsContext
return $ unhashLocalResourcePure ctx actor
unhashLocalResourceF
:: (F.MonadFail m, MonadSite m, YesodHashids (SiteEnv m))
=> LocalResourceBy KeyHashid -> String -> m (LocalResourceBy Key)
unhashLocalResourceF actor e = maybe (F.fail e) return =<< unhashLocalResource actor
unhashLocalResourceM
:: (MonadSite m, YesodHashids (SiteEnv m))
=> LocalResourceBy KeyHashid -> MaybeT m (LocalResourceBy Key)
unhashLocalResourceM = MaybeT . unhashLocalResource
unhashLocalResourceE
:: (MonadSite m, YesodHashids (SiteEnv m))
=> LocalResourceBy KeyHashid -> e -> ExceptT e m (LocalResourceBy Key)
unhashLocalResourceE actor e =
ExceptT $ maybe (Left e) Right <$> unhashLocalResource actor
hashLocalStagePure hashLocalStagePure
:: HashidsContext -> LocalStageBy Key -> LocalStageBy KeyHashid :: HashidsContext -> LocalStageBy Key -> LocalStageBy KeyHashid
hashLocalStagePure ctx = f hashLocalStagePure ctx = f

View file

@ -149,6 +149,11 @@ Person
UniquePersonEmail email UniquePersonEmail email
UniquePersonActor actor UniquePersonActor actor
Resource
actor ActorId
UniqueResource actor
-- ========================================================================= -- -- ========================================================================= --
-- Delivery -- Delivery
-- ========================================================================= -- -- ========================================================================= --
@ -270,8 +275,9 @@ SshKey
UniqueSshKey person ident UniqueSshKey person ident
Group Group
actor ActorId actor ActorId
create OutboxItemId resource ResourceId
create OutboxItemId
UniqueGroupActor actor UniqueGroupActor actor
UniqueGroupCreate create UniqueGroupCreate create
@ -289,14 +295,16 @@ GroupMember
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Project Project
actor ActorId actor ActorId
create OutboxItemId resource ResourceId
create OutboxItemId
UniqueProjectActor actor UniqueProjectActor actor
UniqueProjectCreate create UniqueProjectCreate create
Deck Deck
actor ActorId actor ActorId
resource ResourceId
workflow WorkflowId workflow WorkflowId
nextTicket Int nextTicket Int
wiki RepoId Maybe wiki RepoId Maybe
@ -308,6 +316,7 @@ Deck
Loom Loom
nextTicket Int nextTicket Int
actor ActorId actor ActorId
resource ResourceId
repo RepoId repo RepoId
create OutboxItemId create OutboxItemId
@ -320,6 +329,7 @@ Repo
project DeckId Maybe project DeckId Maybe
mainBranch Text mainBranch Text
actor ActorId actor ActorId
resource ResourceId
create OutboxItemId create OutboxItemId
loom LoomId Maybe loom LoomId Maybe
@ -936,8 +946,9 @@ PermitTopicExtendRemote
UniquePermitTopicExtendRemoteGrant grant UniquePermitTopicExtendRemoteGrant grant
PermitTopicExtendResourceLocal PermitTopicExtendResourceLocal
permit PermitTopicExtendId permit PermitTopicExtendId
actor ActorId actor ActorId
--resource ResourceId
UniquePermitTopicExtendResourceLocal permit UniquePermitTopicExtendResourceLocal permit