mirror of
https://code.sup39.dev/repos/Wqawg
synced 2024-12-27 17:44:52 +09:00
DB: Add Collab tables for recording Recip's and Topic's Accept activities
This commit is contained in:
parent
0bd7568ca5
commit
10645bf02b
6 changed files with 258 additions and 26 deletions
20
migrations/425_2022-08-21_collab_accept.model
Normal file
20
migrations/425_2022-08-21_collab_accept.model
Normal 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
|
101
migrations/426_2022-08-21_collab_accept_mig.model
Normal file
101
migrations/426_2022-08-21_collab_accept_mig.model
Normal 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
|
|
@ -139,18 +139,15 @@ checkRepoAccess' mpid op repoID = do
|
||||||
status <$> roleHasAccess role op
|
status <$> roleHasAccess role op
|
||||||
where
|
where
|
||||||
asCollab rid pid = do
|
asCollab rid pid = do
|
||||||
fmap (maybe Developer RoleID . E.unValue . snd) . listToMaybe <$> do
|
fmap (const Developer) . listToMaybe <$> do
|
||||||
E.select $ E.from $ \ (topic `E.InnerJoin` recip `E.LeftOuterJoin` role) -> do
|
E.select $ E.from $ \ (topic `E.InnerJoin` recip `E.InnerJoin` accept) -> do
|
||||||
E.on $ E.just (topic E.^. CollabTopicLocalRepoCollab) E.==. role E.?. CollabRoleLocalCollab
|
E.on $ topic E.^. CollabTopicLocalRepoCollab E.==. accept E.^. CollabTopicAcceptCollab
|
||||||
E.on $ topic E.^. CollabTopicLocalRepoCollab E.==. recip E.^. CollabRecipLocalCollab
|
E.on $ topic E.^. CollabTopicLocalRepoCollab E.==. recip E.^. CollabRecipLocalCollab
|
||||||
E.where_ $
|
E.where_ $
|
||||||
topic E.^. CollabTopicLocalRepoRepo E.==. E.val rid E.&&.
|
topic E.^. CollabTopicLocalRepoRepo E.==. E.val rid E.&&.
|
||||||
recip E.^. CollabRecipLocalPerson E.==. E.val pid
|
recip E.^. CollabRecipLocalPerson E.==. E.val pid
|
||||||
E.limit 1
|
E.limit 1
|
||||||
return
|
return $ topic E.^. CollabTopicLocalRepoCollab
|
||||||
( topic E.^. CollabTopicLocalRepoCollab
|
|
||||||
, role E.?. CollabRoleLocalRole
|
|
||||||
)
|
|
||||||
asUser = fmap RoleID . repoCollabUser
|
asUser = fmap RoleID . repoCollabUser
|
||||||
asAnon = fmap RoleID . repoCollabAnon
|
asAnon = fmap RoleID . repoCollabAnon
|
||||||
|
|
||||||
|
@ -176,18 +173,15 @@ checkRepoAccess mpid op repoHash = do
|
||||||
status <$> roleHasAccess role op
|
status <$> roleHasAccess role op
|
||||||
where
|
where
|
||||||
asCollab rid pid = do
|
asCollab rid pid = do
|
||||||
fmap (maybe Developer RoleID . E.unValue . snd) . listToMaybe <$> do
|
fmap (const Developer) . listToMaybe <$> do
|
||||||
E.select $ E.from $ \ (topic `E.InnerJoin` recip `E.LeftOuterJoin` role) -> do
|
E.select $ E.from $ \ (topic `E.InnerJoin` recip `E.InnerJoin` accept) -> do
|
||||||
E.on $ E.just (topic E.^. CollabTopicLocalRepoCollab) E.==. role E.?. CollabRoleLocalCollab
|
E.on $ topic E.^. CollabTopicLocalRepoCollab E.==. accept E.^. CollabTopicAcceptCollab
|
||||||
E.on $ topic E.^. CollabTopicLocalRepoCollab E.==. recip E.^. CollabRecipLocalCollab
|
E.on $ topic E.^. CollabTopicLocalRepoCollab E.==. recip E.^. CollabRecipLocalCollab
|
||||||
E.where_ $
|
E.where_ $
|
||||||
topic E.^. CollabTopicLocalRepoRepo E.==. E.val rid E.&&.
|
topic E.^. CollabTopicLocalRepoRepo E.==. E.val rid E.&&.
|
||||||
recip E.^. CollabRecipLocalPerson E.==. E.val pid
|
recip E.^. CollabRecipLocalPerson E.==. E.val pid
|
||||||
E.limit 1
|
E.limit 1
|
||||||
return
|
return $ topic E.^. CollabTopicLocalRepoCollab
|
||||||
( topic E.^. CollabTopicLocalRepoCollab
|
|
||||||
, role E.?. CollabRoleLocalRole
|
|
||||||
)
|
|
||||||
asUser = fmap RoleID . repoCollabUser
|
asUser = fmap RoleID . repoCollabUser
|
||||||
asAnon = fmap RoleID . repoCollabAnon
|
asAnon = fmap RoleID . repoCollabAnon
|
||||||
|
|
||||||
|
@ -214,17 +208,14 @@ checkProjectAccess mpid op deckHash = do
|
||||||
status <$> roleHasAccess role op
|
status <$> roleHasAccess role op
|
||||||
where
|
where
|
||||||
asCollab jid pid = do
|
asCollab jid pid = do
|
||||||
fmap (maybe Developer RoleID . E.unValue . snd) . listToMaybe <$> do
|
fmap (const Developer) . listToMaybe <$> do
|
||||||
E.select $ E.from $ \ (topic `E.InnerJoin` recip `E.LeftOuterJoin` role) -> do
|
E.select $ E.from $ \ (topic `E.InnerJoin` recip `E.InnerJoin` accept) -> do
|
||||||
E.on $ E.just (topic E.^. CollabTopicLocalDeckCollab) E.==. role E.?. CollabRoleLocalCollab
|
E.on $ topic E.^. CollabTopicLocalDeckCollab E.==. accept E.^. CollabTopicAcceptCollab
|
||||||
E.on $ topic E.^. CollabTopicLocalDeckCollab E.==. recip E.^. CollabRecipLocalCollab
|
E.on $ topic E.^. CollabTopicLocalDeckCollab E.==. recip E.^. CollabRecipLocalCollab
|
||||||
E.where_ $
|
E.where_ $
|
||||||
topic E.^. CollabTopicLocalDeckDeck E.==. E.val jid E.&&.
|
topic E.^. CollabTopicLocalDeckDeck E.==. E.val jid E.&&.
|
||||||
recip E.^. CollabRecipLocalPerson E.==. E.val pid
|
recip E.^. CollabRecipLocalPerson E.==. E.val pid
|
||||||
E.limit 1
|
E.limit 1
|
||||||
return
|
return $ topic E.^. CollabTopicLocalDeckCollab
|
||||||
( topic E.^. CollabTopicLocalDeckCollab
|
|
||||||
, role E.?. CollabRoleLocalRole
|
|
||||||
)
|
|
||||||
asUser = fmap RoleID . deckCollabUser
|
asUser = fmap RoleID . deckCollabUser
|
||||||
asAnon = fmap RoleID . deckCollabAnon
|
asAnon = fmap RoleID . deckCollabAnon
|
||||||
|
|
|
@ -2343,6 +2343,95 @@ changes hLocal ctx =
|
||||||
, removeField "Workflow" "sharer"
|
, removeField "Workflow" "sharer"
|
||||||
-- 423
|
-- 423
|
||||||
, removeEntity "Sharer"
|
, 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
|
migrateDB
|
||||||
|
|
|
@ -623,3 +623,9 @@ makeEntitiesMigration "414"
|
||||||
|
|
||||||
makeEntitiesMigration "418"
|
makeEntitiesMigration "418"
|
||||||
$(modelFile "migrations/418_2022-08-06_follow_actor.model")
|
$(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")
|
||||||
|
|
35
th/models
35
th/models
|
@ -588,11 +588,12 @@ Collab
|
||||||
|
|
||||||
-------------------------------- Collab topic --------------------------------
|
-------------------------------- Collab topic --------------------------------
|
||||||
|
|
||||||
CollabRoleLocal
|
-- Removed for now, until I figure out whether/how to federate custom roles
|
||||||
collab CollabId
|
--CollabRoleLocal
|
||||||
role RoleId
|
-- collab CollabId
|
||||||
|
-- role RoleId
|
||||||
UniqueCollabRoleLocal collab
|
--
|
||||||
|
-- UniqueCollabRoleLocal collab
|
||||||
|
|
||||||
CollabTopicLocalRepo
|
CollabTopicLocalRepo
|
||||||
collab CollabId
|
collab CollabId
|
||||||
|
@ -612,6 +613,16 @@ CollabTopicLocalLoom
|
||||||
|
|
||||||
UniqueCollabTopicLocalLoom collab
|
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
|
CollabTopicRemote
|
||||||
collab CollabId
|
collab CollabId
|
||||||
topic RemoteObjectId
|
topic RemoteObjectId
|
||||||
|
@ -644,12 +655,26 @@ CollabRecipLocal
|
||||||
|
|
||||||
UniqueCollabRecipLocal collab
|
UniqueCollabRecipLocal collab
|
||||||
|
|
||||||
|
CollabRecipLocalAccept
|
||||||
|
collab CollabRecipLocalId
|
||||||
|
accept OutboxItemId
|
||||||
|
|
||||||
|
UniqueCollabRecipLocalAcceptCollab collab
|
||||||
|
UniqueCollabRecipLocalAcceptAccept accept
|
||||||
|
|
||||||
CollabRecipRemote
|
CollabRecipRemote
|
||||||
collab CollabId
|
collab CollabId
|
||||||
actor RemoteActorId
|
actor RemoteActorId
|
||||||
|
|
||||||
UniqueCollabRecipRemote collab
|
UniqueCollabRecipRemote collab
|
||||||
|
|
||||||
|
CollabRecipRemoteAccept
|
||||||
|
collab CollabRecipRemoteId
|
||||||
|
accept RemoteActivityId
|
||||||
|
|
||||||
|
UniqueCollabRecipRemoteAcceptCollab collab
|
||||||
|
UniqueCollabRecipRemoteAcceptAccept accept
|
||||||
|
|
||||||
-------------------------------- Collab reason -------------------------------
|
-------------------------------- Collab reason -------------------------------
|
||||||
|
|
||||||
CollabFulfillsLocalTopicCreation
|
CollabFulfillsLocalTopicCreation
|
||||||
|
|
Loading…
Reference in a new issue