DB: Add Collab tables for recording Recip's and Topic's Accept activities

This commit is contained in:
fr33domlover 2022-08-21 18:10:03 +00:00
parent 0bd7568ca5
commit 10645bf02b
6 changed files with 258 additions and 26 deletions

View file

@ -0,0 +1,20 @@
CollabTopicAccept
collab CollabId
accept OutboxItemId
UniqueCollabTopicAcceptCollab collab
UniqueCollabTopicAcceptAccept accept
CollabRecipLocalAccept
collab CollabRecipLocalId
accept OutboxItemId
UniqueCollabRecipLocalAcceptCollab collab
UniqueCollabRecipLocalAcceptAccept accept
CollabRecipRemoteAccept
collab CollabRecipRemoteId
accept RemoteActivityId
UniqueCollabRecipRemoteAcceptCollab collab
UniqueCollabRecipRemoteAcceptAccept accept

View file

@ -0,0 +1,101 @@
RemoteActor
RemoteActivity
Role
Workflow
Inbox
FollowerSet
Collab
CollabTopicLocalRepo
collab CollabId
repo RepoId
UniqueCollabTopicLocalRepo collab
CollabTopicLocalDeck
collab CollabId
deck DeckId
UniqueCollabTopicLocalDeck collab
CollabTopicLocalLoom
collab CollabId
loom LoomId
UniqueCollabTopicLocalLoom collab
CollabTopicAccept
collab CollabId
accept OutboxItemId
UniqueCollabTopicAcceptCollab collab
UniqueCollabTopicAcceptAccept accept
CollabSenderLocal
collab CollabId
activity OutboxItemId
UniqueCollabSenderLocal collab
UniqueCollabSenderLocalActivity activity
CollabSenderRemote
collab CollabId
actor RemoteActorId
activity RemoteActivityId
UniqueCollabSenderRemote collab
UniqueCollabSenderRemoteActivity activity
Repo
vcs VersionControlSystem
project DeckId Maybe
mainBranch Text
collabUser RoleId Maybe
collabAnon RoleId Maybe
actor ActorId
create OutboxItemId
UniqueRepoActor actor
UniqueRepoCreate create
Deck
actor ActorId
workflow WorkflowId
nextTicket Int
wiki RepoId Maybe
collabUser RoleId Maybe
collabAnon RoleId Maybe
create OutboxItemId
UniqueDeckActor actor
UniqueDeckCreate create
Loom
nextTicket Int
actor ActorId
repo RepoId
create OutboxItemId
UniqueLoomActor actor
UniqueLoomRepo repo
UniqueLoomCreate create
Actor
name Text
desc Text
createdAt UTCTime
inbox InboxId
outbox OutboxId
followers FollowerSetId
UniqueActorInbox inbox
UniqueActorOutbox outbox
UniqueActorFollowers followers
Outbox
OutboxItem
outbox OutboxId
activity PersistJSONObject
published UTCTime

View file

@ -139,18 +139,15 @@ checkRepoAccess' mpid op repoID = do
status <$> roleHasAccess role op
where
asCollab rid pid = do
fmap (maybe Developer RoleID . E.unValue . snd) . listToMaybe <$> do
E.select $ E.from $ \ (topic `E.InnerJoin` recip `E.LeftOuterJoin` role) -> do
E.on $ E.just (topic E.^. CollabTopicLocalRepoCollab) E.==. role E.?. CollabRoleLocalCollab
fmap (const Developer) . listToMaybe <$> do
E.select $ E.from $ \ (topic `E.InnerJoin` recip `E.InnerJoin` accept) -> do
E.on $ topic E.^. CollabTopicLocalRepoCollab E.==. accept E.^. CollabTopicAcceptCollab
E.on $ topic E.^. CollabTopicLocalRepoCollab E.==. recip E.^. CollabRecipLocalCollab
E.where_ $
topic E.^. CollabTopicLocalRepoRepo E.==. E.val rid E.&&.
recip E.^. CollabRecipLocalPerson E.==. E.val pid
E.limit 1
return
( topic E.^. CollabTopicLocalRepoCollab
, role E.?. CollabRoleLocalRole
)
return $ topic E.^. CollabTopicLocalRepoCollab
asUser = fmap RoleID . repoCollabUser
asAnon = fmap RoleID . repoCollabAnon
@ -176,18 +173,15 @@ checkRepoAccess mpid op repoHash = do
status <$> roleHasAccess role op
where
asCollab rid pid = do
fmap (maybe Developer RoleID . E.unValue . snd) . listToMaybe <$> do
E.select $ E.from $ \ (topic `E.InnerJoin` recip `E.LeftOuterJoin` role) -> do
E.on $ E.just (topic E.^. CollabTopicLocalRepoCollab) E.==. role E.?. CollabRoleLocalCollab
fmap (const Developer) . listToMaybe <$> do
E.select $ E.from $ \ (topic `E.InnerJoin` recip `E.InnerJoin` accept) -> do
E.on $ topic E.^. CollabTopicLocalRepoCollab E.==. accept E.^. CollabTopicAcceptCollab
E.on $ topic E.^. CollabTopicLocalRepoCollab E.==. recip E.^. CollabRecipLocalCollab
E.where_ $
topic E.^. CollabTopicLocalRepoRepo E.==. E.val rid E.&&.
recip E.^. CollabRecipLocalPerson E.==. E.val pid
E.limit 1
return
( topic E.^. CollabTopicLocalRepoCollab
, role E.?. CollabRoleLocalRole
)
return $ topic E.^. CollabTopicLocalRepoCollab
asUser = fmap RoleID . repoCollabUser
asAnon = fmap RoleID . repoCollabAnon
@ -214,17 +208,14 @@ checkProjectAccess mpid op deckHash = do
status <$> roleHasAccess role op
where
asCollab jid pid = do
fmap (maybe Developer RoleID . E.unValue . snd) . listToMaybe <$> do
E.select $ E.from $ \ (topic `E.InnerJoin` recip `E.LeftOuterJoin` role) -> do
E.on $ E.just (topic E.^. CollabTopicLocalDeckCollab) E.==. role E.?. CollabRoleLocalCollab
fmap (const Developer) . listToMaybe <$> do
E.select $ E.from $ \ (topic `E.InnerJoin` recip `E.InnerJoin` accept) -> do
E.on $ topic E.^. CollabTopicLocalDeckCollab E.==. accept E.^. CollabTopicAcceptCollab
E.on $ topic E.^. CollabTopicLocalDeckCollab E.==. recip E.^. CollabRecipLocalCollab
E.where_ $
topic E.^. CollabTopicLocalDeckDeck E.==. E.val jid E.&&.
recip E.^. CollabRecipLocalPerson E.==. E.val pid
E.limit 1
return
( topic E.^. CollabTopicLocalDeckCollab
, role E.?. CollabRoleLocalRole
)
return $ topic E.^. CollabTopicLocalDeckCollab
asUser = fmap RoleID . deckCollabUser
asAnon = fmap RoleID . deckCollabAnon

View file

@ -2343,6 +2343,95 @@ changes hLocal ctx =
, removeField "Workflow" "sharer"
-- 423
, removeEntity "Sharer"
-- 424
, removeEntity "CollabRoleLocal"
-- 425
, addEntities model_425_collab_accept
-- 426
, unchecked $ lift $ do
repos <- selectList [] [Asc CollabTopicLocalRepo426Id]
for_ repos $ \ (Entity _ (CollabTopicLocalRepo426 collabID repoID)) -> do
repo <- getJust repoID
itemID <- do
mgrant <- runMaybeT $ do
CollabSenderLocal426 _ grantID <-
MaybeT $ maybeRight <$>
requireEitherAlt
(getBy $ UniqueCollabSenderRemote426 collabID)
(getValBy $ UniqueCollabSenderLocal426 collabID)
"No CollabSender*"
"Multiple CollabSender*"
OutboxItem426 outboxID _ _ <- lift $ getJust $ grantID
actorID <- do
mactor <- lift $ getKeyBy $ UniqueActorOutbox426 outboxID
case mactor of
Just a -> return a
Nothing -> error "Outbox with no actor"
guard $ repo426Actor repo == actorID
return grantID
case mgrant of
Just grantID -> return grantID
Nothing -> do
actor <- getJust $ repo426Actor repo
let doc = persistJSONObjectFromDoc $ Doc hLocal emptyActivity
insert $ OutboxItem426 (actor426Outbox actor) doc defaultTime
insert_ $ CollabTopicAccept426 collabID itemID
decks <- selectList [] [Asc CollabTopicLocalDeck426Id]
for_ decks $ \ (Entity _ (CollabTopicLocalDeck426 collabID deckID)) -> do
deck <- getJust deckID
itemID <- do
mgrant <- runMaybeT $ do
CollabSenderLocal426 _ grantID <-
MaybeT $ maybeRight <$>
requireEitherAlt
(getBy $ UniqueCollabSenderRemote426 collabID)
(getValBy $ UniqueCollabSenderLocal426 collabID)
"No CollabSender*"
"Multiple CollabSender*"
OutboxItem426 outboxID _ _ <- lift $ getJust $ grantID
actorID <- do
mactor <- lift $ getKeyBy $ UniqueActorOutbox426 outboxID
case mactor of
Just a -> return a
Nothing -> error "Outbox with no actor"
guard $ deck426Actor deck == actorID
return grantID
case mgrant of
Just grantID -> return grantID
Nothing -> do
actor <- getJust $ deck426Actor deck
let doc = persistJSONObjectFromDoc $ Doc hLocal emptyActivity
insert $ OutboxItem426 (actor426Outbox actor) doc defaultTime
insert_ $ CollabTopicAccept426 collabID itemID
looms <- selectList [] [Asc CollabTopicLocalLoom426Id]
for_ looms $ \ (Entity _ (CollabTopicLocalLoom426 collabID loomID)) -> do
loom <- getJust loomID
itemID <- do
mgrant <- runMaybeT $ do
CollabSenderLocal426 _ grantID <-
MaybeT $ maybeRight <$>
requireEitherAlt
(getBy $ UniqueCollabSenderRemote426 collabID)
(getValBy $ UniqueCollabSenderLocal426 collabID)
"No CollabSender*"
"Multiple CollabSender*"
OutboxItem426 outboxID _ _ <- lift $ getJust $ grantID
actorID <- do
mactor <- lift $ getKeyBy $ UniqueActorOutbox426 outboxID
case mactor of
Just a -> return a
Nothing -> error "Outbox with no actor"
guard $ loom426Actor loom == actorID
return grantID
case mgrant of
Just grantID -> return grantID
Nothing -> do
actor <- getJust $ loom426Actor loom
let doc = persistJSONObjectFromDoc $ Doc hLocal emptyActivity
insert $ OutboxItem426 (actor426Outbox actor) doc defaultTime
insert_ $ CollabTopicAccept426 collabID itemID
]
migrateDB

View file

@ -623,3 +623,9 @@ makeEntitiesMigration "414"
makeEntitiesMigration "418"
$(modelFile "migrations/418_2022-08-06_follow_actor.model")
model_425_collab_accept :: [Entity SqlBackend]
model_425_collab_accept = $(schema "425_2022-08-21_collab_accept")
makeEntitiesMigration "426"
$(modelFile "migrations/426_2022-08-21_collab_accept_mig.model")

View file

@ -588,11 +588,12 @@ Collab
-------------------------------- Collab topic --------------------------------
CollabRoleLocal
collab CollabId
role RoleId
UniqueCollabRoleLocal collab
-- Removed for now, until I figure out whether/how to federate custom roles
--CollabRoleLocal
-- collab CollabId
-- role RoleId
--
-- UniqueCollabRoleLocal collab
CollabTopicLocalRepo
collab CollabId
@ -612,6 +613,16 @@ CollabTopicLocalLoom
UniqueCollabTopicLocalLoom collab
CollabTopicAccept
collab CollabId
accept OutboxItemId
UniqueCollabTopicAcceptCollab collab
UniqueCollabTopicAcceptAccept accept
-- Do we need this for S2S? Or is this just for the Client, to decide which
-- Grant URI to use as the 'capability'? If latter, look into removing this
-- table...
CollabTopicRemote
collab CollabId
topic RemoteObjectId
@ -644,12 +655,26 @@ CollabRecipLocal
UniqueCollabRecipLocal collab
CollabRecipLocalAccept
collab CollabRecipLocalId
accept OutboxItemId
UniqueCollabRecipLocalAcceptCollab collab
UniqueCollabRecipLocalAcceptAccept accept
CollabRecipRemote
collab CollabId
actor RemoteActorId
UniqueCollabRecipRemote collab
CollabRecipRemoteAccept
collab CollabRecipRemoteId
accept RemoteActivityId
UniqueCollabRecipRemoteAcceptCollab collab
UniqueCollabRecipRemoteAcceptAccept accept
-------------------------------- Collab reason -------------------------------
CollabFulfillsLocalTopicCreation