diff --git a/config/models b/config/models index e08105c..ec91bb3 100644 --- a/config/models +++ b/config/models @@ -353,13 +353,9 @@ Ticket status TicketStatus closed UTCTime closer PersonId Maybe - discuss DiscussionId - followers FollowerSetId accept OutboxItemId -- UniqueTicket project number - UniqueTicketDiscussion discuss - UniqueTicketFollowers followers UniqueTicketAccept accept LocalTicket diff --git a/src/Vervis/API.hs b/src/Vervis/API.hs index 23ed92d..7e34530 100644 --- a/src/Vervis/API.hs +++ b/src/Vervis/API.hs @@ -169,9 +169,14 @@ createNoteC host (Note mluNote luAttrib aud muParent muContext mpublished source tid <- decodeKeyHashidM tkhid t <- MaybeT $ get tid guard $ ticketProject t == jid - return (sid, projectInbox j, projectFollowers j, t) - (sid, ibidProject, fsidProject, t) <- fromMaybeE mt "Context: No such local ticket" - let did = ticketDiscuss t + lt <- lift $ do + mlt <- getValBy $ UniqueLocalTicket tid + case mlt of + Nothing -> error "No LocalTicket" + Just lt -> return lt + return (sid, projectInbox j, projectFollowers j, t, lt) + (sid, ibidProject, fsidProject, _t, lt) <- fromMaybeE mt "Context: No such local ticket" + let did = localTicketDiscuss lt mmidParent <- for mparent $ \ parent -> case parent of Left (shrParent, lmidParent) -> getLocalParentMessageId did shrParent lmidParent @@ -186,7 +191,7 @@ createNoteC host (Note mluNote luAttrib aud muParent muContext mpublished source throwE "Remote parent belongs to a different discussion" return mid -- lift $ insertUnique_ $ Follow pid (ticketFollowers t) False True - return (did, Left <$> mmidParent, Just (sid, ticketFollowers t, ibidProject, fsidProject)) + return (did, Left <$> mmidParent, Just (sid, localTicketFollowers lt, ibidProject, fsidProject)) Nothing -> do (rd, rdnew) <- lift $ do let ObjURI hContext luContext = uContext @@ -546,9 +551,14 @@ followC shrUser summary audience follow@(AP.Follow uObject muContext hide) = run tid <- decodeKeyHashidM tkhid ticket <- MaybeT $ get tid guard $ ticketProject ticket == jid - return (ticket, project) - (ticket, project) <- fromMaybeE mproject "Follow object: No such ticket in DB" - return (ticketFollowers ticket, projectInbox project, False, projectOutbox project) + lticket <- lift $ do + mlt <- getValBy $ UniqueLocalTicket tid + case mlt of + Nothing -> error "No LocalTicket" + Just lt -> return lt + return (lticket, project) + (lticket, project) <- fromMaybeE mproject "Follow object: No such ticket in DB" + return (localTicketFollowers lticket, projectInbox project, False, projectOutbox project) getFollowee (FolloweeRepo shr rp) = do mrepo <- lift $ runMaybeT $ do sid <- MaybeT $ getKeyBy $ UniqueSharer shr @@ -858,8 +868,6 @@ offerTicketC shrUser summary audience offer@(Offer ticket uTarget) = runExceptT , ticketStatus = TSNew , ticketClosed = UTCTime (ModifiedJulianDay 0) 0 , ticketCloser = Nothing - , ticketDiscuss = did - , ticketFollowers = fsid , ticketAccept = obiidAccept } insert_ LocalTicket diff --git a/src/Vervis/Client.hs b/src/Vervis/Client.hs index 0022cdb..b087d74 100644 --- a/src/Vervis/Client.hs +++ b/src/Vervis/Client.hs @@ -352,7 +352,10 @@ undoFollowTicket shrAuthor pidAuthor shrFollowee prjFollowee numFollowee = t <- fromMaybeE mt "Unfollow target no such local ticket" unless (ticketProject t == jid) $ throwE "Hashid doesn't match sharer/project" - return $ ticketFollowers t + lt <- do + mlt <- lift $ getValBy $ UniqueLocalTicket tid + fromMaybeE mlt "Unexpected, ticket doesn't have a LocalTicket!" + return $ localTicketFollowers lt undoFollowRepo :: (MonadUnliftIO m, MonadHandler m, HandlerSite m ~ App, MonadSite m, SiteEnv m ~ App) diff --git a/src/Vervis/Federation/Discussion.hs b/src/Vervis/Federation/Discussion.hs index c3358af..0b73fd2 100644 --- a/src/Vervis/Federation/Discussion.hs +++ b/src/Vervis/Federation/Discussion.hs @@ -110,7 +110,12 @@ sharerCreateNoteF now shrRecip author body (Note mluNote _ _ muParent muContext tid <- decodeKeyHashidM tkhid t <- MaybeT $ get tid guard $ ticketProject t == jid - return $ ticketDiscuss t + lt <- lift $ do + mlt <- getValBy $ UniqueLocalTicket tid + case mlt of + Nothing -> error "No LocalTicket" + Just lt -> return lt + return $ localTicketDiscuss lt did <- fromMaybeE mdid "Context: No such local ticket" for_ mparent $ \ parent -> case parent of @@ -242,9 +247,11 @@ projectCreateNoteF now shrRecip prjRecip author body (Note mluNote _ _ muParent for mt $ \ t -> do unless (ticketProject t == jid) $ throwE "Context: Local ticket khid belongs to different project" - return (jid, projectInbox j, projectFollowers j, sid ,t) - (jid, ibid, fsidProject, sid, t) <- fromMaybeE mt "Context: No such local ticket" - let did = ticketDiscuss t + mlt <- lift $ getValBy $ UniqueLocalTicket tid + lt <- fromMaybeE mlt "No LocalTicket" + return (jid, projectInbox j, projectFollowers j, sid ,t, lt) + (jid, ibid, fsidProject, sid, _t, lt) <- fromMaybeE mt "Context: No such local ticket" + let did = localTicketDiscuss lt meparent <- for mparent $ \ parent -> case parent of Left (shrParent, lmidParent) -> Left <$> getLocalParentMessageId did shrParent lmidParent @@ -260,7 +267,7 @@ projectCreateNoteF now shrRecip prjRecip author body (Note mluNote _ _ muParent throwE "Remote parent belongs to a different discussion" return mid Nothing -> return $ Right p - return (sid, fsidProject, ticketFollowers t, jid, ibid, did, meparent) + return (sid, fsidProject, localTicketFollowers lt, jid, ibid, did, meparent) insertToDiscussion luCreate luNote published ibid did meparent fsid = do let iidAuthor = remoteAuthorInstance author raidAuthor = remoteAuthorId author diff --git a/src/Vervis/Federation/Offer.hs b/src/Vervis/Federation/Offer.hs index 6a33733..75376bb 100644 --- a/src/Vervis/Federation/Offer.hs +++ b/src/Vervis/Federation/Offer.hs @@ -390,11 +390,14 @@ projectFollowF shr prj = tid <- decodeKeyHashid404 tkhid t <- get404 tid unless (ticketProject t == jid) notFound - return t + mlt <- getValBy $ UniqueLocalTicket tid + case mlt of + Nothing -> error "No LocalTicket" + Just lt -> return lt return (j, mt) - followers (j, Nothing) = projectFollowers j - followers (_, Just t) = ticketFollowers t + followers (j, Nothing) = projectFollowers j + followers (_, Just lt) = localTicketFollowers lt repoFollowF :: ShrIdent @@ -528,11 +531,12 @@ projectUndoF shr prj = sid <- getKeyBy404 $ UniqueSharer shr getBy404 $ UniqueProject prj sid tryTicket jid fsid = do - mt <- getValBy $ UniqueTicketFollowers fsid - return $ - case mt of - Nothing -> Just "Undo object is a RemoteFollow, but isn't under this project" - Just t -> + mlt <- getValBy $ UniqueLocalTicketFollowers fsid + case mlt of + Nothing -> return $ Just "Undo object is a RemoteFollow, but isn't under this project" + Just lt -> do + t <- getJust $ localTicketTicket lt + return $ if ticketProject t /= jid then Just "Undo object is a RemoteFollow of a ticket of another project" else Nothing diff --git a/src/Vervis/Federation/Ticket.hs b/src/Vervis/Federation/Ticket.hs index 09bc064..d084d21 100644 --- a/src/Vervis/Federation/Ticket.hs +++ b/src/Vervis/Federation/Ticket.hs @@ -273,8 +273,6 @@ projectOfferTicketF , ticketStatus = TSNew , ticketClosed = UTCTime (ModifiedJulianDay 0) 0 , ticketCloser = Nothing - , ticketDiscuss = did - , ticketFollowers = fsid , ticketAccept = obiidAccept } insert_ LocalTicket diff --git a/src/Vervis/Form/Ticket.hs b/src/Vervis/Form/Ticket.hs index 47056ba..7d56e84 100644 --- a/src/Vervis/Form/Ticket.hs +++ b/src/Vervis/Form/Ticket.hs @@ -157,8 +157,6 @@ editTicketContentAForm ticket = Ticket <*> pure (ticketStatus ticket) <*> pure (ticketClosed ticket) <*> pure (ticketCloser ticket) - <*> pure (ticketDiscuss ticket) - <*> pure (ticketFollowers ticket) <*> pure (ticketAccept ticket) tEditField diff --git a/src/Vervis/Handler/Discussion.hs b/src/Vervis/Handler/Discussion.hs index 818cf74..fd9add3 100644 --- a/src/Vervis/Handler/Discussion.hs +++ b/src/Vervis/Handler/Discussion.hs @@ -128,12 +128,14 @@ getDiscussionMessage shr lmid = do route2fed <- getEncodeRouteHome uContext <- do let did = messageRoot m - mt <- getBy $ UniqueTicketDiscussion did + mlt <- getValBy $ UniqueLocalTicketDiscussion did mrd <- getValBy $ UniqueRemoteDiscussion did - case (mt, mrd) of + case (mlt, mrd) of (Nothing, Nothing) -> fail $ "DiscussionId #" ++ show did ++ " has no context" (Just _, Just _) -> fail $ "DiscussionId #" ++ show did ++ " has both ticket and remote contexts" - (Just (Entity tid t), Nothing) -> do + (Just lt, Nothing) -> do + let tid = localTicketTicket lt + t <- getJust tid j <- getJust $ ticketProject t s <- getJust $ projectSharer j let shr = sharerIdent s diff --git a/src/Vervis/Handler/Sharer.hs b/src/Vervis/Handler/Sharer.hs index b14f9b9..0d1fddb 100644 --- a/src/Vervis/Handler/Sharer.hs +++ b/src/Vervis/Handler/Sharer.hs @@ -145,7 +145,8 @@ getSharerFollowingR shr = do return (s E.^. SharerIdent, j E.^. ProjectIdent) return $ map (\ (E.Value shr, E.Value prj) -> ProjectR shr prj) pairs getTickets fsids = do - tids <- selectKeysList [TicketFollowers <-. fsids] [] + lts <- selectList [LocalTicketFollowers <-. fsids] [] + let tids = map (localTicketTicket . entityVal) lts triples <- E.select $ E.from $ \ (t `E.InnerJoin` j `E.InnerJoin` s) -> do E.on $ j E.^. ProjectSharer E.==. s E.^. SharerId E.on $ t E.^. TicketProject E.==. j E.^. ProjectId diff --git a/src/Vervis/Handler/Ticket.hs b/src/Vervis/Handler/Ticket.hs index 96c3045..c9a6415 100644 --- a/src/Vervis/Handler/Ticket.hs +++ b/src/Vervis/Handler/Ticket.hs @@ -232,7 +232,7 @@ getTicketR :: ShrIdent -> PrjIdent -> TicketKeyHashid -> Handler TypedContent getTicketR shar proj khid = do mpid <- maybeAuthId ( wshr, wfl, - author, massignee, mcloser, ticket, tparams, eparams, cparams, + author, massignee, mcloser, ticket, lticket, tparams, eparams, cparams, deps, rdeps) <- runDB $ do (jid, wshr, wid, wfl) <- do @@ -252,6 +252,11 @@ getTicketR shar proj khid = do tid <- decodeKeyHashid404 khid ticket <- get404 tid unless (ticketProject ticket == jid) notFound + lticket <- do + mlt <- getValBy $ UniqueLocalTicket tid + case mlt of + Nothing -> error "No LocalTicket" + Just lt -> return lt author <- requireEitherAlt (do mtal <- getValBy $ UniqueTicketAuthorLocal tid @@ -297,7 +302,8 @@ getTicketR shar proj khid = do return t return ( wshr, wfl - , author, massignee, mcloser, ticket, tparams, eparams, cparams + , author, massignee, mcloser, ticket, lticket + , tparams, eparams, cparams , deps, rdeps ) encodeHid <- getEncodeKeyHashid @@ -305,7 +311,7 @@ getTicketR shar proj khid = do desc = toWidget $ preEscapedToMarkup $ ticketDescription ticket discuss = discussionW - (return $ ticketDiscuss ticket) + (return $ localTicketDiscuss lticket) (TicketTopReplyR shar proj khid) (TicketReplyR shar proj khid . encodeHid) cRelevant <- newIdent @@ -367,7 +373,7 @@ getTicketR shar proj khid = do followW (TicketFollowR shar proj khid) (TicketUnfollowR shar proj khid) - (return $ ticketFollowers ticket) + (return $ localTicketFollowers lticket) in $(widgetFile "ticket/one") putTicketR :: ShrIdent -> PrjIdent -> TicketKeyHashid -> Handler Html @@ -792,7 +798,12 @@ selectDiscussionId shar proj tkhid = do tid <- decodeKeyHashid404 tkhid ticket <- get404 tid unless (ticketProject ticket == pid) notFound - return $ ticketDiscuss ticket + lticket <- do + mlt <- getValBy $ UniqueLocalTicket tid + case mlt of + Nothing -> error "No LocalTicket" + Just lt -> return lt + return $ localTicketDiscuss lticket getTicketDiscussionR :: ShrIdent -> PrjIdent -> KeyHashid Ticket -> Handler Html @@ -1073,7 +1084,12 @@ getTicketParticipantsR shr prj tkhid = getFollowersCollection here getFsid tid <- decodeKeyHashid404 tkhid t <- get404 tid unless (ticketProject t == jid) notFound - return $ ticketFollowers t + lt <- do + mlt <- getValBy $ UniqueLocalTicket tid + case mlt of + Nothing -> error "No LocalTicket" + Just lt -> return lt + return $ localTicketFollowers lt getTicketTeamR :: ShrIdent -> PrjIdent -> KeyHashid Ticket -> Handler TypedContent diff --git a/src/Vervis/Migration.hs b/src/Vervis/Migration.hs index e3c1ea5..fa138fb 100644 --- a/src/Vervis/Migration.hs +++ b/src/Vervis/Migration.hs @@ -1244,6 +1244,14 @@ changes hLocal ctx = , localTicket189Followers = ticket189Followers t } insertMany_ $ map makeLT ts + -- 190 + , removeUnique "Ticket" "UniqueTicketDiscussion" + -- 191 + , removeUnique "Ticket" "UniqueTicketFollowers" + -- 192 + , removeField "Ticket" "discuss" + -- 193 + , removeField "Ticket" "followers" ] migrateDB diff --git a/src/Vervis/Ticket.hs b/src/Vervis/Ticket.hs index de4ff52..d7d0557 100644 --- a/src/Vervis/Ticket.hs +++ b/src/Vervis/Ticket.hs @@ -53,13 +53,14 @@ getTicketSummaries getTicketSummaries mfilt morder offlim jid = do tickets <- select $ from $ \ ( t + `InnerJoin` lt `LeftOuterJoin` (tal `InnerJoin` p `InnerJoin` s) `LeftOuterJoin` (tar `InnerJoin` ra `InnerJoin` ro `InnerJoin` i) `InnerJoin` d `LeftOuterJoin` m ) -> do on $ just (d ^. DiscussionId) ==. m ?. MessageRoot - on $ t ^. TicketDiscuss ==. d ^. DiscussionId + on $ lt ^. LocalTicketDiscuss ==. d ^. DiscussionId on $ ro ?. RemoteObjectInstance ==. i ?. InstanceId on $ ra ?. RemoteActorIdent ==. ro ?. RemoteObjectId on $ tar ?. TicketAuthorRemoteAuthor ==. ra ?. RemoteActorId @@ -67,6 +68,7 @@ getTicketSummaries mfilt morder offlim jid = do on $ p ?. PersonIdent ==. s ?. SharerId on $ tal ?. TicketAuthorLocalAuthor ==. p ?. PersonId on $ just (t ^. TicketId) ==. tal ?. TicketAuthorLocalTicket + on $ t ^. TicketId ==. lt ^. LocalTicketTicket where_ $ t ^. TicketProject ==. val jid groupBy ( t ^. TicketId, s ?. SharerId