comments deleteable by creator
This commit is contained in:
parent
1726643f25
commit
6412a87b2b
2 changed files with 67 additions and 2 deletions
|
@ -128,7 +128,62 @@ postCommentReplyR commentId = do
|
||||||
redirect $ HomeR
|
redirect $ HomeR
|
||||||
|
|
||||||
getCommentDeleteR :: CommentId -> Handler Html
|
getCommentDeleteR :: CommentId -> Handler Html
|
||||||
getCommentDeleteR commentId = error "Not yet implemented"
|
getCommentDeleteR commentId = do
|
||||||
|
tempComment <- runDB $ get commentId
|
||||||
|
case tempComment of
|
||||||
|
Just comment -> do
|
||||||
|
msu <- lookupSession "userId"
|
||||||
|
case msu of
|
||||||
|
Just tempUserId -> do
|
||||||
|
userId <- return $ getUserIdFromText tempUserId
|
||||||
|
presence <- return $ (Just userId) == (commentAuthor comment)
|
||||||
|
case presence of
|
||||||
|
True -> do
|
||||||
|
defaultLayout $ do
|
||||||
|
setTitle "Eidolon :: Delete comment"
|
||||||
|
$(widgetFile "commentDelete")
|
||||||
|
False -> do
|
||||||
|
setMessage "You must be the author of this comment to delete it"
|
||||||
|
redirect $ MediumR $ commentOrigin comment
|
||||||
|
Nothing -> do
|
||||||
|
setMessage "You must be logged in to delete comments"
|
||||||
|
redirect $ LoginR
|
||||||
|
Nothing -> do
|
||||||
|
setMessage "This comment does not exist"
|
||||||
|
redirect $ HomeR
|
||||||
|
|
||||||
postCommentDeleteR :: CommentId -> Handler Html
|
postCommentDeleteR :: CommentId -> Handler Html
|
||||||
postCommentDeleteR commentId = error "Not yet implemented"
|
postCommentDeleteR commentId = do
|
||||||
|
tempComment <- runDB $ get commentId
|
||||||
|
case tempComment of
|
||||||
|
Just comment -> do
|
||||||
|
msu <- lookupSession "userId"
|
||||||
|
case msu of
|
||||||
|
Just tempUserId -> do
|
||||||
|
userId <- return $ getUserIdFromText tempUserId
|
||||||
|
presence <- return $ (Just userId) == (commentAuthor comment)
|
||||||
|
case presence of
|
||||||
|
True -> do
|
||||||
|
confirm <- lookupPostParam "confirm"
|
||||||
|
case confirm of
|
||||||
|
Just "confirm" -> do
|
||||||
|
-- delete comment children
|
||||||
|
childEnts <- runDB $ selectList [CommentParent ==. (Just commentId)] []
|
||||||
|
mapM (\ent -> runDB $ delete $ entityKey ent) childEnts
|
||||||
|
-- delete comment itself
|
||||||
|
runDB $ delete commentId
|
||||||
|
-- outro
|
||||||
|
setMessage "Your comment has been deleted"
|
||||||
|
redirect $ MediumR $ commentOrigin comment
|
||||||
|
_ -> do
|
||||||
|
setMessage "You must confirm the deletion"
|
||||||
|
redirect $ MediumR $ commentOrigin comment
|
||||||
|
False -> do
|
||||||
|
setMessage "You must be the author of this comment to delete it"
|
||||||
|
redirect $ MediumR $ commentOrigin comment
|
||||||
|
Nothing -> do
|
||||||
|
setMessage "You must be logged in to delete comments"
|
||||||
|
redirect $ LoginR
|
||||||
|
Nothing -> do
|
||||||
|
setMessage "This comment does not exist"
|
||||||
|
redirect $ HomeR
|
||||||
|
|
10
templates/commentDelete.hamlet
Normal file
10
templates/commentDelete.hamlet
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
$newline always
|
||||||
|
<h3>Delete comment
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Do you wish to delete this comment?
|
||||||
|
|
||||||
|
<form method="POST" action=@{CommentDeleteR commentId}>
|
||||||
|
<label for="confirm">Really delete this comment
|
||||||
|
<input type="checkbox" id="confirm" name="confirm" value="confirm" required>
|
||||||
|
<input id="delete" type="submit" value="Delete medium">
|
Loading…
Reference in a new issue