Merge pull request #240 from hlaaftana/patch-1

Let users delete their own posts, fixes #208
This commit is contained in:
Joey 2020-05-10 10:38:32 -06:00 committed by GitHub
commit d372d9f980
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 4 deletions

View file

@ -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.

View file

@ -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)