From 372d8149836731283a004714f5d843ed47b6bd30 Mon Sep 17 00:00:00 2001 From: Filip Gralinski Date: Sun, 28 May 2017 10:06:50 +0200 Subject: [PATCH] tags can be accepted now --- Foundation.hs | 2 ++ Handler/TagUtils.hs | 12 ++++++++++-- Handler/Tags.hs | 16 ++++++++++++++++ config/routes | 1 + 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Foundation.hs b/Foundation.hs index 8c67970..56f4b73 100644 --- a/Foundation.hs +++ b/Foundation.hs @@ -139,6 +139,8 @@ instance Yesod App where isAuthorized MyScoreR _ = return Authorized isAuthorized (ResetPasswordR _) _ = return Authorized + isAuthorized (ToggleSubmissionTagR _) _ = return Authorized + -- Default to Authorized for now. isAuthorized _ _ = isTrustedAuthorized diff --git a/Handler/TagUtils.hs b/Handler/TagUtils.hs index 41bc2ff..f9f5579 100644 --- a/Handler/TagUtils.hs +++ b/Handler/TagUtils.hs @@ -31,11 +31,19 @@ $forall (Entity _ v) <- tagEnts fragmentWithSubmissionTags t tagEnts = [whamlet| #{t} -$forall ((Entity _ v), (Entity _ s)) <- tagEnts - \ #{tagName v} +$forall ((Entity _ v), (Entity sid s)) <- tagEnts + \ #{tagName v} |] +allTagClasses :: Text +allTagClasses = (tagClass $ Just True) <> " " <> (tagClass $ Just False) <> " " <> (tagClass $ Nothing); + + tagClass :: Maybe Bool -> Text tagClass (Just True) = "label-success" tagClass (Just False) = "label-default" tagClass Nothing = "label-primary" + +toggleTag :: Maybe Bool -> Maybe Bool +toggleTag (Just True) = Just False +toggleTag _ = Just True diff --git a/Handler/Tags.hs b/Handler/Tags.hs index e6ef43f..bb217f3 100644 --- a/Handler/Tags.hs +++ b/Handler/Tags.hs @@ -6,6 +6,8 @@ import Yesod.Form.Bootstrap3 (BootstrapFormLayout (..), renderBootstrap3, bfs) import qualified Yesod.Table as Table +import Handler.TagUtils + getTagsR :: Handler Html getTagsR = do (formWidget, formEnctype) <- generateFormPost tagForm @@ -41,3 +43,17 @@ tagForm :: Form (Text, Maybe Text) tagForm = renderBootstrap3 BootstrapBasicForm $ (,) <$> areq textField (bfs MsgTagName) Nothing <*> aopt textField (bfs MsgTagDescription) Nothing + +getToggleSubmissionTagR :: SubmissionTagId -> Handler RepPlain +getToggleSubmissionTagR submissionTagId = do + mUser <- maybeAuth + if (checkIfAdmin mUser) + then + do + submissionTag <- runDB $ get404 submissionTagId + let newState = toggleTag $ submissionTagAccepted submissionTag + runDB $ update submissionTagId [SubmissionTagAccepted =. newState] + return $ RepPlain $ toContent $ tagClass newState + else + do + return $ RepPlain $ toContent ("BLOCKED" :: Text) diff --git a/config/routes b/config/routes index 93ba798..d0dddb4 100644 --- a/config/routes +++ b/config/routes @@ -36,6 +36,7 @@ /start-working-on/#AchievementId StartWorkingOnR GET /give-up-working-on/#AchievementId GiveUpWorkingOnR GET /submission-for-achievement/#SubmissionId/#WorkingOnId SubmissionForAchievementR GET +/toggle-submission-tag/#SubmissionTagId ToggleSubmissionTagR GET /score/#UserId ScoreR GET /my-score MyScoreR GET