Merge pull request #240 from hlaaftana/patch-1
Let users delete their own posts, fixes #208
This commit is contained in:
commit
d372d9f980
2 changed files with 25 additions and 4 deletions
|
|
@ -711,12 +711,15 @@ proc executeLockState(c: TForumData, threadId: int, locked: bool) =
|
|||
proc executeDeletePost(c: TForumData, postId: int) =
|
||||
# Verify that this post belongs to the user.
|
||||
const postQuery = sql"""
|
||||
select p.id from post p
|
||||
select p.author, p.id from post p
|
||||
where p.author = ? and p.id = ?
|
||||
"""
|
||||
let id = getValue(db, postQuery, c.username, postId)
|
||||
let
|
||||
row = getRow(db, postQuery, c.username, postId)
|
||||
author = row[0]
|
||||
id = row[1]
|
||||
|
||||
if id.len == 0 and c.rank < Admin:
|
||||
if id.len == 0 and not (c.rank == Admin or c.userid == author):
|
||||
raise newForumError("You cannot delete this post")
|
||||
|
||||
# Set the `isDeleted` flag.
|
||||
|
|
|
|||
|
|
@ -40,6 +40,24 @@ proc userTests(session: Session, baseUrl: string) =
|
|||
checkText "#thread-title .title-text", userTitleStr
|
||||
checkText ".original-post div.post-content", userContentStr
|
||||
|
||||
test "can delete thread":
|
||||
with session:
|
||||
# create thread to be deleted
|
||||
click "#new-thread-btn"
|
||||
|
||||
sendKeys "#thread-title", "To be deleted"
|
||||
sendKeys "#reply-textarea", "This thread is to be deleted"
|
||||
|
||||
click "#create-thread-btn"
|
||||
|
||||
click ".post-buttons .delete-button"
|
||||
|
||||
# click delete confirmation
|
||||
click "#delete-modal .delete-btn"
|
||||
|
||||
# Make sure the forum post is gone
|
||||
checkIsNone "To be deleted", LinkTextSelector
|
||||
|
||||
session.logout()
|
||||
|
||||
proc anonymousTests(session: Session, baseUrl: string) =
|
||||
|
|
@ -158,4 +176,4 @@ proc test*(session: Session, baseUrl: string) =
|
|||
|
||||
unBanUser(session, baseUrl)
|
||||
|
||||
session.navigate(baseUrl)
|
||||
session.navigate(baseUrl)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue