2013-03-31 20:38:05 +00:00
|
|
|
{- git-annex assistant webapp repository deletion
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2013 Joey Hess <id@joeyh.name>
|
2013-03-31 20:38:05 +00:00
|
|
|
-
|
|
|
|
- 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.DaemonStatus
|
2013-03-31 23:00:43 +00:00
|
|
|
import Assistant.ScanRemotes
|
2013-10-26 20:54:49 +00:00
|
|
|
import Assistant.Sync
|
2013-03-31 20:38:05 +00:00
|
|
|
import qualified Remote
|
|
|
|
import qualified Git
|
2020-11-04 18:20:37 +00:00
|
|
|
import Config.Files.AutoStart
|
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-09-29 18:51:49 +00:00
|
|
|
import Annex.UUID
|
2016-07-12 18:18:35 +00:00
|
|
|
import Command.Uninit (prepareRemoveAnnexDir)
|
2013-03-31 20:38:05 +00:00
|
|
|
|
2013-04-03 21:01:40 +00:00
|
|
|
import qualified Data.Text as T
|
|
|
|
import qualified Data.Map as M
|
2013-03-31 20:38:05 +00:00
|
|
|
|
2013-06-27 05:15:28 +00:00
|
|
|
notCurrentRepo :: UUID -> Handler Html -> Handler Html
|
2013-09-29 18:51:49 +00:00
|
|
|
notCurrentRepo uuid a = do
|
|
|
|
u <- liftAnnex getUUID
|
|
|
|
if u == uuid
|
|
|
|
then redirect DeleteCurrentRepositoryR
|
|
|
|
else go =<< liftAnnex (Remote.remoteFromUUID uuid)
|
2013-04-04 01:26:38 +00:00
|
|
|
where
|
2023-04-10 17:38:14 +00:00
|
|
|
go Nothing = giveup "Unknown UUID"
|
2013-04-04 01:26:38 +00:00
|
|
|
go (Just _) = a
|
|
|
|
|
2013-06-27 05:15:28 +00:00
|
|
|
getDeleteRepositoryR :: UUID -> Handler Html
|
2016-11-14 18:26:20 +00:00
|
|
|
getDeleteRepositoryR uuid = notCurrentRepo uuid $ do
|
2013-04-04 01:26:38 +00:00
|
|
|
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-06-27 05:15:28 +00:00
|
|
|
getStartDeleteRepositoryR :: UUID -> Handler Html
|
2013-04-04 00:54:53 +00:00
|
|
|
getStartDeleteRepositoryR uuid = do
|
2023-04-10 17:38:14 +00:00
|
|
|
remote <- fromMaybe (giveup "unknown remote")
|
2013-03-31 23:00:43 +00:00
|
|
|
<$> 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-06-27 05:15:28 +00:00
|
|
|
getFinishDeleteRepositoryR :: UUID -> Handler Html
|
2013-04-04 00:54:53 +00:00
|
|
|
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. -}
|
2020-09-22 17:52:26 +00:00
|
|
|
gitrepo <- liftAnnex $ M.notMember uuid <$> remoteConfigMap
|
2013-04-03 21:01:40 +00:00
|
|
|
$(widgetFile "configurators/delete/finished")
|
|
|
|
|
2013-06-27 05:15:28 +00:00
|
|
|
getDeleteCurrentRepositoryR :: Handler Html
|
2013-03-31 20:38:05 +00:00
|
|
|
getDeleteCurrentRepositoryR = deleteCurrentRepository
|
|
|
|
|
2013-06-27 05:15:28 +00:00
|
|
|
postDeleteCurrentRepositoryR :: Handler Html
|
2013-03-31 20:38:05 +00:00
|
|
|
postDeleteCurrentRepositoryR = deleteCurrentRepository
|
|
|
|
|
2013-06-27 05:15:28 +00:00
|
|
|
deleteCurrentRepository :: Handler Html
|
2013-03-31 20:38:05 +00:00
|
|
|
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
|
2017-09-20 17:27:59 +00:00
|
|
|
havedataremotes <- haveremotes downloadRemotes
|
2013-06-03 17:51:54 +00:00
|
|
|
((result, form), enctype) <- liftH $
|
2014-04-18 00:07:09 +00:00
|
|
|
runFormPostNoToken $ renderBootstrap3 bootstrapFormLayout $
|
|
|
|
sanityVerifierAForm $ SanityVerifier magicphrase
|
2013-03-31 20:38:05 +00:00
|
|
|
case result of
|
2013-06-03 17:51:54 +00:00
|
|
|
FormSuccess _ -> liftH $ do
|
2019-12-09 17:49:05 +00:00
|
|
|
dir <- liftAnnex $ fromRawFilePath <$> fromRepo Git.repoPath
|
2013-03-31 20:38:05 +00:00
|
|
|
liftIO $ removeAutoStartFile dir
|
|
|
|
|
|
|
|
{- Disable syncing to this repository, and all
|
|
|
|
- remotes. This stops all transfers, and all
|
|
|
|
- file watching. -}
|
2013-10-26 20:54:49 +00:00
|
|
|
liftAssistant $ do
|
|
|
|
changeSyncable Nothing False
|
|
|
|
rs <- syncRemotes <$> getDaemonStatus
|
|
|
|
mapM_ (\r -> changeSyncable (Just r) False) rs
|
2013-03-31 20:38:05 +00:00
|
|
|
|
2016-07-12 18:18:35 +00:00
|
|
|
liftAnnex $ prepareRemoveAnnexDir dir
|
2020-11-04 18:20:37 +00:00
|
|
|
liftIO $ removeDirectoryRecursive . fromRawFilePath
|
|
|
|
=<< absPath (toRawFilePath dir)
|
2013-03-31 20:38:05 +00:00
|
|
|
|
|
|
|
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
|
2014-04-18 00:07:09 +00:00
|
|
|
<$> areq checksanity (bfs "Confirm deletion?") Nothing
|
2013-03-31 20:38:05 +00:00
|
|
|
where
|
|
|
|
checksanity = checkBool (\input -> SanityVerifier input == template)
|
|
|
|
insane textField
|
|
|
|
|
|
|
|
insane = "Maybe this is not a good idea..." :: Text
|
|
|
|
|
2013-06-27 05:15:28 +00:00
|
|
|
deletionPage :: Widget -> Handler Html
|
2013-03-31 23:00:43 +00:00
|
|
|
deletionPage = page "Delete repository" (Just Configuration)
|
|
|
|
|
2013-06-27 05:15:28 +00:00
|
|
|
dangerPage :: Widget -> Handler Html
|
2013-03-31 20:38:05 +00:00
|
|
|
dangerPage = page "Danger danger danger" (Just Configuration)
|
|
|
|
|
|
|
|
magicphrase :: Text
|
|
|
|
magicphrase = "Yes, please do as I say!"
|