2016-02-27 14:41:36 +09:00
|
|
|
{- This file is part of Vervis.
|
|
|
|
-
|
2019-01-30 07:24:32 +09:00
|
|
|
- Written in 2016, 2018, 2019 by fr33domlover <fr33domlover@riseup.net>.
|
2016-02-27 14:41:36 +09:00
|
|
|
-
|
|
|
|
- ♡ 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.Repo
|
|
|
|
( getReposR
|
|
|
|
, postReposR
|
|
|
|
, getRepoNewR
|
|
|
|
, getRepoR
|
2016-06-06 06:11:05 +09:00
|
|
|
, putRepoR
|
2016-05-14 04:23:56 +09:00
|
|
|
, deleteRepoR
|
|
|
|
, postRepoR
|
2016-06-06 06:11:05 +09:00
|
|
|
, getRepoEditR
|
2016-04-12 09:19:04 +09:00
|
|
|
, getRepoSourceR
|
2016-05-06 01:30:30 +09:00
|
|
|
, getRepoHeadChangesR
|
|
|
|
, getRepoChangesR
|
2018-05-18 00:46:57 +09:00
|
|
|
, getRepoPatchR
|
2016-05-29 23:13:25 +09:00
|
|
|
, getRepoDevsR
|
|
|
|
, postRepoDevsR
|
|
|
|
, getRepoDevNewR
|
|
|
|
, getRepoDevR
|
|
|
|
, deleteRepoDevR
|
|
|
|
, postRepoDevR
|
2016-05-13 19:58:42 +09:00
|
|
|
, getDarcsDownloadR
|
2016-02-27 14:41:36 +09:00
|
|
|
)
|
|
|
|
where
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
import Prelude
|
2016-04-12 20:21:14 +09:00
|
|
|
|
2016-05-24 05:46:54 +09:00
|
|
|
import Control.Monad.IO.Class (liftIO)
|
|
|
|
import Control.Monad.Logger (logWarn)
|
2016-04-10 00:45:00 +09:00
|
|
|
import Data.Git.Graph
|
2016-05-01 05:14:56 +09:00
|
|
|
import Data.Git.Harder
|
2016-04-12 09:19:04 +09:00
|
|
|
import Data.Git.Named (RefName (..))
|
2016-03-03 17:15:54 +09:00
|
|
|
import Data.Git.Ref (toHex)
|
2016-05-04 20:44:06 +09:00
|
|
|
import Data.Git.Repository
|
2016-05-05 02:17:47 +09:00
|
|
|
import Data.Git.Storage (withRepo)
|
2016-04-12 19:06:21 +09:00
|
|
|
import Data.Git.Storage.Object (Object (..))
|
|
|
|
import Data.Git.Types (Blob (..), Commit (..), Person (..), entName)
|
2016-04-10 00:45:00 +09:00
|
|
|
import Data.Graph.Inductive.Graph (noNodes)
|
|
|
|
import Data.Graph.Inductive.Query.Topsort
|
2016-04-13 08:10:46 +09:00
|
|
|
import Data.List (inits)
|
2016-05-24 05:46:54 +09:00
|
|
|
import Data.Text (Text, unpack)
|
2016-03-03 17:15:54 +09:00
|
|
|
import Data.Text.Encoding (decodeUtf8With)
|
|
|
|
import Data.Text.Encoding.Error (lenientDecode)
|
2016-06-06 06:11:05 +09:00
|
|
|
import Data.Traversable (for)
|
2016-05-14 04:23:56 +09:00
|
|
|
import Database.Esqueleto hiding (delete, (%))
|
2016-05-24 05:46:54 +09:00
|
|
|
import Database.Persist (delete)
|
2016-03-03 17:15:54 +09:00
|
|
|
import Data.Hourglass (timeConvert)
|
2016-05-14 04:23:56 +09:00
|
|
|
import Formatting (sformat, stext, (%))
|
|
|
|
import System.Directory
|
2016-03-03 17:15:54 +09:00
|
|
|
import System.Hourglass (dateCurrent)
|
2016-05-24 05:46:54 +09:00
|
|
|
import Text.Blaze.Html (Html)
|
2016-06-07 14:17:54 +09:00
|
|
|
import Yesod.Auth (requireAuthId)
|
2016-05-24 05:46:54 +09:00
|
|
|
import Yesod.Core (defaultLayout, setMessage)
|
2018-04-01 07:04:33 +09:00
|
|
|
import Yesod.Core.Content (TypedContent)
|
2016-05-24 05:46:54 +09:00
|
|
|
import Yesod.Core.Handler (lookupPostParam, redirect, notFound)
|
|
|
|
import Yesod.Form.Functions (runFormPost)
|
|
|
|
import Yesod.Form.Types (FormResult (..))
|
|
|
|
import Yesod.Persist.Core (runDB, getBy404)
|
2016-03-03 17:15:54 +09:00
|
|
|
|
2016-05-24 05:46:54 +09:00
|
|
|
import qualified Data.CaseInsensitive as CI (foldedCase)
|
2016-04-10 00:45:00 +09:00
|
|
|
import qualified Data.DList as D
|
2016-04-12 09:19:04 +09:00
|
|
|
import qualified Data.Set as S (member)
|
2016-04-12 19:06:21 +09:00
|
|
|
import qualified Data.Text.Lazy.Encoding as L (decodeUtf8With)
|
2016-04-10 00:45:00 +09:00
|
|
|
|
2016-03-03 17:15:54 +09:00
|
|
|
import Data.ByteString.Char8.Local (takeLine)
|
2016-05-05 02:17:47 +09:00
|
|
|
import Data.Git.Local
|
2016-04-18 02:55:23 +09:00
|
|
|
import Text.FilePath.Local (breakExt)
|
2016-02-27 14:41:36 +09:00
|
|
|
import Vervis.Form.Repo
|
2016-03-03 17:15:54 +09:00
|
|
|
import Vervis.Foundation
|
2016-05-13 19:11:17 +09:00
|
|
|
import Vervis.Handler.Repo.Darcs
|
|
|
|
import Vervis.Handler.Repo.Git
|
2016-03-03 17:15:54 +09:00
|
|
|
import Vervis.Path
|
2016-04-18 02:55:23 +09:00
|
|
|
import Vervis.MediaType (chooseMediaType)
|
2016-03-03 17:15:54 +09:00
|
|
|
import Vervis.Model
|
2016-05-24 05:46:54 +09:00
|
|
|
import Vervis.Model.Ident
|
2016-05-03 09:33:49 +09:00
|
|
|
import Vervis.Model.Repo
|
2016-05-13 17:49:19 +09:00
|
|
|
import Vervis.Paginate
|
2016-04-14 01:17:34 +09:00
|
|
|
import Vervis.Readme
|
2016-04-13 15:55:39 +09:00
|
|
|
import Vervis.Render
|
2016-03-03 17:15:54 +09:00
|
|
|
import Vervis.Settings
|
2016-05-05 16:29:19 +09:00
|
|
|
import Vervis.SourceTree
|
2016-04-12 23:44:43 +09:00
|
|
|
import Vervis.Style
|
2016-05-06 19:29:02 +09:00
|
|
|
import Vervis.Widget.Repo
|
2016-05-31 10:52:04 +09:00
|
|
|
import Vervis.Widget.Sharer
|
2016-02-27 14:41:36 +09:00
|
|
|
|
2016-05-08 23:28:03 +09:00
|
|
|
import qualified Darcs.Local.Repository as D (createRepo)
|
2016-05-05 02:17:47 +09:00
|
|
|
import qualified Data.ByteString.Lazy as BL (ByteString)
|
|
|
|
import qualified Data.Git.Local as G (createRepo)
|
2016-05-24 05:46:54 +09:00
|
|
|
import qualified Vervis.Formatting as F
|
2016-05-04 20:44:06 +09:00
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
getReposR :: ShrIdent -> Handler Html
|
2016-04-13 02:37:31 +09:00
|
|
|
getReposR user = do
|
|
|
|
repos <- runDB $ select $ from $ \ (sharer, repo) -> do
|
2016-02-27 14:41:36 +09:00
|
|
|
where_ $
|
|
|
|
sharer ^. SharerIdent ==. val user &&.
|
2016-04-13 02:37:31 +09:00
|
|
|
sharer ^. SharerId ==. repo ^. RepoSharer
|
2016-02-27 14:41:36 +09:00
|
|
|
orderBy [asc $ repo ^. RepoIdent]
|
|
|
|
return $ repo ^. RepoIdent
|
2016-05-24 05:46:54 +09:00
|
|
|
defaultLayout $(widgetFile "repo/list")
|
2016-02-27 14:41:36 +09:00
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
postReposR :: ShrIdent -> Handler Html
|
2016-04-13 02:37:31 +09:00
|
|
|
postReposR user = do
|
2016-05-30 22:10:02 +09:00
|
|
|
Entity sid _sharer <- runDB $ getBy404 $ UniqueSharer user
|
2016-06-07 02:29:54 +09:00
|
|
|
((result, widget), enctype) <- runFormPost $ newRepoForm sid Nothing
|
2016-02-27 14:41:36 +09:00
|
|
|
case result of
|
2016-05-30 22:10:02 +09:00
|
|
|
FormSuccess nrp -> do
|
2016-05-04 20:44:06 +09:00
|
|
|
parent <- askSharerDir user
|
|
|
|
liftIO $ do
|
|
|
|
createDirectoryIfMissing True parent
|
2016-05-24 05:46:54 +09:00
|
|
|
let repoName =
|
2016-05-30 22:10:02 +09:00
|
|
|
unpack $ CI.foldedCase $ unRpIdent $ nrpIdent nrp
|
|
|
|
case nrpVcs nrp of
|
2016-05-05 02:17:47 +09:00
|
|
|
VCSDarcs -> D.createRepo parent repoName
|
|
|
|
VCSGit -> G.createRepo parent repoName
|
2016-06-07 14:17:54 +09:00
|
|
|
pid <- requireAuthId
|
2016-05-30 22:10:02 +09:00
|
|
|
runDB $ do
|
|
|
|
let repo = Repo
|
|
|
|
{ repoIdent = nrpIdent nrp
|
|
|
|
, repoSharer = sid
|
|
|
|
, repoVcs = nrpVcs nrp
|
|
|
|
, repoProject = nrpProj nrp
|
|
|
|
, repoDesc = nrpDesc nrp
|
|
|
|
, repoMainBranch = "master"
|
2019-01-30 07:24:32 +09:00
|
|
|
, repoCollabUser = Nothing
|
|
|
|
, repoCollabAnon = Nothing
|
2016-05-30 22:10:02 +09:00
|
|
|
}
|
|
|
|
rid <- insert repo
|
2016-06-01 16:35:22 +09:00
|
|
|
let collab = RepoCollab
|
|
|
|
{ repoCollabRepo = rid
|
|
|
|
, repoCollabPerson = pid
|
|
|
|
, repoCollabRole = nrpRole nrp
|
2016-05-30 22:10:02 +09:00
|
|
|
}
|
|
|
|
insert_ collab
|
2016-05-04 20:44:06 +09:00
|
|
|
setMessage "Repo added."
|
|
|
|
redirect $ ReposR user
|
2016-02-27 14:41:36 +09:00
|
|
|
FormMissing -> do
|
|
|
|
setMessage "Field(s) missing"
|
2016-05-24 05:46:54 +09:00
|
|
|
defaultLayout $(widgetFile "repo/new")
|
2016-05-04 20:44:06 +09:00
|
|
|
FormFailure _l -> do
|
|
|
|
setMessage "Repo creation failed, see errors below"
|
2016-05-24 05:46:54 +09:00
|
|
|
defaultLayout $(widgetFile "repo/new")
|
2016-02-27 14:41:36 +09:00
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
getRepoNewR :: ShrIdent -> Handler Html
|
2016-04-13 02:37:31 +09:00
|
|
|
getRepoNewR user = do
|
2016-05-30 22:10:02 +09:00
|
|
|
Entity sid _sharer <- runDB $ getBy404 $ UniqueSharer user
|
2016-06-07 02:29:54 +09:00
|
|
|
((_result, widget), enctype) <- runFormPost $ newRepoForm sid Nothing
|
2016-05-24 05:46:54 +09:00
|
|
|
defaultLayout $(widgetFile "repo/new")
|
2016-02-27 14:41:36 +09:00
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
selectRepo :: ShrIdent -> RpIdent -> AppDB Repo
|
2016-05-06 01:30:30 +09:00
|
|
|
selectRepo shar repo = do
|
2016-05-24 05:46:54 +09:00
|
|
|
Entity sid _s <- getBy404 $ UniqueSharer shar
|
2016-05-06 01:30:30 +09:00
|
|
|
Entity _rid r <- getBy404 $ UniqueRepo repo sid
|
|
|
|
return r
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
getRepoR :: ShrIdent -> RpIdent -> Handler Html
|
2016-05-06 01:30:30 +09:00
|
|
|
getRepoR shar repo = do
|
|
|
|
repository <- runDB $ selectRepo shar repo
|
2016-05-05 16:29:19 +09:00
|
|
|
case repoVcs repository of
|
2016-05-06 01:30:30 +09:00
|
|
|
VCSDarcs -> getDarcsRepoSource repository shar repo []
|
2016-05-05 16:29:19 +09:00
|
|
|
VCSGit ->
|
|
|
|
getGitRepoSource
|
2016-05-06 01:30:30 +09:00
|
|
|
repository shar repo (repoMainBranch repository) []
|
2016-05-05 16:29:19 +09:00
|
|
|
|
2016-06-06 06:11:05 +09:00
|
|
|
putRepoR :: ShrIdent -> RpIdent -> Handler Html
|
|
|
|
putRepoR shr rp = do
|
|
|
|
mer <- runDB $ do
|
|
|
|
Entity sid _ <- getBy404 $ UniqueSharer shr
|
|
|
|
er@(Entity rid r) <- getBy404 $ UniqueRepo rp sid
|
|
|
|
mwiki <- for (repoProject r) $ \ jid -> do
|
|
|
|
project <- getJust jid
|
|
|
|
return $ (== rid) <$> projectWiki project
|
|
|
|
return $ case mwiki of
|
|
|
|
Just (Just True) -> Nothing
|
2019-01-30 07:24:32 +09:00
|
|
|
_ -> Just (sid, er)
|
2016-06-06 06:11:05 +09:00
|
|
|
case mer of
|
|
|
|
Nothing -> do
|
|
|
|
setMessage "Repo used as a wiki, can't move between projects."
|
|
|
|
redirect $ RepoR shr rp
|
2019-01-30 07:24:32 +09:00
|
|
|
Just (sid, er@(Entity rid _)) -> do
|
|
|
|
((result, widget), enctype) <- runFormPost $ editRepoForm sid er
|
2016-06-06 06:11:05 +09:00
|
|
|
case result of
|
|
|
|
FormSuccess repository' -> do
|
|
|
|
runDB $ replace rid repository'
|
|
|
|
setMessage "Repository updated."
|
|
|
|
redirect $ RepoR shr rp
|
|
|
|
FormMissing -> do
|
|
|
|
setMessage "Field(s) missing."
|
|
|
|
defaultLayout $(widgetFile "repo/edit")
|
|
|
|
FormFailure _l -> do
|
|
|
|
setMessage "Repository update failed, see errors below."
|
|
|
|
defaultLayout $(widgetFile "repo/edit")
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
deleteRepoR :: ShrIdent -> RpIdent -> Handler Html
|
2016-05-14 04:23:56 +09:00
|
|
|
deleteRepoR shar repo = do
|
|
|
|
runDB $ do
|
2016-05-24 05:46:54 +09:00
|
|
|
Entity sid _s <- getBy404 $ UniqueSharer shar
|
2016-05-14 04:23:56 +09:00
|
|
|
Entity rid _r <- getBy404 $ UniqueRepo repo sid
|
|
|
|
delete rid
|
|
|
|
path <- askRepoDir shar repo
|
|
|
|
exists <- liftIO $ doesDirectoryExist path
|
|
|
|
if exists
|
|
|
|
then liftIO $ removeDirectoryRecursive path
|
|
|
|
else
|
|
|
|
$logWarn $ sformat
|
2016-05-24 05:46:54 +09:00
|
|
|
( "Deleted repo " % F.sharer % "/" % F.repo
|
2016-05-14 04:23:56 +09:00
|
|
|
% " from DB but repo dir doesn't exist"
|
|
|
|
)
|
|
|
|
shar repo
|
|
|
|
setMessage "Repo deleted."
|
|
|
|
redirect HomeR
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
postRepoR :: ShrIdent -> RpIdent -> Handler Html
|
2016-05-14 04:23:56 +09:00
|
|
|
postRepoR shar repo = do
|
|
|
|
mmethod <- lookupPostParam "_method"
|
|
|
|
case mmethod of
|
2016-06-06 06:11:05 +09:00
|
|
|
Just "PUT" -> putRepoR shar repo
|
2016-05-14 04:23:56 +09:00
|
|
|
Just "DELETE" -> deleteRepoR shar repo
|
|
|
|
_ -> notFound
|
|
|
|
|
2016-06-06 06:11:05 +09:00
|
|
|
getRepoEditR :: ShrIdent -> RpIdent -> Handler Html
|
|
|
|
getRepoEditR shr rp = do
|
2019-01-30 07:24:32 +09:00
|
|
|
(sid, er) <- runDB $ do
|
|
|
|
Entity sid _ <- getBy404 $ UniqueSharer shr
|
|
|
|
er <- getBy404 $ UniqueRepo rp sid
|
|
|
|
return (sid, er)
|
|
|
|
((_result, widget), enctype) <- runFormPost $ editRepoForm sid er
|
2016-06-06 06:11:05 +09:00
|
|
|
defaultLayout $(widgetFile "repo/edit")
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
getRepoSourceR :: ShrIdent -> RpIdent -> [Text] -> Handler Html
|
2016-05-06 01:30:30 +09:00
|
|
|
getRepoSourceR shar repo refdir = do
|
|
|
|
repository <- runDB $ selectRepo shar repo
|
2016-05-05 16:29:19 +09:00
|
|
|
case repoVcs repository of
|
2016-05-06 01:30:30 +09:00
|
|
|
VCSDarcs -> getDarcsRepoSource repository shar repo refdir
|
2016-05-05 16:29:19 +09:00
|
|
|
VCSGit -> case refdir of
|
|
|
|
[] -> notFound
|
2016-05-06 01:30:30 +09:00
|
|
|
(ref:dir) -> getGitRepoSource repository shar repo ref dir
|
|
|
|
|
2018-04-01 07:04:33 +09:00
|
|
|
getRepoHeadChangesR :: ShrIdent -> RpIdent -> Handler TypedContent
|
2016-05-06 01:30:30 +09:00
|
|
|
getRepoHeadChangesR user repo = do
|
|
|
|
repository <- runDB $ selectRepo user repo
|
|
|
|
case repoVcs repository of
|
|
|
|
VCSDarcs -> getDarcsRepoHeadChanges user repo
|
|
|
|
VCSGit -> getGitRepoHeadChanges repository user repo
|
|
|
|
|
2018-04-01 07:04:33 +09:00
|
|
|
getRepoChangesR :: ShrIdent -> RpIdent -> Text -> Handler TypedContent
|
2016-05-06 01:30:30 +09:00
|
|
|
getRepoChangesR shar repo ref = do
|
|
|
|
repository <- runDB $ selectRepo shar repo
|
|
|
|
case repoVcs repository of
|
|
|
|
VCSDarcs -> getDarcsRepoChanges shar repo ref
|
|
|
|
VCSGit -> getGitRepoChanges shar repo ref
|
2016-05-29 23:13:25 +09:00
|
|
|
|
2018-05-18 00:46:57 +09:00
|
|
|
getRepoPatchR :: ShrIdent -> RpIdent -> Text -> Handler Html
|
|
|
|
getRepoPatchR shr rp ref = do
|
|
|
|
repository <- runDB $ selectRepo shr rp
|
|
|
|
case repoVcs repository of
|
2018-07-08 01:05:10 +09:00
|
|
|
VCSDarcs -> getDarcsPatch shr rp ref
|
2018-05-18 08:33:37 +09:00
|
|
|
VCSGit -> getGitPatch shr rp ref
|
2018-05-18 00:46:57 +09:00
|
|
|
|
2016-05-29 23:13:25 +09:00
|
|
|
getRepoDevsR :: ShrIdent -> RpIdent -> Handler Html
|
2016-05-31 10:52:04 +09:00
|
|
|
getRepoDevsR shr rp = do
|
|
|
|
devs <- runDB $ do
|
|
|
|
rid <- do
|
|
|
|
Entity s _ <- getBy404 $ UniqueSharer shr
|
|
|
|
Entity r _ <- getBy404 $ UniqueRepo rp s
|
|
|
|
return r
|
2019-01-30 07:24:32 +09:00
|
|
|
select $ from $ \ (collab `InnerJoin`
|
|
|
|
person `InnerJoin`
|
|
|
|
sharer `LeftOuterJoin`
|
|
|
|
role) -> do
|
|
|
|
on $ collab ^. RepoCollabRole ==. role ?. ProjectRoleId
|
|
|
|
on $ person ^. PersonIdent ==. sharer ^. SharerId
|
|
|
|
on $ collab ^. RepoCollabPerson ==. person ^. PersonId
|
|
|
|
where_ $ collab ^. RepoCollabRepo ==. val rid
|
|
|
|
return (sharer, role ?. ProjectRoleIdent)
|
2016-05-31 10:52:04 +09:00
|
|
|
defaultLayout $(widgetFile "repo/collab/list")
|
2016-05-29 23:13:25 +09:00
|
|
|
|
|
|
|
postRepoDevsR :: ShrIdent -> RpIdent -> Handler Html
|
2016-05-31 10:52:04 +09:00
|
|
|
postRepoDevsR shr rp = do
|
2016-06-07 02:29:54 +09:00
|
|
|
(sid, mjid, rid) <- runDB $ do
|
2016-05-31 10:52:04 +09:00
|
|
|
Entity s _ <- getBy404 $ UniqueSharer shr
|
2016-06-05 22:59:48 +09:00
|
|
|
Entity r repository <- getBy404 $ UniqueRepo rp s
|
2016-06-07 02:29:54 +09:00
|
|
|
return (s, repoProject repository, r)
|
|
|
|
((result, widget), enctype) <- runFormPost $ newRepoCollabForm sid mjid rid
|
2016-05-31 10:52:04 +09:00
|
|
|
case result of
|
|
|
|
FormSuccess nc -> do
|
|
|
|
runDB $ do
|
2016-06-01 16:35:22 +09:00
|
|
|
let collab = RepoCollab
|
|
|
|
{ repoCollabRepo = rid
|
|
|
|
, repoCollabPerson = ncPerson nc
|
|
|
|
, repoCollabRole = ncRole nc
|
2016-05-31 10:52:04 +09:00
|
|
|
}
|
|
|
|
insert_ collab
|
|
|
|
setMessage "Collaborator added."
|
|
|
|
redirect $ RepoDevsR shr rp
|
|
|
|
FormMissing -> do
|
|
|
|
setMessage "Field(s) missing"
|
|
|
|
defaultLayout $(widgetFile "repo/collab/new")
|
|
|
|
FormFailure _l -> do
|
|
|
|
setMessage "Operation failed, see errors below"
|
|
|
|
defaultLayout $(widgetFile "repo/collab/new")
|
2016-05-29 23:13:25 +09:00
|
|
|
|
|
|
|
getRepoDevNewR :: ShrIdent -> RpIdent -> Handler Html
|
2016-05-31 10:52:04 +09:00
|
|
|
getRepoDevNewR shr rp = do
|
2016-06-07 02:29:54 +09:00
|
|
|
(sid, mjid, rid) <- runDB $ do
|
2016-05-31 10:52:04 +09:00
|
|
|
Entity s _ <- getBy404 $ UniqueSharer shr
|
2016-06-05 22:59:48 +09:00
|
|
|
Entity r repository <- getBy404 $ UniqueRepo rp s
|
2016-06-07 02:29:54 +09:00
|
|
|
return (s, repoProject repository, r)
|
2016-06-05 22:59:48 +09:00
|
|
|
((_result, widget), enctype) <-
|
2016-06-07 02:29:54 +09:00
|
|
|
runFormPost $ newRepoCollabForm sid mjid rid
|
2016-05-31 10:52:04 +09:00
|
|
|
defaultLayout $(widgetFile "repo/collab/new")
|
2016-05-29 23:13:25 +09:00
|
|
|
|
|
|
|
getRepoDevR :: ShrIdent -> RpIdent -> ShrIdent -> Handler Html
|
2016-05-31 10:52:04 +09:00
|
|
|
getRepoDevR shr rp dev = do
|
2019-01-30 07:24:32 +09:00
|
|
|
mrl <- runDB $ do
|
2016-05-31 10:52:04 +09:00
|
|
|
rid <- do
|
|
|
|
Entity s _ <- getBy404 $ UniqueSharer shr
|
|
|
|
Entity r _ <- getBy404 $ UniqueRepo rp s
|
|
|
|
return r
|
|
|
|
pid <- do
|
|
|
|
Entity s _ <- getBy404 $ UniqueSharer dev
|
|
|
|
Entity p _ <- getBy404 $ UniquePersonIdent s
|
|
|
|
return p
|
2016-06-01 16:35:22 +09:00
|
|
|
Entity _cid collab <- getBy404 $ UniqueRepoCollab rid pid
|
2019-01-30 07:24:32 +09:00
|
|
|
fmap projectRoleIdent <$> traverse getJust (repoCollabRole collab)
|
2016-05-31 10:52:04 +09:00
|
|
|
defaultLayout $(widgetFile "repo/collab/one")
|
2016-05-29 23:13:25 +09:00
|
|
|
|
|
|
|
deleteRepoDevR :: ShrIdent -> RpIdent -> ShrIdent -> Handler Html
|
2016-05-30 23:32:20 +09:00
|
|
|
deleteRepoDevR shr rp dev = do
|
|
|
|
runDB $ do
|
|
|
|
rid <- do
|
|
|
|
Entity s _ <- getBy404 $ UniqueSharer shr
|
|
|
|
Entity r _ <- getBy404 $ UniqueRepo rp s
|
|
|
|
return r
|
|
|
|
pid <- do
|
|
|
|
Entity s _ <- getBy404 $ UniqueSharer dev
|
|
|
|
Entity p _ <- getBy404 $ UniquePersonIdent s
|
|
|
|
return p
|
2016-06-01 16:35:22 +09:00
|
|
|
Entity cid _collab <- getBy404 $ UniqueRepoCollab rid pid
|
2016-05-30 23:32:20 +09:00
|
|
|
delete cid
|
|
|
|
setMessage "Collaborator removed."
|
|
|
|
redirect $ RepoDevsR shr rp
|
2016-05-29 23:13:25 +09:00
|
|
|
|
|
|
|
postRepoDevR :: ShrIdent -> RpIdent -> ShrIdent -> Handler Html
|
2016-05-30 23:32:20 +09:00
|
|
|
postRepoDevR shr rp dev = do
|
|
|
|
mmethod <- lookupPostParam "_method"
|
|
|
|
case mmethod of
|
|
|
|
Just "DELETE" -> deleteRepoDevR shr rp dev
|
|
|
|
_ -> notFound
|