mirror of
https://github.com/commercialhaskell/stackage-server.git
synced 2026-01-26 02:41:56 +01:00
Banned tag admin page
Pinging @chrisdone, decided to just bite the bullet and do it anyway
This commit is contained in:
parent
985f48a6dc
commit
3fb5375230
@ -61,6 +61,7 @@ import Handler.Package
|
|||||||
import Handler.PackageList
|
import Handler.PackageList
|
||||||
import Handler.CompressorStatus
|
import Handler.CompressorStatus
|
||||||
import Handler.Tag
|
import Handler.Tag
|
||||||
|
import Handler.BannedTags
|
||||||
|
|
||||||
-- This line actually creates our YesodDispatch instance. It is the second half
|
-- This line actually creates our YesodDispatch instance. It is the second half
|
||||||
-- of the call to mkYesodData which occurs in Foundation.hs. Please see the
|
-- of the call to mkYesodData which occurs in Foundation.hs. Please see the
|
||||||
|
|||||||
37
Handler/BannedTags.hs
Normal file
37
Handler/BannedTags.hs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
module Handler.BannedTags where
|
||||||
|
|
||||||
|
import Import
|
||||||
|
import Data.Slug (unSlug, mkSlug, Slug)
|
||||||
|
|
||||||
|
checkSlugs :: Monad m => Textarea -> m (Either Text [Slug])
|
||||||
|
checkSlugs (Textarea t) =
|
||||||
|
return $ first tshow $ (mapM mkSlug $ filter (not . null) $ lines $ filter (/= '\r') t)
|
||||||
|
|
||||||
|
fromSlugs :: [Slug] -> Textarea
|
||||||
|
fromSlugs = Textarea . unlines . map unSlug
|
||||||
|
|
||||||
|
getBannedTagsR :: Handler Html
|
||||||
|
getBannedTagsR = do
|
||||||
|
Entity _ user <- requireAuth
|
||||||
|
extra <- getExtra
|
||||||
|
when (unSlug (userHandle user) `notMember` adminUsers extra)
|
||||||
|
$ permissionDenied "You are not an administrator"
|
||||||
|
curr <- fmap (map (bannedTagTag . entityVal))
|
||||||
|
$ runDB $ selectList [] [Asc BannedTagTag]
|
||||||
|
((res, widget), enctype) <- runFormPost $ renderDivs
|
||||||
|
$ areq
|
||||||
|
(checkMMap checkSlugs fromSlugs textareaField)
|
||||||
|
"Banned tags (one per line)" $ Just curr
|
||||||
|
case res of
|
||||||
|
FormSuccess tags -> do
|
||||||
|
runDB $ do
|
||||||
|
deleteWhere ([] :: [Filter BannedTag])
|
||||||
|
insertMany_ $ map BannedTag tags
|
||||||
|
setMessage "Tags updated"
|
||||||
|
redirect BannedTagsR
|
||||||
|
_ -> defaultLayout $ do
|
||||||
|
setTitle "Banned Tags"
|
||||||
|
$(widgetFile "banned-tags")
|
||||||
|
|
||||||
|
putBannedTagsR :: Handler Html
|
||||||
|
putBannedTagsR = getBannedTagsR
|
||||||
@ -67,6 +67,7 @@ widgetFile = (if development then widgetFileReload
|
|||||||
data Extra = Extra
|
data Extra = Extra
|
||||||
{ storeConfig :: !BlobStoreConfig
|
{ storeConfig :: !BlobStoreConfig
|
||||||
, hackageRoot :: !HackageRoot
|
, hackageRoot :: !HackageRoot
|
||||||
|
, adminUsers :: !(HashSet Text)
|
||||||
}
|
}
|
||||||
deriving Show
|
deriving Show
|
||||||
|
|
||||||
@ -74,6 +75,7 @@ parseExtra :: DefaultEnv -> Object -> Parser Extra
|
|||||||
parseExtra _ o = Extra
|
parseExtra _ o = Extra
|
||||||
<$> o .: "blob-store"
|
<$> o .: "blob-store"
|
||||||
<*> (HackageRoot <$> o .: "hackage-root")
|
<*> (HackageRoot <$> o .: "hackage-root")
|
||||||
|
<*> o .:? "admin-users" .!= mempty
|
||||||
|
|
||||||
data BlobStoreConfig = BSCFile !FilePath
|
data BlobStoreConfig = BSCFile !FilePath
|
||||||
| BSCAWS !FilePath !Text !Text !Text !Text
|
| BSCAWS !FilePath !Text !Text !Text !Text
|
||||||
|
|||||||
@ -31,4 +31,5 @@
|
|||||||
/package/#PackageName/unlike PackageUnlikeR POST
|
/package/#PackageName/unlike PackageUnlikeR POST
|
||||||
/package/#PackageName/tag PackageTagR POST
|
/package/#PackageName/tag PackageTagR POST
|
||||||
/tags TagListR GET
|
/tags TagListR GET
|
||||||
/tag/#Slug TagR GET
|
/tag/#Slug TagR GET
|
||||||
|
/banned-tags BannedTagsR GET PUT
|
||||||
|
|||||||
@ -3,6 +3,8 @@ Default: &defaults
|
|||||||
port: 3000
|
port: 3000
|
||||||
approot: "http://localhost:3000"
|
approot: "http://localhost:3000"
|
||||||
hackage-root: http://hackage.fpcomplete.com
|
hackage-root: http://hackage.fpcomplete.com
|
||||||
|
admin-users:
|
||||||
|
- fpcomplete
|
||||||
|
|
||||||
Development:
|
Development:
|
||||||
<<: *defaults
|
<<: *defaults
|
||||||
|
|||||||
@ -46,6 +46,7 @@ library
|
|||||||
Handler.PackageList
|
Handler.PackageList
|
||||||
Handler.CompressorStatus
|
Handler.CompressorStatus
|
||||||
Handler.Tag
|
Handler.Tag
|
||||||
|
Handler.BannedTags
|
||||||
|
|
||||||
if flag(dev) || flag(library-only)
|
if flag(dev) || flag(library-only)
|
||||||
cpp-options: -DDEVELOPMENT
|
cpp-options: -DDEVELOPMENT
|
||||||
|
|||||||
6
templates/banned-tags.hamlet
Normal file
6
templates/banned-tags.hamlet
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<div .container>
|
||||||
|
<h1>Banned Tags
|
||||||
|
<a href=@{TagListR}>List of viewable tags
|
||||||
|
<form method=post action=@{BannedTagsR}?_method=PUT enctype=#{enctype}>
|
||||||
|
^{widget}
|
||||||
|
<button .btn>Update banned tags
|
||||||
4
templates/banned-tags.lucius
Normal file
4
templates/banned-tags.lucius
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
textarea {
|
||||||
|
width: 500px;
|
||||||
|
height: 400px;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user