From 21192fef26e6e713c8d200ef0f771c1770a7adf4 Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Thu, 11 Aug 2016 07:58:51 +0000 Subject: [PATCH] Route for accepting a New ticket --- config/routes | 1 + src/Vervis/Foundation.hs | 6 ++++-- src/Vervis/Handler/Ticket.hs | 19 +++++++++++++++++++ src/Vervis/Model/Role.hs | 5 ++++- templates/ticket/one.hamlet | 2 ++ 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/config/routes b/config/routes index 96f34c7..fe0f117 100644 --- a/config/routes +++ b/config/routes @@ -114,6 +114,7 @@ /s/#ShrIdent/p/#PrjIdent/t/!new TicketNewR GET /s/#ShrIdent/p/#PrjIdent/t/#Int TicketR GET PUT DELETE POST /s/#ShrIdent/p/#PrjIdent/t/#Int/edit TicketEditR GET +/s/#ShrIdent/p/#PrjIdent/t/#Int/accept TicketAcceptR POST /s/#ShrIdent/p/#PrjIdent/t/#Int/close TicketCloseR POST /s/#ShrIdent/p/#PrjIdent/t/#Int/open TicketOpenR POST /s/#ShrIdent/p/#PrjIdent/t/#Int/claim TicketClaimR POST diff --git a/src/Vervis/Foundation.hs b/src/Vervis/Foundation.hs index 7da9241..eb4f57a 100644 --- a/src/Vervis/Foundation.hs +++ b/src/Vervis/Foundation.hs @@ -182,8 +182,9 @@ instance Yesod App where (TicketNewR _ _ , _ ) -> personAny (TicketR user _ _ , True) -> person user (TicketEditR user _ _ , _ ) -> person user - (TicketCloseR user _ _ , _ ) -> person user - (TicketOpenR user _ _ , _ ) -> person user + (TicketAcceptR s j _ , _ ) -> projOp ProjOpAcceptTicket s j + (TicketCloseR s j _ , _ ) -> projOp ProjOpCloseTicket s j + (TicketOpenR s j _ , _ ) -> projOp ProjOpReopenTicket s j (TicketClaimR s j _ , _ ) -> projOp ProjOpClaimTicket s j (TicketUnclaimR s j _ , _ ) -> projOp ProjOpUnclaimTicket s j (TicketAssignR s j _ , _ ) -> projOp ProjOpAssignTicket s j @@ -518,6 +519,7 @@ instance YesodBreadcrumbs App where TicketEditR shar proj num -> ( "Edit" , Just $ TicketR shar proj num ) + TicketAcceptR _shr _prj _num -> ("", Nothing) TicketCloseR _shar _proj _num -> ("", Nothing) TicketOpenR _shar _proj _num -> ("", Nothing) TicketClaimR _shar _proj _num -> ("", Nothing) diff --git a/src/Vervis/Handler/Ticket.hs b/src/Vervis/Handler/Ticket.hs index 95b1e4b..df272cc 100644 --- a/src/Vervis/Handler/Ticket.hs +++ b/src/Vervis/Handler/Ticket.hs @@ -23,6 +23,7 @@ module Vervis.Handler.Ticket , deleteTicketR , postTicketR , getTicketEditR + , postTicketAcceptR , postTicketCloseR , postTicketOpenR , postTicketClaimR @@ -323,6 +324,24 @@ getTicketEditR shar proj num = do runFormPost $ editTicketContentForm tid ticket wid defaultLayout $(widgetFile "ticket/edit") +postTicketAcceptR :: ShrIdent -> PrjIdent -> Int -> Handler Html +postTicketAcceptR shr prj num = do + succ <- runDB $ do + Entity tid ticket <- do + Entity s _ <- getBy404 $ UniqueSharer shr + Entity p _ <- getBy404 $ UniqueProject prj s + getBy404 $ UniqueTicket p num + case ticketStatus ticket of + TSNew -> do + update tid [TicketStatus =. TSTodo] + return True + _ -> return False + setMessage $ + if succ + then "Ticket accepted." + else "Ticket is already accepted." + redirect $ TicketR shr prj num + postTicketCloseR :: ShrIdent -> PrjIdent -> Int -> Handler Html postTicketCloseR shr prj num = do pid <- requireAuthId diff --git a/src/Vervis/Model/Role.hs b/src/Vervis/Model/Role.hs index 730de6e..4103f69 100644 --- a/src/Vervis/Model/Role.hs +++ b/src/Vervis/Model/Role.hs @@ -28,7 +28,10 @@ data RepoOperation = RepoOpPush deriving (Eq, Show, Read, Enum, Bounded) derivePersistField "RepoOperation" data ProjectOperation - = ProjOpRequestTicket + = ProjOpAcceptTicket + | ProjOpCloseTicket + | ProjOpReopenTicket + | ProjOpRequestTicket | ProjOpClaimTicket | ProjOpUnclaimTicket | ProjOpAssignTicket diff --git a/templates/ticket/one.hamlet b/templates/ticket/one.hamlet index 1be36b6..fa77105 100644 --- a/templates/ticket/one.hamlet +++ b/templates/ticket/one.hamlet @@ -88,6 +88,8 @@ $if ticketStatus ticket /= TSClosed $of TSNew Open, new. +
+ $of TSTodo