We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit 592079a9 authored by Mitchell Rosen's avatar Mitchell Rosen

fixed 'method POST not supported' error on deleting a tag

parent a9f91a14
......@@ -6,6 +6,7 @@ module Handler.Comment
( deleteCommentDirectLinkR
, getCommentDirectLinkR
, getCommentTagR
, postCommentTagR
-- Utils
, MakeCommentActionWidget
, earlierClosuresFromMaybeParentId
......@@ -26,7 +27,6 @@ module Handler.Comment
, makeRethreadCommentWidget
, makeRetractCommentWidget
, makeUnclaimCommentWidget
, postCommentTag
, postCommentApplyTag
, postCommentCreateTag
, postApproveComment
......@@ -624,28 +624,6 @@ getCommentTags comment_id = do
tags <- runDB $ M.findWithDefault [] comment_id <$> (fetchCommentCommentTagsDB comment_id >>= buildAnnotatedCommentTagsDB muser_id)
defaultLayout $(widgetFile "tags")
postCommentTag :: CommentId -> TagId -> Handler ()
postCommentTag comment_id tag_id = do
user_id <- requireAuthId
direction <- lookupPostParam "direction"
let delta = case T.unpack <$> direction of
Just "+" -> 1
Just "-" -> -1
Just "\215" -> -1
Nothing -> error "direction unset"
Just str -> error $ "unrecognized direction: " ++ str
runDB $ do
maybe_comment_tag_entity <- getBy (UniqueCommentTag comment_id tag_id user_id)
case maybe_comment_tag_entity of
Nothing -> insert_ (CommentTag comment_id tag_id user_id delta)
Just (Entity comment_tag_id comment_tag) -> case commentTagCount comment_tag + delta of
0 -> delete $ from $ \ ct -> where_ $ ct ^. CommentTagId ==. val comment_tag_id
x -> void $ update $ \ ct -> do
set ct [ CommentTagCount =. val x ]
where_ $ ct ^. CommentTagId ==. val comment_tag_id
postCommentApplyTag :: CommentId -> Handler ()
postCommentApplyTag comment_id = do
Entity user_id user <- requireAuth
......@@ -723,3 +701,27 @@ getCommentTagR comment_id tag_id = do
renderTag (AnnotatedTag tag _ _ user_votes) = do
let tag_name = tagName $ entityVal tag
defaultLayout $(widgetFile "tag")
postCommentTagR :: CommentId -> TagId -> Handler ()
postCommentTagR comment_id tag_id = do
user_id <- requireAuthId
direction <- lookupPostParam "direction"
let delta = case T.unpack <$> direction of
Just "+" -> 1
Just "-" -> -1
Just "\215" -> -1
Nothing -> error "direction unset"
Just str -> error $ "unrecognized direction: " ++ str
runDB $ do
maybe_comment_tag_entity <- getBy (UniqueCommentTag comment_id tag_id user_id)
case maybe_comment_tag_entity of
Nothing -> insert_ (CommentTag comment_id tag_id user_id delta)
Just (Entity comment_tag_id comment_tag) -> case commentTagCount comment_tag + delta of
0 -> delete $ from $ \ ct -> where_ $ ct ^. CommentTagId ==. val comment_tag_id
x -> void $ update $ \ ct -> do
set ct [ CommentTagCount =. val x ]
where_ $ ct ^. CommentTagId ==. val comment_tag_id
getCommentDirectLinkR comment_id
......@@ -691,10 +691,8 @@ getProjectCommentTagsR _ = getCommentTags
getProjectCommentTagR :: Text -> CommentId -> TagId -> Handler Html
getProjectCommentTagR _ = getCommentTagR
postProjectCommentTagR :: Text -> CommentId -> TagId -> Handler Html
postProjectCommentTagR project_handle comment_id tag_id = do
postCommentTag comment_id tag_id
redirect (ProjectCommentTagR project_handle comment_id tag_id)
postProjectCommentTagR :: Text -> CommentId -> TagId -> Handler ()
postProjectCommentTagR _ = postCommentTagR
--------------------------------------------------------------------------------
-- /c/#CommentId/tag/apply, /c/#CommentId/tag/create
......
......@@ -405,10 +405,8 @@ getWikiCommentTagsR _ _ = getCommentTags
getWikiCommentTagR :: Text -> Text -> CommentId -> TagId -> Handler Html
getWikiCommentTagR _ _ = getCommentTagR
postWikiCommentTagR :: Text -> Text -> CommentId -> TagId -> Handler Html
postWikiCommentTagR project_handle target comment_id tag_id = do
postCommentTag comment_id tag_id
redirect (WikiCommentTagR project_handle target comment_id tag_id)
postWikiCommentTagR :: Text -> Text -> CommentId -> TagId -> Handler ()
postWikiCommentTagR _ _ = postCommentTagR
--------------------------------------------------------------------------------
-- /tag/apply, /tag/create
......
......@@ -107,7 +107,7 @@
/p/#Text/w/#Text/perm EditWikiPermissionsR GET POST
/c/#CommentId CommentDirectLinkR GET DELETE
/c/#CommentId/tag/#TagId CommentTagR GET
/c/#CommentId/tag/#TagId CommentTagR GET POST
-- Devs only!
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment