2013-03-31 20:38:05 +00:00
|
|
|
{- git-annex assistant webapp repository deletion
|
|
|
|
-
|
|
|
|
- Copyright 2013 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
2013-06-05 01:02:09 +00:00
|
|
|
{-# LANGUAGE QuasiQuotes, TemplateHaskell, OverloadedStrings #-}
|
2013-03-31 20:38:05 +00:00
|
|
|
|
|
|
|
module Assistant.WebApp.Configurators.Delete where
|
|
|
|
|
|
|
|
import Assistant.WebApp.Common
|
2013-04-03 21:01:40 +00:00
|
|
|
import Assistant.DeleteRemote
|
2013-03-31 20:38:05 +00:00
|
|
|
import Assistant.WebApp.Utility
|
|
|
|
import Assistant.DaemonStatus
|
2013-03-31 23:00:43 +00:00
|
|
|
import Assistant.ScanRemotes
|
2013-03-31 20:38:05 +00:00
|
|
|
import qualified Remote
|
|
|
|
import qualified Git
|
2013-04-23 15:38:52 +00:00
|
|
|
import Config.Files
|
2013-03-31 20:38:05 +00:00
|
|
|
import Utility.FileMode
|
2013-03-31 23:00:43 +00:00
|
|
|
import Logs.Trust
|
2013-04-03 21:01:40 +00:00
|
|
|
import Logs.Remote
|
2013-03-31 23:00:43 +00:00
|
|
|
import Logs.PreferredContent
|
|
|
|
import Types.StandardGroups
|
2013-03-31 20:38:05 +00:00
|
|
|
|
|
|
|
import System.IO.HVFS (SystemFS(..))
|
2013-04-03 21:01:40 +00:00
|
|
|
import qualified Data.Text as T
|
|
|
|
import qualified Data.Map as M
|
2013-05-12 23:13:38 +00:00
|
|
|
import System.Path
|
2013-03-31 20:38:05 +00:00
|
|
|
|
2013-04-04 01:26:38 +00:00
|
|
|
notCurrentRepo :: UUID -> Handler RepHtml -> Handler RepHtml
|
|
|
|
notCurrentRepo uuid a = go =<< liftAnnex (Remote.remoteFromUUID uuid)
|
|
|
|
where
|
|
|
|
go Nothing = redirect DeleteCurrentRepositoryR
|
|
|
|
go (Just _) = a
|
|
|
|
|
2013-04-04 00:54:53 +00:00
|
|
|
getDisableRepositoryR :: UUID -> Handler RepHtml
|
2013-04-04 01:26:38 +00:00
|
|
|
getDisableRepositoryR uuid = notCurrentRepo uuid $ do
|
2013-04-04 00:54:53 +00:00
|
|
|
void $ liftAssistant $ disableRemote uuid
|
|
|
|
redirect DashboardR
|
|
|
|
|
2013-03-31 20:38:05 +00:00
|
|
|
getDeleteRepositoryR :: UUID -> Handler RepHtml
|
2013-04-04 01:26:38 +00:00
|
|
|
getDeleteRepositoryR uuid = notCurrentRepo uuid $
|
|
|
|
deletionPage $ do
|
2013-04-03 21:01:40 +00:00
|
|
|
reponame <- liftAnnex $ Remote.prettyUUID uuid
|
2013-04-04 00:54:53 +00:00
|
|
|
$(widgetFile "configurators/delete/start")
|
2013-03-31 20:38:05 +00:00
|
|
|
|
2013-04-04 00:54:53 +00:00
|
|
|
getStartDeleteRepositoryR :: UUID -> Handler RepHtml
|
|
|
|
getStartDeleteRepositoryR uuid = do
|
2013-03-31 23:00:43 +00:00
|
|
|
remote <- fromMaybe (error "unknown remote")
|
|
|
|
<$> liftAnnex (Remote.remoteFromUUID uuid)
|
|
|
|
liftAnnex $ do
|
|
|
|
trustSet uuid UnTrusted
|
|
|
|
setStandardGroup uuid UnwantedGroup
|
|
|
|
liftAssistant $ addScanRemotes True [remote]
|
2013-04-04 00:54:53 +00:00
|
|
|
redirect DashboardR
|
2013-03-31 20:38:05 +00:00
|
|
|
|
2013-04-04 00:54:53 +00:00
|
|
|
getFinishDeleteRepositoryR :: UUID -> Handler RepHtml
|
|
|
|
getFinishDeleteRepositoryR uuid = deletionPage $ do
|
|
|
|
void $ liftAssistant $ removeRemote uuid
|
2013-03-31 20:38:05 +00:00
|
|
|
|
2013-04-03 21:01:40 +00:00
|
|
|
reponame <- liftAnnex $ Remote.prettyUUID uuid
|
|
|
|
{- If it's not listed in the remote log, it must be a git repo. -}
|
|
|
|
gitrepo <- liftAnnex $ M.notMember uuid <$> readRemoteLog
|
|
|
|
$(widgetFile "configurators/delete/finished")
|
|
|
|
|
2013-03-31 20:38:05 +00:00
|
|
|
getDeleteCurrentRepositoryR :: Handler RepHtml
|
|
|
|
getDeleteCurrentRepositoryR = deleteCurrentRepository
|
|
|
|
|
|
|
|
postDeleteCurrentRepositoryR :: Handler RepHtml
|
|
|
|
postDeleteCurrentRepositoryR = deleteCurrentRepository
|
|
|
|
|
|
|
|
deleteCurrentRepository :: Handler RepHtml
|
|
|
|
deleteCurrentRepository = dangerPage $ do
|
2013-06-03 17:51:54 +00:00
|
|
|
reldir <- fromJust . relDir <$> liftH getYesod
|
2013-03-31 20:38:05 +00:00
|
|
|
havegitremotes <- haveremotes syncGitRemotes
|
|
|
|
havedataremotes <- haveremotes syncDataRemotes
|
2013-06-03 17:51:54 +00:00
|
|
|
((result, form), enctype) <- liftH $
|
2013-03-31 20:38:05 +00:00
|
|
|
runFormPost $ renderBootstrap $ sanityVerifierAForm $
|
|
|
|
SanityVerifier magicphrase
|
|
|
|
case result of
|
2013-06-03 17:51:54 +00:00
|
|
|
FormSuccess _ -> liftH $ do
|
2013-03-31 20:38:05 +00:00
|
|
|
dir <- liftAnnex $ fromRepo Git.repoPath
|
|
|
|
liftIO $ removeAutoStartFile dir
|
|
|
|
|
|
|
|
{- Disable syncing to this repository, and all
|
|
|
|
- remotes. This stops all transfers, and all
|
|
|
|
- file watching. -}
|
|
|
|
changeSyncable Nothing False
|
|
|
|
rs <- liftAssistant $ syncRemotes <$> getDaemonStatus
|
|
|
|
mapM_ (\r -> changeSyncable (Just r) False) rs
|
|
|
|
|
|
|
|
{- Make all directories writable, so all annexed
|
|
|
|
- content can be deleted. -}
|
|
|
|
liftIO $ do
|
|
|
|
recurseDir SystemFS dir >>=
|
|
|
|
filterM doesDirectoryExist >>=
|
|
|
|
mapM_ allowWrite
|
|
|
|
removeDirectoryRecursive dir
|
|
|
|
|
|
|
|
redirect ShutdownConfirmedR
|
|
|
|
_ -> $(widgetFile "configurators/delete/currentrepository")
|
|
|
|
where
|
|
|
|
haveremotes selector = not . null . selector
|
|
|
|
<$> liftAssistant getDaemonStatus
|
|
|
|
|
|
|
|
data SanityVerifier = SanityVerifier T.Text
|
|
|
|
deriving (Eq)
|
|
|
|
|
2013-06-03 20:33:05 +00:00
|
|
|
sanityVerifierAForm :: SanityVerifier -> MkAForm SanityVerifier
|
2013-03-31 20:38:05 +00:00
|
|
|
sanityVerifierAForm template = SanityVerifier
|
|
|
|
<$> areq checksanity "Confirm deletion?" Nothing
|
|
|
|
where
|
|
|
|
checksanity = checkBool (\input -> SanityVerifier input == template)
|
|
|
|
insane textField
|
|
|
|
|
|
|
|
insane = "Maybe this is not a good idea..." :: Text
|
|
|
|
|
2013-03-31 23:00:43 +00:00
|
|
|
deletionPage :: Widget -> Handler RepHtml
|
|
|
|
deletionPage = page "Delete repository" (Just Configuration)
|
|
|
|
|
2013-03-31 20:38:05 +00:00
|
|
|
dangerPage :: Widget -> Handler RepHtml
|
|
|
|
dangerPage = page "Danger danger danger" (Just Configuration)
|
|
|
|
|
|
|
|
magicphrase :: Text
|
|
|
|
magicphrase = "Yes, please do as I say!"
|