Skip to content

Fixes #4 and #6 #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Fixes #4 and #6 #7

wants to merge 6 commits into from

Conversation

transcental
Copy link

Adding these two lines of code to the else statement in views.py's delete_post() function solves this issue(#6):

def delete_post(id):
    post = Post.query.filter_by(id=id).first()

    if not post:
        flash('Post not found', category='error')
    elif current_user.id != post.id and current_user.username not in moderators:
        flash('You do not have permission to delete this post', category='error')
    else:
++      for comment in post.comments:
++          db.session.delete(comment)
        db.session.delete(post)
        db.session.commit()
        flash('Post deleted', category='success')

@transcental
Copy link
Author

Also fixed #4 like so:

    if not post:
        flash("Post does not exist.", category='error')
--  elif current_user.id != post.id:
++  elif current_user.id != post.author:
        flash('You do not have permission to delete this post.', category='error')
    else:
        for comment in post.comments:
            db.session.delete(comment)
        db.session.delete(post)
        db.session.commit()
        flash('Post deleted.', category='success')

@transcental transcental changed the title Fixes #6 Fixes #4 and #6 Aug 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant