implement delete post
This commit is contained in:
parent
e47103d0ee
commit
0311586a1b
7 changed files with 98 additions and 3 deletions
|
|
@ -5,6 +5,7 @@
|
|||
- Added dependency to [SUOU](https://github.com/sakuragasaki46/suou) library
|
||||
- Added user blocks
|
||||
- Added user strikes: a strike logs the content of a removed message for future use
|
||||
- Posts may now be deleted by author. If it has comments, comments are not spared
|
||||
- Implemented guild subscriptions
|
||||
+ Blocking a user prevents them from seeing your comments, posts (standalone or in feed) and profile
|
||||
- Added ✨color themes✨
|
||||
|
|
|
|||
34
alembic/versions/6d418df3c72f_.py
Normal file
34
alembic/versions/6d418df3c72f_.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
"""empty message
|
||||
|
||||
Revision ID: 6d418df3c72f
|
||||
Revises: 90c7d0098efe
|
||||
Create Date: 2025-07-07 13:37:51.667620
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '6d418df3c72f'
|
||||
down_revision: Union[str, None] = '90c7d0098efe'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_constraint('comment_parent_post_id_fkey', 'freak_comment', type_='foreignkey')
|
||||
op.create_foreign_key('comment_parent_post_id', 'freak_comment', 'freak_post', ['parent_post_id'], ['id'], ondelete='cascade')
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_constraint('comment_parent_post_id', 'freak_comment', type_='foreignkey')
|
||||
op.create_foreign_key('comment_parent_post_id_fkey', 'freak_comment', 'freak_post', ['parent_post_id'], ['id'])
|
||||
# ### end Alembic commands ###
|
||||
|
|
@ -245,7 +245,6 @@ class User(Base):
|
|||
target_id = target
|
||||
|
||||
qq= ~select(UserBlock).where(UserBlock.c.actor_id == actor_id, UserBlock.c.target_id == target_id).exists()
|
||||
print(qq)
|
||||
return qq
|
||||
|
||||
def recompute_karma(self):
|
||||
|
|
@ -437,7 +436,7 @@ class Comment(Base):
|
|||
id = snowflake_column()
|
||||
|
||||
author_id = Column(BigInteger, ForeignKey('freak_user.id', name='comment_author_id'), nullable=True)
|
||||
parent_post_id = Column(BigInteger, ForeignKey('freak_post.id', name='comment_parent_post_id'), nullable=False)
|
||||
parent_post_id = Column(BigInteger, ForeignKey('freak_post.id', name='comment_parent_post_id', ondelete='cascade'), nullable=False)
|
||||
parent_comment_id = Column(BigInteger, ForeignKey('freak_comment.id', name='comment_parent_comment_id'), nullable=True)
|
||||
text_content = Column(String(16384), nullable=False)
|
||||
created_at = Column(DateTime, server_default=func.current_timestamp(), index=True)
|
||||
|
|
|
|||
27
freak/templates/singledelete.html
Normal file
27
freak/templates/singledelete.html
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{% extends "base.html" %}
|
||||
{% from "macros/title.html" import title_tag with context %}
|
||||
{% from "macros/icon.html" import icon, callout with context %}
|
||||
|
||||
{% block title %}{{ title_tag('Confirm deletion: ' + p.title, False) }}{% endblock %}
|
||||
|
||||
{% block heading %}
|
||||
<h2><span class="faint">Confirm deletion:</span> {{ p.title }}</h2>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="card">
|
||||
<form action="/delete/post/{{ p.id | to_b32l }}" method="POST">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<div>
|
||||
<p>You are about to delete <u>permanently</u> <a href="{{ p.url() }}">your post on {{ p.topic_or_user().handle() }}</a>.</p>
|
||||
{% call callout('spoiler', 'error') %}This action <u><b>cannot be undone</b></u>.{% endcall %}
|
||||
{% if (p.comments | count) %}
|
||||
{% call callout('spoiler') %}Your post has <strong>{{ (p.comments | count) }} comments</strong>. Your post will be deleted <u>along with ALL the comments</u>.{% endcall %}
|
||||
{% endif %}
|
||||
</div>
|
||||
<div>
|
||||
<button type="submit" class="primary">{{ icon('delete') }} Delete</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
@ -17,6 +17,9 @@ blueprints.append(bp)
|
|||
from .edit import bp
|
||||
blueprints.append(bp)
|
||||
|
||||
from .delete import bp
|
||||
blueprints.append(bp)
|
||||
|
||||
from .about import bp
|
||||
blueprints.append(bp)
|
||||
|
||||
|
|
|
|||
31
freak/website/delete.py
Normal file
31
freak/website/delete.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
|
||||
from flask import Blueprint, abort, flash, redirect, render_template, request
|
||||
from flask_login import current_user, login_required
|
||||
from sqlalchemy import delete, select
|
||||
|
||||
from ..models import Post, db
|
||||
|
||||
|
||||
bp = Blueprint('delete', __name__)
|
||||
|
||||
|
||||
@bp.route('/delete/post/<b32l:id>', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def delete_post(id: int):
|
||||
p = db.session.execute(select(Post).where(Post.id == id, Post.author == current_user)).scalar()
|
||||
|
||||
if p is None:
|
||||
abort(404)
|
||||
if p.author != current_user:
|
||||
abort(403)
|
||||
|
||||
pt = p.topic_or_user()
|
||||
|
||||
if request.method == 'POST':
|
||||
db.session.execute(delete(Post).where(Post.id == id, Post.author == current_user))
|
||||
db.session.commit()
|
||||
flash('Your post has been deleted')
|
||||
return redirect(pt.url()), 303
|
||||
|
||||
return render_template('singledelete.html', p=p)
|
||||
|
|
@ -14,7 +14,7 @@ bp = Blueprint('edit', __name__)
|
|||
@bp.route('/edit/post/<b32l:id>', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def edit_post(id):
|
||||
p: Post | None = db.session.execute(select(Post).where(Post.id == id)).scalar()
|
||||
p: Post | None = db.session.execute(select(Post).where(Post.id == id, Post.author == current_user)).scalar()
|
||||
|
||||
if p is None:
|
||||
abort(404)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue