2016-05-01 07:32:22 +09:00
|
|
|
|
{- This file is part of Vervis.
|
|
|
|
|
-
|
|
|
|
|
- Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
|
|
|
|
|
-
|
|
|
|
|
- ♡ Copying is an act of love. Please copy, reuse and share.
|
|
|
|
|
-
|
|
|
|
|
- The author(s) have dedicated all copyright and related and neighboring
|
|
|
|
|
- rights to this software to the public domain worldwide. This software is
|
|
|
|
|
- distributed without any warranty.
|
|
|
|
|
-
|
|
|
|
|
- You should have received a copy of the CC0 Public Domain Dedication along
|
|
|
|
|
- with this software. If not, see
|
|
|
|
|
- <http://creativecommons.org/publicdomain/zero/1.0/>.
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
module Vervis.Handler.Ticket
|
|
|
|
|
( getTicketsR
|
|
|
|
|
, postTicketsR
|
|
|
|
|
, getTicketNewR
|
2016-05-01 08:02:44 +09:00
|
|
|
|
, getTicketR
|
2016-05-02 15:13:57 +09:00
|
|
|
|
, putTicketR
|
|
|
|
|
, deleteTicketR
|
2016-05-02 20:34:11 +09:00
|
|
|
|
, postTicketR
|
2016-05-02 15:13:57 +09:00
|
|
|
|
, getTicketEditR
|
2016-06-02 04:50:41 +09:00
|
|
|
|
, postTicketCloseR
|
|
|
|
|
, postTicketOpenR
|
2016-06-06 18:03:49 +09:00
|
|
|
|
, postTicketClaimR
|
|
|
|
|
, postTicketUnclaimR
|
2016-06-07 16:33:19 +09:00
|
|
|
|
, getTicketAssignR
|
|
|
|
|
, postTicketAssignR
|
|
|
|
|
, postTicketUnassignR
|
2016-06-08 01:31:55 +09:00
|
|
|
|
, getClaimRequestsPersonR
|
|
|
|
|
, getClaimRequestsProjectR
|
|
|
|
|
, getClaimRequestsTicketR
|
2016-06-08 10:28:18 +09:00
|
|
|
|
, postClaimRequestsTicketR
|
|
|
|
|
, getClaimRequestNewR
|
2016-05-20 01:58:23 +09:00
|
|
|
|
, getTicketDiscussionR
|
2016-05-22 05:01:31 +09:00
|
|
|
|
, postTicketDiscussionR
|
2016-05-20 07:07:25 +09:00
|
|
|
|
, getTicketMessageR
|
|
|
|
|
, postTicketMessageR
|
|
|
|
|
, getTicketTopReplyR
|
|
|
|
|
, getTicketReplyR
|
2016-06-08 05:16:15 +09:00
|
|
|
|
, getTicketDepsR
|
2016-05-01 07:32:22 +09:00
|
|
|
|
)
|
|
|
|
|
where
|
|
|
|
|
|
|
|
|
|
import Prelude
|
|
|
|
|
|
2016-05-18 18:15:11 +09:00
|
|
|
|
import Control.Monad.IO.Class (liftIO)
|
2016-06-06 18:03:49 +09:00
|
|
|
|
import Control.Monad.Logger (logWarn)
|
2016-05-22 23:31:56 +09:00
|
|
|
|
import Data.Default.Class (def)
|
2016-05-01 18:58:55 +09:00
|
|
|
|
import Data.Maybe (fromMaybe)
|
2016-06-07 16:33:19 +09:00
|
|
|
|
import Data.Monoid ((<>))
|
2016-05-01 07:32:22 +09:00
|
|
|
|
import Data.Text (Text)
|
2016-05-18 18:15:11 +09:00
|
|
|
|
import Data.Time.Calendar (Day (..))
|
|
|
|
|
import Data.Time.Clock (UTCTime (..), getCurrentTime)
|
2016-05-01 18:58:55 +09:00
|
|
|
|
import Data.Time.Format (formatTime, defaultTimeLocale)
|
2016-06-02 01:20:19 +09:00
|
|
|
|
import Data.Traversable (for)
|
2016-06-02 04:50:41 +09:00
|
|
|
|
import Database.Esqueleto hiding ((==.), (=.), (+=.), update)
|
2016-05-01 08:02:44 +09:00
|
|
|
|
import Database.Persist
|
2016-05-01 07:32:22 +09:00
|
|
|
|
import Text.Blaze.Html (Html, toHtml)
|
2016-06-06 19:00:05 +09:00
|
|
|
|
import Yesod.Auth (requireAuthId, maybeAuthId)
|
2016-05-01 07:32:22 +09:00
|
|
|
|
import Yesod.Core (defaultLayout)
|
2016-05-02 20:34:11 +09:00
|
|
|
|
import Yesod.Core.Handler (setMessage, redirect, lookupPostParam, notFound)
|
2016-05-22 23:31:56 +09:00
|
|
|
|
import Yesod.Form.Functions (runFormGet, runFormPost)
|
2016-05-01 19:15:38 +09:00
|
|
|
|
import Yesod.Form.Types (FormResult (..))
|
2016-05-01 18:58:55 +09:00
|
|
|
|
import Yesod.Persist.Core (runDB, get404, getBy404)
|
2016-05-01 07:32:22 +09:00
|
|
|
|
|
2016-05-03 06:20:25 +09:00
|
|
|
|
import qualified Data.Text as T (filter, intercalate, pack)
|
2016-05-01 18:58:55 +09:00
|
|
|
|
import qualified Database.Esqueleto as E ((==.))
|
2016-05-01 07:32:22 +09:00
|
|
|
|
|
|
|
|
|
import Vervis.Form.Ticket
|
|
|
|
|
import Vervis.Foundation
|
2016-05-20 01:58:23 +09:00
|
|
|
|
import Vervis.Handler.Discussion
|
2016-05-03 06:20:25 +09:00
|
|
|
|
import Vervis.MediaType (MediaType (Markdown))
|
2016-05-01 07:32:22 +09:00
|
|
|
|
import Vervis.Model
|
2016-05-24 05:46:54 +09:00
|
|
|
|
import Vervis.Model.Ident
|
2016-05-03 06:20:25 +09:00
|
|
|
|
import Vervis.Render (renderSourceT)
|
2016-05-01 07:32:22 +09:00
|
|
|
|
import Vervis.Settings (widgetFile)
|
2016-05-22 23:31:56 +09:00
|
|
|
|
import Vervis.TicketFilter (filterTickets)
|
2016-06-06 16:26:58 +09:00
|
|
|
|
import Vervis.Time (showDate)
|
2016-05-18 19:26:19 +09:00
|
|
|
|
import Vervis.Widget.Discussion (discussionW)
|
2016-05-25 06:48:21 +09:00
|
|
|
|
import Vervis.Widget.Sharer (personLinkW)
|
2016-05-01 07:32:22 +09:00
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
|
getTicketsR :: ShrIdent -> PrjIdent -> Handler Html
|
2016-05-01 08:02:44 +09:00
|
|
|
|
getTicketsR shar proj = do
|
2016-05-22 23:31:56 +09:00
|
|
|
|
((filtResult, filtWidget), filtEnctype) <- runFormGet ticketFilterForm
|
|
|
|
|
let tf =
|
|
|
|
|
case filtResult of
|
|
|
|
|
FormSuccess filt -> filt
|
|
|
|
|
FormMissing -> def
|
|
|
|
|
FormFailure l ->
|
|
|
|
|
error $ "Ticket filter form failed: " ++ show l
|
2016-05-18 18:38:48 +09:00
|
|
|
|
rows <- runDB $ select $ from $ \ (sharer, project, ticket) -> do
|
2016-05-22 23:31:56 +09:00
|
|
|
|
where_ $ filterTickets tf ticket $
|
2016-05-18 18:38:48 +09:00
|
|
|
|
sharer ^. SharerIdent E.==. val shar &&.
|
|
|
|
|
project ^. ProjectSharer E.==. sharer ^. SharerId &&.
|
|
|
|
|
project ^. ProjectIdent E.==. val proj &&.
|
|
|
|
|
ticket ^. TicketProject E.==. project ^. ProjectId
|
2016-05-01 18:58:55 +09:00
|
|
|
|
orderBy [asc $ ticket ^. TicketNumber]
|
|
|
|
|
return
|
|
|
|
|
( ticket ^. TicketNumber
|
2016-05-24 05:46:54 +09:00
|
|
|
|
, sharer
|
2016-05-01 18:58:55 +09:00
|
|
|
|
, ticket ^. TicketTitle
|
|
|
|
|
, ticket ^. TicketDone
|
|
|
|
|
)
|
2016-05-18 18:38:48 +09:00
|
|
|
|
defaultLayout $(widgetFile "ticket/list")
|
2016-05-01 07:32:22 +09:00
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
|
postTicketsR :: ShrIdent -> PrjIdent -> Handler Html
|
2016-05-01 19:15:38 +09:00
|
|
|
|
postTicketsR shar proj = do
|
2016-05-20 07:07:25 +09:00
|
|
|
|
((result, widget), enctype) <- runFormPost newTicketForm
|
2016-05-01 19:15:38 +09:00
|
|
|
|
case result of
|
2016-05-18 18:15:11 +09:00
|
|
|
|
FormSuccess nt -> do
|
|
|
|
|
author <- requireAuthId
|
|
|
|
|
now <- liftIO getCurrentTime
|
|
|
|
|
tnum <- runDB $ do
|
|
|
|
|
Entity pid project <- do
|
2016-05-24 05:46:54 +09:00
|
|
|
|
Entity sid _sharer <- getBy404 $ UniqueSharer shar
|
2016-05-18 18:15:11 +09:00
|
|
|
|
getBy404 $ UniqueProject proj sid
|
2016-05-18 18:44:32 +09:00
|
|
|
|
update pid [ProjectNextTicket +=. 1]
|
2016-05-20 01:58:23 +09:00
|
|
|
|
let discussion = Discussion
|
|
|
|
|
{ discussionNextMessage = 1
|
|
|
|
|
}
|
|
|
|
|
did <- insert discussion
|
2016-05-18 18:15:11 +09:00
|
|
|
|
let ticket = Ticket
|
2016-06-02 01:20:19 +09:00
|
|
|
|
{ ticketProject = pid
|
|
|
|
|
, ticketNumber = projectNextTicket project
|
|
|
|
|
, ticketCreated = now
|
|
|
|
|
, ticketCreator = author
|
|
|
|
|
, ticketTitle = ntTitle nt
|
|
|
|
|
, ticketDesc = ntDesc nt
|
|
|
|
|
, ticketAssignee = Nothing
|
|
|
|
|
, ticketDone = False
|
|
|
|
|
, ticketClosed = UTCTime (ModifiedJulianDay 0) 0
|
|
|
|
|
, ticketCloser = author
|
|
|
|
|
, ticketDiscuss = did
|
2016-05-18 18:15:11 +09:00
|
|
|
|
}
|
2016-05-01 19:15:38 +09:00
|
|
|
|
insert_ ticket
|
2016-05-18 18:15:11 +09:00
|
|
|
|
return $ ticketNumber ticket
|
2016-05-01 19:15:38 +09:00
|
|
|
|
setMessage "Ticket created."
|
2016-05-18 18:15:11 +09:00
|
|
|
|
redirect $ TicketR shar proj tnum
|
2016-05-01 19:15:38 +09:00
|
|
|
|
FormMissing -> do
|
|
|
|
|
setMessage "Field(s) missing."
|
|
|
|
|
defaultLayout $(widgetFile "ticket/new")
|
|
|
|
|
FormFailure _l -> do
|
|
|
|
|
setMessage "Ticket creation failed, see errors below."
|
|
|
|
|
defaultLayout $(widgetFile "ticket/new")
|
2016-05-01 07:32:22 +09:00
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
|
getTicketNewR :: ShrIdent -> PrjIdent -> Handler Html
|
2016-05-01 07:32:22 +09:00
|
|
|
|
getTicketNewR shar proj = do
|
2016-05-18 18:15:11 +09:00
|
|
|
|
((_result, widget), enctype) <- runFormPost newTicketForm
|
|
|
|
|
defaultLayout $(widgetFile "ticket/new")
|
2016-05-01 08:02:44 +09:00
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
|
getTicketR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
2016-05-01 18:58:55 +09:00
|
|
|
|
getTicketR shar proj num = do
|
2016-06-06 19:00:05 +09:00
|
|
|
|
mpid <- maybeAuthId
|
2016-06-02 01:20:19 +09:00
|
|
|
|
(author, massignee, closer, ticket) <- runDB $ do
|
|
|
|
|
ticket <- do
|
|
|
|
|
Entity s _ <- getBy404 $ UniqueSharer shar
|
|
|
|
|
Entity p _ <- getBy404 $ UniqueProject proj s
|
|
|
|
|
Entity _ t <- getBy404 $ UniqueTicket p num
|
|
|
|
|
return t
|
|
|
|
|
author <- do
|
|
|
|
|
person <- get404 $ ticketCreator ticket
|
|
|
|
|
get404 $ personIdent person
|
2016-06-06 18:03:49 +09:00
|
|
|
|
massignee <- for (ticketAssignee ticket) $ \ apid -> do
|
|
|
|
|
person <- get404 apid
|
|
|
|
|
sharer <- get404 $ personIdent person
|
2016-06-06 19:00:05 +09:00
|
|
|
|
return (sharer, fromMaybe False $ (== apid) <$> mpid)
|
2016-05-02 18:15:10 +09:00
|
|
|
|
closer <-
|
|
|
|
|
if ticketDone ticket
|
|
|
|
|
then do
|
2016-06-02 01:20:19 +09:00
|
|
|
|
person <- get404 $ ticketCloser ticket
|
|
|
|
|
get404 $ personIdent person
|
2016-05-02 18:15:10 +09:00
|
|
|
|
else return author
|
2016-06-02 01:20:19 +09:00
|
|
|
|
return (author, massignee, closer, ticket)
|
2016-05-03 06:20:25 +09:00
|
|
|
|
let desc = renderSourceT Markdown $ T.filter (/= '\r') $ ticketDesc ticket
|
2016-05-22 06:27:12 +09:00
|
|
|
|
discuss =
|
|
|
|
|
discussionW
|
|
|
|
|
(return $ ticketDiscuss ticket)
|
|
|
|
|
(TicketTopReplyR shar proj num)
|
|
|
|
|
(TicketReplyR shar proj num)
|
2016-05-20 01:58:23 +09:00
|
|
|
|
defaultLayout $(widgetFile "ticket/one")
|
2016-05-02 15:13:57 +09:00
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
|
putTicketR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
2016-05-02 18:15:10 +09:00
|
|
|
|
putTicketR shar proj num = do
|
|
|
|
|
Entity tid ticket <- runDB $ do
|
2016-05-24 05:46:54 +09:00
|
|
|
|
Entity sid _sharer <- getBy404 $ UniqueSharer shar
|
2016-05-02 18:15:10 +09:00
|
|
|
|
Entity pid _project <- getBy404 $ UniqueProject proj sid
|
|
|
|
|
getBy404 $ UniqueTicket pid num
|
2016-06-02 04:50:41 +09:00
|
|
|
|
((result, widget), enctype) <- runFormPost $ editTicketContentForm ticket
|
2016-05-02 18:15:10 +09:00
|
|
|
|
case result of
|
|
|
|
|
FormSuccess ticket' -> do
|
|
|
|
|
runDB $ replace tid ticket'
|
2016-05-02 20:33:30 +09:00
|
|
|
|
setMessage "Ticket updated."
|
2016-05-02 18:15:10 +09:00
|
|
|
|
redirect $ TicketR shar proj num
|
|
|
|
|
FormMissing -> do
|
|
|
|
|
setMessage "Field(s) missing."
|
|
|
|
|
defaultLayout $(widgetFile "ticket/edit")
|
|
|
|
|
FormFailure _l -> do
|
|
|
|
|
setMessage "Ticket update failed, see errors below."
|
|
|
|
|
defaultLayout $(widgetFile "ticket/edit")
|
2016-05-02 15:13:57 +09:00
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
|
deleteTicketR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
2016-05-02 18:15:10 +09:00
|
|
|
|
deleteTicketR shar proj num =
|
|
|
|
|
--TODO: I can easily implement this, but should it even be possible to
|
|
|
|
|
--delete tickets?
|
|
|
|
|
error "Not implemented"
|
2016-05-02 15:13:57 +09:00
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
|
postTicketR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
2016-05-02 20:34:11 +09:00
|
|
|
|
postTicketR shar proj num = do
|
|
|
|
|
mmethod <- lookupPostParam "_method"
|
|
|
|
|
case mmethod of
|
|
|
|
|
Just "PUT" -> putTicketR shar proj num
|
|
|
|
|
Just "DELETE" -> deleteTicketR shar proj num
|
|
|
|
|
_ -> notFound
|
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
|
getTicketEditR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
2016-05-02 18:15:10 +09:00
|
|
|
|
getTicketEditR shar proj num = do
|
|
|
|
|
Entity _tid ticket <- runDB $ do
|
2016-05-24 05:46:54 +09:00
|
|
|
|
Entity sid _sharer <- getBy404 $ UniqueSharer shar
|
2016-05-02 18:15:10 +09:00
|
|
|
|
Entity pid _project <- getBy404 $ UniqueProject proj sid
|
|
|
|
|
getBy404 $ UniqueTicket pid num
|
2016-06-02 04:50:41 +09:00
|
|
|
|
((_result, widget), enctype) <- runFormPost $ editTicketContentForm ticket
|
2016-05-20 01:58:23 +09:00
|
|
|
|
defaultLayout $(widgetFile "ticket/edit")
|
|
|
|
|
|
2016-06-02 04:50:41 +09:00
|
|
|
|
postTicketCloseR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
|
|
|
|
postTicketCloseR shr prj num = do
|
|
|
|
|
pid <- requireAuthId
|
|
|
|
|
now <- liftIO getCurrentTime
|
|
|
|
|
succ <- runDB $ do
|
|
|
|
|
Entity tid ticket <- do
|
|
|
|
|
Entity s _ <- getBy404 $ UniqueSharer shr
|
|
|
|
|
Entity p _ <- getBy404 $ UniqueProject prj s
|
|
|
|
|
getBy404 $ UniqueTicket p num
|
|
|
|
|
if ticketDone ticket
|
|
|
|
|
then return False
|
|
|
|
|
else do
|
|
|
|
|
update tid
|
2016-06-06 16:44:00 +09:00
|
|
|
|
[ TicketAssignee =. Nothing
|
|
|
|
|
, TicketDone =. True
|
|
|
|
|
, TicketClosed =. now
|
|
|
|
|
, TicketCloser =. pid
|
2016-06-02 04:50:41 +09:00
|
|
|
|
]
|
|
|
|
|
return True
|
|
|
|
|
setMessage $
|
|
|
|
|
if succ
|
|
|
|
|
then "Ticket closed."
|
|
|
|
|
else "Ticket is already closed."
|
|
|
|
|
redirect $ TicketR shr prj num
|
|
|
|
|
|
|
|
|
|
postTicketOpenR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
|
|
|
|
postTicketOpenR shr prj num = do
|
|
|
|
|
pid <- requireAuthId
|
|
|
|
|
now <- liftIO getCurrentTime
|
|
|
|
|
succ <- runDB $ do
|
|
|
|
|
Entity tid ticket <- do
|
|
|
|
|
Entity s _ <- getBy404 $ UniqueSharer shr
|
|
|
|
|
Entity p _ <- getBy404 $ UniqueProject prj s
|
|
|
|
|
getBy404 $ UniqueTicket p num
|
|
|
|
|
if ticketDone ticket
|
|
|
|
|
then do
|
|
|
|
|
update tid
|
|
|
|
|
[ TicketDone =. False
|
|
|
|
|
, TicketCloser =. ticketCreator ticket
|
|
|
|
|
]
|
|
|
|
|
return True
|
|
|
|
|
else return False
|
|
|
|
|
setMessage $
|
|
|
|
|
if succ
|
|
|
|
|
then "Ticket reopened"
|
|
|
|
|
else "Ticket is already open."
|
|
|
|
|
redirect $ TicketR shr prj num
|
|
|
|
|
|
2016-06-06 18:03:49 +09:00
|
|
|
|
postTicketClaimR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
|
|
|
|
postTicketClaimR shr prj num = do
|
|
|
|
|
pid <- requireAuthId
|
|
|
|
|
mmsg <- runDB $ do
|
|
|
|
|
Entity tid ticket <- do
|
|
|
|
|
Entity s _ <- getBy404 $ UniqueSharer shr
|
|
|
|
|
Entity p _ <- getBy404 $ UniqueProject prj s
|
|
|
|
|
getBy404 $ UniqueTicket p num
|
|
|
|
|
case (ticketDone ticket, ticketAssignee ticket) of
|
|
|
|
|
(True, _) ->
|
|
|
|
|
return $
|
|
|
|
|
Just "The ticket is closed. Can’t claim closed tickets."
|
|
|
|
|
(False, Just _) ->
|
|
|
|
|
return $
|
|
|
|
|
Just "The ticket is already assigned to someone."
|
|
|
|
|
(False, Nothing) -> do
|
|
|
|
|
update tid [TicketAssignee =. Just pid]
|
|
|
|
|
return Nothing
|
|
|
|
|
setMessage $ fromMaybe "The ticket is now assigned to you." mmsg
|
|
|
|
|
redirect $ TicketR shr prj num
|
|
|
|
|
|
|
|
|
|
postTicketUnclaimR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
|
|
|
|
postTicketUnclaimR shr prj num = do
|
|
|
|
|
pid <- requireAuthId
|
|
|
|
|
mmsg <- runDB $ do
|
|
|
|
|
Entity tid ticket <- do
|
|
|
|
|
Entity s _ <- getBy404 $ UniqueSharer shr
|
|
|
|
|
Entity p _ <- getBy404 $ UniqueProject prj s
|
|
|
|
|
getBy404 $ UniqueTicket p num
|
|
|
|
|
case ((== pid) <$> ticketAssignee ticket, ticketDone ticket) of
|
|
|
|
|
(Nothing, _) ->
|
|
|
|
|
return $ Just "The ticket is already unassigned."
|
|
|
|
|
(Just False, _) ->
|
|
|
|
|
return $ Just "The ticket is assigned to someone else."
|
|
|
|
|
(Just True, True) -> do
|
|
|
|
|
$logWarn "Found a closed claimed ticket, this is invalid"
|
|
|
|
|
return $
|
|
|
|
|
Just "The ticket is closed. Can’t unclaim closed tickets."
|
|
|
|
|
(Just True, False) -> do
|
|
|
|
|
update tid [TicketAssignee =. Nothing]
|
|
|
|
|
return Nothing
|
|
|
|
|
setMessage $ fromMaybe "The ticket is now unassigned." mmsg
|
|
|
|
|
redirect $ TicketR shr prj num
|
|
|
|
|
|
2016-06-07 16:33:19 +09:00
|
|
|
|
getTicketAssignR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
|
|
|
|
getTicketAssignR shr prj num = do
|
|
|
|
|
vpid <- requireAuthId
|
|
|
|
|
(jid, Entity tid ticket) <- runDB $ do
|
|
|
|
|
Entity s _ <- getBy404 $ UniqueSharer shr
|
|
|
|
|
Entity j _ <- getBy404 $ UniqueProject prj s
|
|
|
|
|
et <- getBy404 $ UniqueTicket j num
|
|
|
|
|
return (j, et)
|
|
|
|
|
let msg t = do
|
|
|
|
|
setMessage t
|
|
|
|
|
redirect $ TicketR shr prj num
|
|
|
|
|
case (ticketDone ticket, ticketAssignee ticket) of
|
|
|
|
|
(True, _) -> msg "The ticket is closed. Can’t assign closed tickets."
|
|
|
|
|
(False, Just _) -> msg "The ticket is already assigned to someone."
|
|
|
|
|
(False, Nothing) -> do
|
|
|
|
|
((_result, widget), enctype) <-
|
|
|
|
|
runFormPost $ assignTicketForm vpid jid
|
|
|
|
|
defaultLayout $(widgetFile "ticket/assign")
|
|
|
|
|
|
|
|
|
|
postTicketAssignR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
|
|
|
|
postTicketAssignR shr prj num = do
|
|
|
|
|
vpid <- requireAuthId
|
|
|
|
|
(jid, Entity tid ticket) <- runDB $ do
|
|
|
|
|
Entity s _ <- getBy404 $ UniqueSharer shr
|
|
|
|
|
Entity j _ <- getBy404 $ UniqueProject prj s
|
|
|
|
|
et <- getBy404 $ UniqueTicket j num
|
|
|
|
|
return (j, et)
|
|
|
|
|
let msg t = do
|
|
|
|
|
setMessage t
|
|
|
|
|
redirect $ TicketR shr prj num
|
|
|
|
|
case (ticketDone ticket, ticketAssignee ticket) of
|
|
|
|
|
(True, _) -> msg "The ticket is closed. Can’t assign closed tickets."
|
|
|
|
|
(False, Just _) -> msg "The ticket is already assigned to someone."
|
|
|
|
|
(False, Nothing) -> do
|
|
|
|
|
((result, widget), enctype) <-
|
|
|
|
|
runFormPost $ assignTicketForm vpid jid
|
|
|
|
|
case result of
|
|
|
|
|
FormSuccess pid -> do
|
|
|
|
|
sharer <- runDB $ do
|
|
|
|
|
update tid [TicketAssignee =. Just pid]
|
|
|
|
|
person <- getJust pid
|
|
|
|
|
getJust $ personIdent person
|
|
|
|
|
let si = sharerIdent sharer
|
|
|
|
|
msg $ toHtml $
|
|
|
|
|
"The ticket is now assigned to " <> shr2text si <> "."
|
|
|
|
|
FormMissing -> do
|
|
|
|
|
setMessage "Field(s) missing."
|
|
|
|
|
defaultLayout $(widgetFile "ticket/assign")
|
|
|
|
|
FormFailure _l -> do
|
|
|
|
|
setMessage "Ticket assignment failed, see errors below."
|
|
|
|
|
defaultLayout $(widgetFile "ticket/assign")
|
|
|
|
|
|
|
|
|
|
postTicketUnassignR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
|
|
|
|
postTicketUnassignR shr prj num = do
|
|
|
|
|
pid <- requireAuthId
|
|
|
|
|
mmsg <- runDB $ do
|
|
|
|
|
Entity tid ticket <- do
|
|
|
|
|
Entity s _ <- getBy404 $ UniqueSharer shr
|
|
|
|
|
Entity p _ <- getBy404 $ UniqueProject prj s
|
|
|
|
|
getBy404 $ UniqueTicket p num
|
|
|
|
|
case ((== pid) <$> ticketAssignee ticket, ticketDone ticket) of
|
|
|
|
|
(Nothing, _) ->
|
|
|
|
|
return $ Just "The ticket is already unassigned."
|
|
|
|
|
(Just True, _) ->
|
|
|
|
|
return $ Just "The ticket is assigned to you, unclaim instead."
|
|
|
|
|
(Just False, True) -> do
|
|
|
|
|
$logWarn "Found a closed claimed ticket, this is invalid"
|
|
|
|
|
return $
|
|
|
|
|
Just "The ticket is closed. Can’t unclaim closed tickets."
|
|
|
|
|
(Just False, False) -> do
|
|
|
|
|
update tid [TicketAssignee =. Nothing]
|
|
|
|
|
return Nothing
|
|
|
|
|
setMessage $ fromMaybe "The ticket is now unassigned." mmsg
|
|
|
|
|
redirect $ TicketR shr prj num
|
|
|
|
|
|
2016-06-08 00:29:26 +09:00
|
|
|
|
-- | The logged-in user gets a list of the ticket claim requests they have
|
|
|
|
|
-- opened, in any project.
|
2016-06-08 01:31:55 +09:00
|
|
|
|
getClaimRequestsPersonR :: Handler Html
|
|
|
|
|
getClaimRequestsPersonR = do
|
2016-06-07 19:01:57 +09:00
|
|
|
|
pid <- requireAuthId
|
|
|
|
|
rqs <- runDB $ select $ from $
|
|
|
|
|
\ (tcr `InnerJoin` ticket `InnerJoin` project `InnerJoin` sharer) -> do
|
|
|
|
|
on $ project ^. ProjectSharer E.==. sharer ^. SharerId
|
|
|
|
|
on $ ticket ^. TicketProject E.==. project ^. ProjectId
|
|
|
|
|
on $ tcr ^. TicketClaimRequestTicket E.==. ticket ^. TicketId
|
|
|
|
|
where_ $ tcr ^. TicketClaimRequestPerson E.==. val pid
|
|
|
|
|
orderBy [desc $ tcr ^. TicketClaimRequestCreated]
|
|
|
|
|
return
|
|
|
|
|
( sharer ^. SharerIdent
|
|
|
|
|
, project ^. ProjectIdent
|
|
|
|
|
, ticket ^. TicketNumber
|
|
|
|
|
, ticket ^. TicketTitle
|
|
|
|
|
, tcr ^. TicketClaimRequestCreated
|
|
|
|
|
)
|
|
|
|
|
defaultLayout $(widgetFile "person/claim-requests")
|
|
|
|
|
|
2016-06-08 00:29:26 +09:00
|
|
|
|
-- | Get a list of ticket claim requests for a given project.
|
2016-06-08 01:31:55 +09:00
|
|
|
|
getClaimRequestsProjectR :: ShrIdent -> PrjIdent -> Handler Html
|
|
|
|
|
getClaimRequestsProjectR shr prj = do
|
2016-06-08 00:29:26 +09:00
|
|
|
|
rqs <- runDB $ do
|
|
|
|
|
Entity sid _ <- getBy404 $ UniqueSharer shr
|
|
|
|
|
Entity jid _ <- getBy404 $ UniqueProject prj sid
|
|
|
|
|
select $ from $
|
|
|
|
|
\ ( tcr `InnerJoin`
|
|
|
|
|
ticket `InnerJoin`
|
|
|
|
|
person `InnerJoin`
|
|
|
|
|
sharer
|
|
|
|
|
) -> do
|
|
|
|
|
on $ person ^. PersonIdent E.==. sharer ^. SharerId
|
|
|
|
|
on $ tcr ^. TicketClaimRequestPerson E.==. person ^. PersonId
|
|
|
|
|
on $ tcr ^. TicketClaimRequestTicket E.==. ticket ^. TicketId
|
|
|
|
|
where_ $ ticket ^. TicketProject E.==. val jid
|
|
|
|
|
orderBy [desc $ tcr ^. TicketClaimRequestCreated]
|
|
|
|
|
return
|
|
|
|
|
( sharer
|
|
|
|
|
, ticket ^. TicketNumber
|
|
|
|
|
, ticket ^. TicketTitle
|
|
|
|
|
, tcr ^. TicketClaimRequestCreated
|
|
|
|
|
)
|
2016-06-08 01:31:55 +09:00
|
|
|
|
defaultLayout $(widgetFile "project/claim-request/list")
|
|
|
|
|
|
|
|
|
|
-- | Get a list of ticket claim requests for a given ticket.
|
|
|
|
|
getClaimRequestsTicketR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
|
|
|
|
getClaimRequestsTicketR shr prj num = do
|
|
|
|
|
rqs <- runDB $ do
|
|
|
|
|
Entity sid _ <- getBy404 $ UniqueSharer shr
|
|
|
|
|
Entity jid _ <- getBy404 $ UniqueProject prj sid
|
|
|
|
|
Entity tid _ <- getBy404 $ UniqueTicket jid num
|
|
|
|
|
select $ from $ \ (tcr `InnerJoin` person `InnerJoin` sharer) -> do
|
|
|
|
|
on $ person ^. PersonIdent E.==. sharer ^. SharerId
|
|
|
|
|
on $ tcr ^. TicketClaimRequestPerson E.==. person ^. PersonId
|
|
|
|
|
where_ $ tcr ^. TicketClaimRequestTicket E.==. val tid
|
|
|
|
|
orderBy [desc $ tcr ^. TicketClaimRequestCreated]
|
|
|
|
|
return (sharer, tcr)
|
2016-06-08 00:29:26 +09:00
|
|
|
|
defaultLayout $(widgetFile "ticket/claim-request/list")
|
|
|
|
|
|
2016-06-08 10:28:18 +09:00
|
|
|
|
getClaimRequestNewR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
|
|
|
|
getClaimRequestNewR shr prj num = do
|
|
|
|
|
((_result, widget), etype) <- runFormPost claimRequestForm
|
|
|
|
|
defaultLayout $(widgetFile "ticket/claim-request/new")
|
|
|
|
|
|
|
|
|
|
postClaimRequestsTicketR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
|
|
|
|
postClaimRequestsTicketR shr prj num = do
|
|
|
|
|
((result, widget), etype) <- runFormPost claimRequestForm
|
|
|
|
|
case result of
|
|
|
|
|
FormSuccess msg -> do
|
|
|
|
|
now <- liftIO getCurrentTime
|
|
|
|
|
pid <- requireAuthId
|
|
|
|
|
runDB $ do
|
|
|
|
|
tid <- do
|
|
|
|
|
Entity s _ <- getBy404 $ UniqueSharer shr
|
|
|
|
|
Entity j _ <- getBy404 $ UniqueProject prj s
|
|
|
|
|
Entity t _ <- getBy404 $ UniqueTicket j num
|
|
|
|
|
return t
|
|
|
|
|
let cr = TicketClaimRequest
|
|
|
|
|
{ ticketClaimRequestPerson = pid
|
|
|
|
|
, ticketClaimRequestTicket = tid
|
|
|
|
|
, ticketClaimRequestMessage = msg
|
|
|
|
|
, ticketClaimRequestCreated = now
|
|
|
|
|
}
|
|
|
|
|
insert_ cr
|
|
|
|
|
setMessage "Ticket claim request opened."
|
|
|
|
|
redirect $ TicketR shr prj num
|
|
|
|
|
FormMissing -> do
|
|
|
|
|
setMessage "Field(s) missing."
|
|
|
|
|
defaultLayout $(widgetFile "ticket/claim-request/new")
|
|
|
|
|
FormFailure _l -> do
|
|
|
|
|
setMessage "Submission failed, see errors below."
|
|
|
|
|
defaultLayout $(widgetFile "ticket/claim-request/new")
|
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
|
selectDiscussionId :: ShrIdent -> PrjIdent -> Int -> AppDB DiscussionId
|
2016-05-20 07:07:25 +09:00
|
|
|
|
selectDiscussionId shar proj tnum = do
|
2016-05-24 05:46:54 +09:00
|
|
|
|
Entity sid _sharer <- getBy404 $ UniqueSharer shar
|
2016-05-20 07:07:25 +09:00
|
|
|
|
Entity pid _project <- getBy404 $ UniqueProject proj sid
|
|
|
|
|
Entity _tid ticket <- getBy404 $ UniqueTicket pid tnum
|
|
|
|
|
return $ ticketDiscuss ticket
|
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
|
getTicketDiscussionR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
2016-05-20 07:40:54 +09:00
|
|
|
|
getTicketDiscussionR shar proj num =
|
|
|
|
|
getDiscussion
|
|
|
|
|
(TicketReplyR shar proj num)
|
2016-05-22 06:27:12 +09:00
|
|
|
|
(TicketTopReplyR shar proj num)
|
2016-05-20 07:40:54 +09:00
|
|
|
|
(selectDiscussionId shar proj num)
|
2016-05-20 01:58:23 +09:00
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
|
postTicketDiscussionR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
2016-05-22 05:01:31 +09:00
|
|
|
|
postTicketDiscussionR shar proj num =
|
|
|
|
|
postTopReply
|
|
|
|
|
(TicketDiscussionR shar proj num)
|
|
|
|
|
(const $ TicketR shar proj num)
|
|
|
|
|
(selectDiscussionId shar proj num)
|
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
|
getTicketMessageR :: ShrIdent -> PrjIdent -> Int -> Int -> Handler Html
|
2016-05-20 07:40:54 +09:00
|
|
|
|
getTicketMessageR shar proj tnum cnum =
|
|
|
|
|
getMessage
|
|
|
|
|
(TicketReplyR shar proj tnum)
|
|
|
|
|
(selectDiscussionId shar proj tnum)
|
|
|
|
|
cnum
|
2016-05-20 07:07:25 +09:00
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
|
postTicketMessageR :: ShrIdent -> PrjIdent -> Int -> Int -> Handler Html
|
2016-05-20 07:40:54 +09:00
|
|
|
|
postTicketMessageR shar proj tnum cnum =
|
2016-05-20 07:07:25 +09:00
|
|
|
|
postReply
|
|
|
|
|
(TicketReplyR shar proj tnum)
|
|
|
|
|
(TicketMessageR shar proj tnum)
|
|
|
|
|
(const $ TicketR shar proj tnum)
|
2016-05-20 07:40:54 +09:00
|
|
|
|
(selectDiscussionId shar proj tnum)
|
2016-05-20 07:07:25 +09:00
|
|
|
|
cnum
|
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
|
getTicketTopReplyR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
2016-05-22 05:01:31 +09:00
|
|
|
|
getTicketTopReplyR shar proj num =
|
|
|
|
|
getTopReply $ TicketDiscussionR shar proj num
|
2016-05-20 07:07:25 +09:00
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
|
getTicketReplyR :: ShrIdent -> PrjIdent -> Int -> Int -> Handler Html
|
2016-05-20 07:40:54 +09:00
|
|
|
|
getTicketReplyR shar proj tnum cnum =
|
2016-05-20 07:07:25 +09:00
|
|
|
|
getReply
|
|
|
|
|
(TicketReplyR shar proj tnum)
|
|
|
|
|
(TicketMessageR shar proj tnum)
|
2016-05-20 07:40:54 +09:00
|
|
|
|
(selectDiscussionId shar proj tnum)
|
2016-05-20 07:07:25 +09:00
|
|
|
|
cnum
|
2016-06-08 05:16:15 +09:00
|
|
|
|
|
|
|
|
|
getTicketDepsR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
|
|
|
|
getTicketDepsR shr prj num = do
|
|
|
|
|
rows <- runDB $ do
|
|
|
|
|
Entity sid _ <- getBy404 $ UniqueSharer shr
|
|
|
|
|
Entity jid _ <- getBy404 $ UniqueProject prj sid
|
|
|
|
|
Entity tid _ <- getBy404 $ UniqueTicket jid num
|
|
|
|
|
select $ from $
|
|
|
|
|
\ ( td `InnerJoin`
|
|
|
|
|
ticket `InnerJoin`
|
|
|
|
|
person `InnerJoin`
|
|
|
|
|
sharer
|
|
|
|
|
) -> do
|
|
|
|
|
on $ person ^. PersonIdent E.==. sharer ^. SharerId
|
|
|
|
|
on $ ticket ^. TicketCreator E.==. person ^. PersonId
|
|
|
|
|
on $ td ^. TicketDependencyChild E.==. ticket ^. TicketId
|
|
|
|
|
where_ $ td ^. TicketDependencyParent E.==. val tid
|
|
|
|
|
orderBy [asc $ ticket ^. TicketNumber]
|
|
|
|
|
return
|
|
|
|
|
( ticket ^. TicketNumber
|
|
|
|
|
, sharer
|
|
|
|
|
, ticket ^. TicketTitle
|
|
|
|
|
, ticket ^. TicketDone
|
|
|
|
|
)
|
|
|
|
|
defaultLayout $(widgetFile "ticket/dep/list")
|