Terminology change: instead of "banning" comments or posts, remove them.

This commit is contained in:
Ben Rog-Wilhelm 2023-06-23 21:41:03 -05:00
parent c610c60dc0
commit 2f0a3fc278
8 changed files with 63 additions and 30 deletions

View file

@ -1,11 +1,11 @@
function removeCommentBackend(post_id) { function removeCommentBackend(post_id) {
url="/ban_comment/"+post_id url="/remove_comment/"+post_id
post(url) post(url)
} }
function approveCommentBackend(post_id) { function approveCommentBackend(post_id) {
url="/unban_comment/"+post_id url="/unremove_comment/"+post_id
post(url) post(url)
} }

View file

@ -100,7 +100,7 @@ ACTIONTYPES = {
"icon": 'fa-badge', "icon": 'fa-badge',
"color": 'bg-danger' "color": 'bg-danger'
}, },
'ban_comment': { 'remove_comment': {
"str": 'removed {self.target_link}', "str": 'removed {self.target_link}',
"icon": 'fa-comment', "icon": 'fa-comment',
"color": 'bg-danger' "color": 'bg-danger'
@ -110,7 +110,7 @@ ACTIONTYPES = {
"icon": 'fa-globe', "icon": 'fa-globe',
"color": 'bg-danger' "color": 'bg-danger'
}, },
'ban_post': { 'remove_post': {
"str": 'removed post {self.target_link}', "str": 'removed post {self.target_link}',
"icon": 'fa-feather-alt', "icon": 'fa-feather-alt',
"color": 'bg-danger' "color": 'bg-danger'
@ -300,7 +300,7 @@ ACTIONTYPES = {
"icon": 'fa-eye-slash', "icon": 'fa-eye-slash',
"color": 'bg-danger' "color": 'bg-danger'
}, },
'unban_comment': { 'unremove_comment': {
"str": 'reinstated {self.target_link}', "str": 'reinstated {self.target_link}',
"icon": 'fa-comment', "icon": 'fa-comment',
"color": 'bg-success' "color": 'bg-success'
@ -310,7 +310,7 @@ ACTIONTYPES = {
"icon": 'fa-globe', "icon": 'fa-globe',
"color": 'bg-success' "color": 'bg-success'
}, },
'unban_post': { 'unremove_post': {
"str": 'reinstated post {self.target_link}', "str": 'reinstated post {self.target_link}',
"icon": 'fa-feather-alt', "icon": 'fa-feather-alt',
"color": 'bg-success' "color": 'bg-success'

View file

@ -129,10 +129,10 @@ def revert_actions(v, username):
cutoff = int(time.time()) - 86400 cutoff = int(time.time()) - 86400
posts = [x[0] for x in g.db.query(ModAction.target_submission_id).filter(ModAction.user_id == user.id, ModAction.created_utc > cutoff, ModAction.kind == 'ban_post').all()] posts = [x[0] for x in g.db.query(ModAction.target_submission_id).filter(ModAction.user_id == user.id, ModAction.created_utc > cutoff, ModAction.kind == 'remove_post').all()]
posts = g.db.query(Submission).filter(Submission.id.in_(posts)).all() posts = g.db.query(Submission).filter(Submission.id.in_(posts)).all()
comments = [x[0] for x in g.db.query(ModAction.target_comment_id).filter(ModAction.user_id == user.id, ModAction.created_utc > cutoff, ModAction.kind == 'ban_comment').all()] comments = [x[0] for x in g.db.query(ModAction.target_comment_id).filter(ModAction.user_id == user.id, ModAction.created_utc > cutoff, ModAction.kind == 'remove_comment').all()]
comments = g.db.query(Comment).filter(Comment.id.in_(comments)).all() comments = g.db.query(Comment).filter(Comment.id.in_(comments)).all()
for item in posts + comments: for item in posts + comments:
@ -1079,10 +1079,10 @@ def unban_user(user_id, v):
else: return {"message": f"@{user.username} was unbanned!"} else: return {"message": f"@{user.username} was unbanned!"}
@app.post("/ban_post/<post_id>") @app.post("/remove_post/<post_id>")
@limiter.exempt @limiter.exempt
@admin_level_required(2) @admin_level_required(2)
def ban_post(post_id, v): def remove_post(post_id, v):
post = g.db.query(Submission).filter_by(id=post_id).one_or_none() post = g.db.query(Submission).filter_by(id=post_id).one_or_none()
if not post: if not post:
@ -1098,7 +1098,7 @@ def ban_post(post_id, v):
ma=ModAction( ma=ModAction(
kind="ban_post", kind="remove_post",
user_id=v.id, user_id=v.id,
target_submission_id=post.id, target_submission_id=post.id,
) )
@ -1116,10 +1116,10 @@ def ban_post(post_id, v):
return {"message": "Post removed!"} return {"message": "Post removed!"}
@app.post("/unban_post/<post_id>") @app.post("/unremove_post/<post_id>")
@limiter.exempt @limiter.exempt
@admin_level_required(2) @admin_level_required(2)
def unban_post(post_id, v): def unremove_post(post_id, v):
post = g.db.query(Submission).filter_by(id=post_id).one_or_none() post = g.db.query(Submission).filter_by(id=post_id).one_or_none()
if not post: if not post:
@ -1127,7 +1127,7 @@ def unban_post(post_id, v):
if post.is_banned: if post.is_banned:
ma=ModAction( ma=ModAction(
kind="unban_post", kind="unremove_post",
user_id=v.id, user_id=v.id,
target_submission_id=post.id, target_submission_id=post.id,
) )
@ -1288,10 +1288,10 @@ def unsticky_comment(cid, v):
return {"message": "Comment unpinned!"} return {"message": "Comment unpinned!"}
@app.post("/ban_comment/<c_id>") @app.post("/remove_comment/<c_id>")
@limiter.exempt @limiter.exempt
@admin_level_required(2) @admin_level_required(2)
def api_ban_comment(c_id, v): def api_remove_comment(c_id, v):
comment = g.db.query(Comment).filter_by(id=c_id).one_or_none() comment = g.db.query(Comment).filter_by(id=c_id).one_or_none()
if not comment: if not comment:
abort(404) abort(404)
@ -1301,7 +1301,7 @@ def api_ban_comment(c_id, v):
comment.ban_reason = v.username comment.ban_reason = v.username
comment_on_unpublish(comment) # XXX: can cause discrepancies if removal state ≠ filter state comment_on_unpublish(comment) # XXX: can cause discrepancies if removal state ≠ filter state
ma=ModAction( ma=ModAction(
kind="ban_comment", kind="remove_comment",
user_id=v.id, user_id=v.id,
target_comment_id=comment.id, target_comment_id=comment.id,
) )
@ -1310,16 +1310,16 @@ def api_ban_comment(c_id, v):
return {"message": "Comment removed!"} return {"message": "Comment removed!"}
@app.post("/unban_comment/<c_id>") @app.post("/unremove_comment/<c_id>")
@limiter.exempt @limiter.exempt
@admin_level_required(2) @admin_level_required(2)
def api_unban_comment(c_id, v): def api_unremove_comment(c_id, v):
comment = g.db.query(Comment).filter_by(id=c_id).one_or_none() comment = g.db.query(Comment).filter_by(id=c_id).one_or_none()
if not comment: abort(404) if not comment: abort(404)
if comment.is_banned: if comment.is_banned:
ma=ModAction( ma=ModAction(
kind="unban_comment", kind="unremove_comment",
user_id=v.id, user_id=v.id,
target_comment_id=comment.id, target_comment_id=comment.id,
) )

View file

@ -194,7 +194,7 @@ def api_comment(v):
ma=ModAction( ma=ModAction(
user_id=AUTOJANNY_ID, user_id=AUTOJANNY_ID,
target_comment_id=comment.id, target_comment_id=comment.id,
kind="ban_comment", kind="remove_comment",
_note="spam" _note="spam"
) )
g.db.add(ma) g.db.add(ma)

View file

@ -475,7 +475,7 @@ def _do_antispam_submission_check(v:User, validated:validators.ValidatedSubmissi
ma=ModAction( ma=ModAction(
user_id=AUTOJANNY_ID, user_id=AUTOJANNY_ID,
target_submission_id=post.id, target_submission_id=post.id,
kind="ban_post", kind="remove_post",
_note="spam" _note="spam"
) )
g.db.add(ma) g.db.add(ma)

View file

@ -60,11 +60,11 @@
{% if v.admin_level > 1 %} {% if v.admin_level > 1 %}
{% if "/reported/" in request.path %} {% if "/reported/" in request.path %}
{% if v.id != p.author.id %}<a class="dropdown-item list-inline-item text-danger" role="button" onclick="post_toast(this,'/ban_post/{{p.id}}')"><i class="fas fa-ban"></i>Remove</a>{% endif %} {% if v.id != p.author.id %}<a class="dropdown-item list-inline-item text-danger" role="button" onclick="post_toast(this,'/remove_post/{{p.id}}')"><i class="fas fa-ban"></i>Remove</a>{% endif %}
<a class="dropdown-item list-inline-item text-success" role="button" onclick="post_toast(this,'/unban_post/{{p.id}}')"><i class="fas fa-check"></i>Approve</a> <a class="dropdown-item list-inline-item text-success" role="button" onclick="post_toast(this,'/unremove_post/{{p.id}}')"><i class="fas fa-check"></i>Approve</a>
{% else %} {% else %}
{% if v.id != p.author.id %}<a id="remove-{{p.id}}" class="dropdown-item {% if p.is_banned %}d-none{% endif %} list-inline-item text-danger" role="button" onclick="post_toast2(this,'/ban_post/{{p.id}}','remove-{{p.id}}','approve-{{p.id}}')"><i class="fas fa-ban"></i>Remove</a>{% endif %} {% if v.id != p.author.id %}<a id="remove-{{p.id}}" class="dropdown-item {% if p.is_banned %}d-none{% endif %} list-inline-item text-danger" role="button" onclick="post_toast2(this,'/remove_post/{{p.id}}','remove-{{p.id}}','approve-{{p.id}}')"><i class="fas fa-ban"></i>Remove</a>{% endif %}
<a id="approve-{{p.id}}" class="dropdown-item {% if not p.is_banned %}d-none{% endif %} list-inline-item text-success" role="button" onclick="post_toast2(this,'/unban_post/{{p.id}}','remove-{{p.id}}','approve-{{p.id}}')"><i class="fas fa-check"></i>Approve</a> <a id="approve-{{p.id}}" class="dropdown-item {% if not p.is_banned %}d-none{% endif %} list-inline-item text-success" role="button" onclick="post_toast2(this,'/unremove_post/{{p.id}}','remove-{{p.id}}','approve-{{p.id}}')"><i class="fas fa-check"></i>Approve</a>
{% endif %} {% endif %}
{% if p.oauth_app %} {% if p.oauth_app %}

View file

@ -24,11 +24,11 @@
<button id="unpin2-{{p.id}}" class="{% if not p.stickied %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-left text-primary" role="button" onclick="post_toast2(this,'/unsticky/{{p.id}}','pin2-{{p.id}}','unpin2-{{p.id}}')" data-bs-dismiss="modal"><i class="fas fa-thumbtack fa-rotate--45 text-center text-primary mr-3"></i>Unpin</button> <button id="unpin2-{{p.id}}" class="{% if not p.stickied %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-left text-primary" role="button" onclick="post_toast2(this,'/unsticky/{{p.id}}','pin2-{{p.id}}','unpin2-{{p.id}}')" data-bs-dismiss="modal"><i class="fas fa-thumbtack fa-rotate--45 text-center text-primary mr-3"></i>Unpin</button>
{% if "/reported/" in request.path %} {% if "/reported/" in request.path %}
<button class="nobackground btn btn-link btn-block btn-lg text-danger text-left" role="button" onclick="post_toast(this,'/ban_post/{{p.id}}')" data-bs-dismiss="modal"><i class="far fa-ban text-center mr-3"></i>Remove</button> <button class="nobackground btn btn-link btn-block btn-lg text-danger text-left" role="button" onclick="post_toast(this,'/remove_post/{{p.id}}')" data-bs-dismiss="modal"><i class="far fa-ban text-center mr-3"></i>Remove</button>
<button class="nobackground btn btn-link btn-block btn-lg text-success text-left" role="button" onclick="post_toast(this,'/unban_post/{{p.id}}')" data-bs-dismiss="modal"><i class="far fa-check text-center mr-3"></i>Approve</button> <button class="nobackground btn btn-link btn-block btn-lg text-success text-left" role="button" onclick="post_toast(this,'/unremove_post/{{p.id}}')" data-bs-dismiss="modal"><i class="far fa-check text-center mr-3"></i>Approve</button>
{% else %} {% else %}
<button id="remove2-{{p.id}}" class="{% if p.is_banned %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-danger text-left" role="button" onclick="post_toast2(this,'/ban_post/{{p.id}}','remove2-{{p.id}}','approve2-{{p.id}}')" data-bs-dismiss="modal"><i class="far fa-ban text-center mr-3"></i>Remove</button> <button id="remove2-{{p.id}}" class="{% if p.is_banned %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-danger text-left" role="button" onclick="post_toast2(this,'/remove_post/{{p.id}}','remove2-{{p.id}}','approve2-{{p.id}}')" data-bs-dismiss="modal"><i class="far fa-ban text-center mr-3"></i>Remove</button>
<button id="approve2-{{p.id}}" class="{% if not p.is_banned %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-success text-left" role="button" onclick="post_toast2(this,'/unban_post/{{p.id}}','remove2-{{p.id}}','approve2-{{p.id}}')" data-bs-dismiss="modal"><i class="far fa-check text-center mr-3"></i>Approve</button> <button id="approve2-{{p.id}}" class="{% if not p.is_banned %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-success text-left" role="button" onclick="post_toast2(this,'/unremove_post/{{p.id}}','remove2-{{p.id}}','approve2-{{p.id}}')" data-bs-dismiss="modal"><i class="far fa-check text-center mr-3"></i>Approve</button>
{% endif %} {% endif %}
{% if v and v.admin_level >= 2 and p.filter_state == 'filtered' %} {% if v and v.admin_level >= 2 and p.filter_state == 'filtered' %}

View file

@ -0,0 +1,33 @@
"""ban_comment->remove_comment, and the same for posts
Revision ID: 4bb8194c8ac0
Revises: 8337558f4f36
Create Date: 2023-06-24 02:37:51.984484+00:00
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '4bb8194c8ac0'
down_revision = '8337558f4f36'
branch_labels = None
depends_on = None
def upgrade():
# update for comments
op.execute(sa.text("""UPDATE modactions SET kind = 'remove_comment' WHERE kind = 'ban_comment'"""))
op.execute(sa.text("""UPDATE modactions SET kind = 'unremove_comment' WHERE kind = 'unban_comment'"""))
# update for posts
op.execute(sa.text("""UPDATE modactions SET kind = 'remove_post' WHERE kind = 'ban_post'"""))
op.execute(sa.text("""UPDATE modactions SET kind = 'unremove_post' WHERE kind = 'unban_post'"""))
def downgrade():
# rollback for comments
op.execute(sa.text("""UPDATE modactions SET kind = 'ban_comment' WHERE kind = 'remove_comment'"""))
op.execute(sa.text("""UPDATE modactions SET kind = 'unban_comment' WHERE kind = 'unremove_comment'"""))
# rollback for posts
op.execute(sa.text("""UPDATE modactions SET kind = 'ban_post' WHERE kind = 'remove_post'"""))
op.execute(sa.text("""UPDATE modactions SET kind = 'unban_post' WHERE kind = 'unremove_post'"""))