Repo deletion button
This commit is contained in:
parent
9295a9ba8c
commit
4d16203e5d
5 changed files with 45 additions and 4 deletions
|
@ -42,7 +42,7 @@
|
||||||
|
|
||||||
/u/#Text/r ReposR GET POST
|
/u/#Text/r ReposR GET POST
|
||||||
/u/#Text/r/!new RepoNewR GET
|
/u/#Text/r/!new RepoNewR GET
|
||||||
/u/#Text/r/#Text RepoR GET
|
/u/#Text/r/#Text RepoR GET DELETE POST
|
||||||
/u/#Text/r/#Text/s/+Texts RepoSourceR GET
|
/u/#Text/r/#Text/s/+Texts RepoSourceR GET
|
||||||
/u/#Text/r/#Text/c RepoHeadChangesR GET
|
/u/#Text/r/#Text/c RepoHeadChangesR GET
|
||||||
/u/#Text/r/#Text/c/#Text RepoChangesR GET
|
/u/#Text/r/#Text/c/#Text RepoChangesR GET
|
||||||
|
|
|
@ -125,6 +125,8 @@ instance Yesod App where
|
||||||
loggedInAs user "You can’t watch keys of other users"
|
loggedInAs user "You can’t watch keys of other users"
|
||||||
isAuthorized (KeyNewR user) _ =
|
isAuthorized (KeyNewR user) _ =
|
||||||
loggedInAs user "You can’t add keys for other users"
|
loggedInAs user "You can’t add keys for other users"
|
||||||
|
isAuthorized (RepoR shar _) True =
|
||||||
|
loggedInAs shar "You can’t modify repos for other users"
|
||||||
isAuthorized (TicketNewR _ _) _ = loggedIn
|
isAuthorized (TicketNewR _ _) _ = loggedIn
|
||||||
isAuthorized (TicketR user _ _) True =
|
isAuthorized (TicketR user _ _) True =
|
||||||
loggedInAs user "Only project members can modify this ticket"
|
loggedInAs user "Only project members can modify this ticket"
|
||||||
|
|
|
@ -18,6 +18,8 @@ module Vervis.Handler.Repo
|
||||||
, postReposR
|
, postReposR
|
||||||
, getRepoNewR
|
, getRepoNewR
|
||||||
, getRepoR
|
, getRepoR
|
||||||
|
, deleteRepoR
|
||||||
|
, postRepoR
|
||||||
, getRepoSourceR
|
, getRepoSourceR
|
||||||
, getRepoHeadChangesR
|
, getRepoHeadChangesR
|
||||||
, getRepoChangesR
|
, getRepoChangesR
|
||||||
|
@ -34,7 +36,7 @@ where
|
||||||
-- [x] write the git and mkdir parts that actually create the repo
|
-- [x] write the git and mkdir parts that actually create the repo
|
||||||
-- [x] make repo view that shows a table of commits
|
-- [x] make repo view that shows a table of commits
|
||||||
|
|
||||||
import ClassyPrelude.Conduit hiding (last, unpack)
|
import ClassyPrelude.Conduit hiding (last, unpack, delete)
|
||||||
import Yesod hiding (Header, parseTime, (==.))
|
import Yesod hiding (Header, parseTime, (==.))
|
||||||
import Yesod.Auth
|
import Yesod.Auth
|
||||||
|
|
||||||
|
@ -54,9 +56,10 @@ import Data.List (inits)
|
||||||
import Data.Text (unpack)
|
import Data.Text (unpack)
|
||||||
import Data.Text.Encoding (decodeUtf8With)
|
import Data.Text.Encoding (decodeUtf8With)
|
||||||
import Data.Text.Encoding.Error (lenientDecode)
|
import Data.Text.Encoding.Error (lenientDecode)
|
||||||
import Database.Esqueleto
|
import Database.Esqueleto hiding (delete, (%))
|
||||||
import Data.Hourglass (timeConvert)
|
import Data.Hourglass (timeConvert)
|
||||||
import System.Directory (createDirectoryIfMissing)
|
import Formatting (sformat, stext, (%))
|
||||||
|
import System.Directory
|
||||||
import System.Hourglass (dateCurrent)
|
import System.Hourglass (dateCurrent)
|
||||||
|
|
||||||
import qualified Data.DList as D
|
import qualified Data.DList as D
|
||||||
|
@ -149,6 +152,32 @@ getRepoR shar repo = do
|
||||||
getGitRepoSource
|
getGitRepoSource
|
||||||
repository shar repo (repoMainBranch repository) []
|
repository shar repo (repoMainBranch repository) []
|
||||||
|
|
||||||
|
deleteRepoR :: Text -> Text -> Handler Html
|
||||||
|
deleteRepoR shar repo = do
|
||||||
|
runDB $ do
|
||||||
|
Entity sid _s <- getBy404 $ UniqueSharerIdent shar
|
||||||
|
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
|
||||||
|
( "Deleted repo " % stext % "/" % stext
|
||||||
|
% " from DB but repo dir doesn't exist"
|
||||||
|
)
|
||||||
|
shar repo
|
||||||
|
setMessage "Repo deleted."
|
||||||
|
redirect HomeR
|
||||||
|
|
||||||
|
postRepoR :: Text -> Text -> Handler Html
|
||||||
|
postRepoR shar repo = do
|
||||||
|
mmethod <- lookupPostParam "_method"
|
||||||
|
case mmethod of
|
||||||
|
Just "DELETE" -> deleteRepoR shar repo
|
||||||
|
_ -> notFound
|
||||||
|
|
||||||
getRepoSourceR :: Text -> Text -> [Text] -> Handler Html
|
getRepoSourceR :: Text -> Text -> [Text] -> Handler Html
|
||||||
getRepoSourceR shar repo refdir = do
|
getRepoSourceR shar repo refdir = do
|
||||||
repository <- runDB $ selectRepo shar repo
|
repository <- runDB $ selectRepo shar repo
|
||||||
|
|
|
@ -15,6 +15,11 @@ $# <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||||
$maybe desc <- repoDesc repository
|
$maybe desc <- repoDesc repository
|
||||||
<p>#{desc}
|
<p>#{desc}
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<form method=POST action=@{RepoR user repo}>
|
||||||
|
<input type=hidden name=_method value=DELETE>
|
||||||
|
<input type=submit value="Delete this repo">
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<a href=@{RepoHeadChangesR user repo}>Changes
|
<a href=@{RepoHeadChangesR user repo}>Changes
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,11 @@ $# <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||||
$maybe desc <- repoDesc repository
|
$maybe desc <- repoDesc repository
|
||||||
<p>#{desc}
|
<p>#{desc}
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<form method=POST action=@{RepoR user repo}>
|
||||||
|
<input type=hidden name=_method value=DELETE>
|
||||||
|
<input type=submit value="Delete this repo">
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<a href=@{RepoHeadChangesR user repo}>Commits
|
<a href=@{RepoHeadChangesR user repo}>Commits
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue