From 91ed2c82b573f0b273d92d9a6bf49cd01c93ac49 Mon Sep 17 00:00:00 2001 From: Pere Lev Date: Sun, 5 Nov 2023 17:50:55 +0200 Subject: [PATCH] UI: Add reopen-this-ticket button to ticket page --- src/Vervis/Foundation.hs | 1 + src/Vervis/Handler/Ticket.hs | 31 +++++++++++++++++++++++++++++++ templates/ticket/one.hamlet | 2 +- th/routes | 2 +- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/Vervis/Foundation.hs b/src/Vervis/Foundation.hs index 5e1cd5c..291f812 100644 --- a/src/Vervis/Foundation.hs +++ b/src/Vervis/Foundation.hs @@ -951,6 +951,7 @@ instance YesodBreadcrumbs App where TicketNewR d -> ("New Ticket", Just $ DeckR d) TicketCloseR _ _ -> ("", Nothing) + TicketOpenR _ _ -> ("", Nothing) TicketFollowR _ _ -> ("", Nothing) TicketUnfollowR _ _ -> ("", Nothing) TicketReplyR d t -> ("Reply", Just $ TicketR d t) diff --git a/src/Vervis/Handler/Ticket.hs b/src/Vervis/Handler/Ticket.hs index 07a3b32..5d4c513 100644 --- a/src/Vervis/Handler/Ticket.hs +++ b/src/Vervis/Handler/Ticket.hs @@ -27,6 +27,7 @@ module Vervis.Handler.Ticket , getTicketNewR , postTicketNewR , postTicketCloseR + , postTicketOpenR , postTicketFollowR , postTicketUnfollowR @@ -520,6 +521,36 @@ postTicketCloseR deckHash taskHash = do setMessage "Resolve activity sent" redirect $ TicketR deckHash taskHash +postTicketOpenR :: KeyHashid Deck -> KeyHashid TicketDeck -> Handler () +postTicketOpenR deckHash taskHash = do + deckID <- decodeKeyHashid404 deckHash + taskID <- decodeKeyHashid404 taskHash + + personEntity@(Entity personID person) <- requireAuth + personHash <- encodeKeyHashid personID + encodeRouteHome <- getEncodeRouteHome + let uTicket = encodeRouteHome $ TicketR deckHash taskHash + result <- runExceptT $ do + (maybeSummary, audience, undo) <- C.unresolve personHash uTicket + grantID <- do + maybeItem <- lift $ runDB $ getGrant CollabTopicDeckCollab CollabTopicDeckDeck deckID personID + fromMaybeE maybeItem "You need to be a collaborator in the Deck to reopen tickets" + grantHash <- encodeKeyHashid grantID + let uCap = encodeRouteHome $ DeckOutboxItemR deckHash grantHash + (localRecips, remoteRecips, fwdHosts, action) <- + C.makeServerInput (Just uCap) maybeSummary audience $ AP.UndoActivity undo + let cap = + Left (LocalActorDeck deckID, LocalActorDeck deckHash, grantID) + handleViaActor personID (Just cap) localRecips remoteRecips fwdHosts action + + case result of + Left e -> do + setMessage $ toHtml e + redirect $ TicketR deckHash taskHash + Right resolveID -> do + setMessage "Undo activity sent" + redirect $ TicketR deckHash taskHash + postTicketFollowR :: KeyHashid Deck -> KeyHashid TicketDeck -> Handler () postTicketFollowR _ = error "Temporarily disabled" diff --git a/templates/ticket/one.hamlet b/templates/ticket/one.hamlet index aeeffcc..002a477 100644 --- a/templates/ticket/one.hamlet +++ b/templates/ticket/one.hamlet @@ -69,7 +69,7 @@ $# . Status: # $maybe (closed, closer) <- resolved Closed on #{showDate closed} by ^{personLinkFedW closer} -$# ^{buttonW POST "Reopen this ticket" (ProjectTicketOpenR deckHash ticketHash)} + ^{buttonW POST "Reopen this ticket" (TicketOpenR deckHash ticketHash)} $nothing Open ^{buttonW POST "Close this ticket" (TicketCloseR deckHash ticketHash)} diff --git a/th/routes b/th/routes index 861e61a..71d01bc 100644 --- a/th/routes +++ b/th/routes @@ -240,7 +240,7 @@ -- /decks/#DeckKeyHashid/tickets/#TicketDeckKeyHashid/edit TicketEditR GET POST -- /decks/#DeckKeyHashid/tickets/#TicketDeckKeyHashid/delete TicketDeleteR POST /decks/#DeckKeyHashid/tickets/#TicketDeckKeyHashid/close TicketCloseR POST --- /decks/#DeckKeyHashid/tickets/#TicketDeckKeyHashid/open TicketOpenR POST +/decks/#DeckKeyHashid/tickets/#TicketDeckKeyHashid/open TicketOpenR POST -- /decks/#DeckKeyHashid/tickets/#TicketDeckKeyHashid/claim TicketClaimR POST -- /decks/#DeckKeyHashid/tickets/#TicketDeckKeyHashid/unclaim TicketUnclaimR POST -- /decks/#DeckKeyHashid/tickets/#TicketDeckKeyHashid/assign TicketAssignR GET POST