fix filter state vestiges

This commit is contained in:
justcool393 2023-07-22 08:41:24 -05:00
parent 2edaec6933
commit 0c478975b3
6 changed files with 68 additions and 205 deletions

View file

@ -1,22 +1,18 @@
function removeCommentBackend(post_id) {
url="/remove_comment/"+post_id
post(url)
filter_new_comment_status(post_id, "removed");
}
function approveCommentBackend(post_id) {
url="/unremove_comment/"+post_id
post(url)
filter_new_comment_status(post_id, "normal");
}
function removeCommentDesktop(post_id,button1,button2) {
removeCommentBackend(post_id)
removeCommentBackend(post_id);
try {
document.getElementById("comment-"+post_id+"-only").classList.add("banned");
document.getElementById("comment-"+post_id+"-only").classList.add("removed");
} catch(e) {
document.getElementById("context").classList.add("banned");
document.getElementById("context").classList.add("removed");
}
var button=document.getElementById("remove-"+post_id);
@ -33,9 +29,9 @@ function approveCommentDesktop(post_id,button1,button2) {
approveCommentBackend(post_id)
try {
document.getElementById("comment-"+post_id+"-only").classList.remove("banned");
document.getElementById("comment-"+post_id+"-only").classList.remove("removed");
} catch(e) {
document.getElementById("context").classList.remove("banned");
document.getElementById("context").classList.remove("removed");
}
var button=document.getElementById("remove-"+post_id);

View file

@ -272,14 +272,14 @@ def filtered_comments(v):
# (also rename Unremove to Approve, sigh)
@app.post("/admin/update_filter_status")
@limiter.exempt
@admin_level_required(2)
@admin_level_required(PERMS['POST_COMMENT_MODERATION'])
def update_filter_status(v):
update_body = request.get_json()
new_status = update_body.get('new_status')
post_id = update_body.get('post_id')
comment_id = update_body.get('comment_id')
if new_status not in ['normal', 'removed', 'ignored']:
return { 'result': f'Status of {new_status} is not permitted' }
return {'result': f'Status of {new_status} is not permitted'}, 403
if new_status == 'normal':
state_mod_new = StateMod.VISIBLE
@ -292,43 +292,45 @@ def update_filter_status(v):
state_report_new = StateReport.IGNORED
if post_id:
target = g.db.get(Submission, post_id)
old_status = target.state_mod
# this could totally be one query but it would be kinda ugly
if state_mod_new is not None:
g.db.query(Submission).where(Submission.id == post_id) \
.update({Submission.state_mod: state_mod_new, Submission.state_mod_set_by: v.username})
g.db.query(Submission).where(Submission.id == post_id) \
.update({Submission.state_report: state_report_new})
target: Submission = get_post(post_id, graceful=True)
modlog_target_type: str = 'post'
elif comment_id:
target = g.db.get(Comment, comment_id)
old_status = target.state_mod
if state_mod_new is not None:
g.db.query(Comment).where(Comment.id == comment_id) \
.update({Comment.state_mod: state_mod_new, Comment.state_mod_set_by: v.username})
g.db.query(Comment).where(Comment.id == comment_id) \
.update({Comment.state_report: state_report_new})
target: Comment = get_comment(comment_id, graceful=True)
modlog_target_type: str = 'comment'
else:
return { 'result': f'No valid item ID provided' }
return {"result": "No valid item ID provided"}, 404
if not target:
return {"result": "Item ID does not exist"}, 404
if target is not None:
# If comment now visible, update state to reflect publication.
if (isinstance(target, Comment)
and old_status != StateMod.VISIBLE
and state_mod_new == StateMod.VISIBLE):
comment_on_publish(target) # XXX: can cause discrepancies if removal state ≠ filter state
old_status = target.state_mod
if (isinstance(target, Comment)
and old_status == StateMod.VISIBLE
and state_mod_new != StateMod.VISIBLE and state_mod_new is not None):
comment_on_unpublish(target) # XXX: can cause discrepancies if removal state ≠ filter state
if state_mod_new is not None:
target.state_mod = state_mod_new
target.state_mod_set_by = v.username
target.state_report = state_report_new
g.db.commit()
return { 'result': 'Update successful' }
else:
return { 'result': 'Item ID does not exist' }
making_visible: bool = old_status != StateMod.VISIBLE and state_mod_new == StateMod.VISIBLE
making_invisible: bool = old_status == StateMod.VISIBLE and state_mod_new != StateMod.VISIBLE and state_mod_new is not None
if making_visible:
modlog_action: str = "approve"
if isinstance(target, Comment): comment_on_publish(target)
elif making_invisible:
modlog_action: str = "remove"
if isinstance(target, Comment): comment_on_unpublish(target)
if making_visible or making_invisible:
g.db.add(ModAction(
kind=f"{modlog_action}_{modlog_target_type}",
user_id=v.id,
target_submission_id=target.id if isinstance(target, Submission) else None,
target_comment_id=target.id if isinstance(target, Comment) else None
))
g.db.commit()
invalidate_cache(frontlist=True)
return { 'result': 'Update successful' }
@app.get("/admin/image_posts")
@limiter.exempt
@ -1100,74 +1102,6 @@ def unban_user(user_id, v):
else: return {"message": f"@{user.username} was unbanned!"}
@app.post("/remove_post/<post_id>")
@limiter.exempt
@admin_level_required(2)
def remove_post(post_id, v):
post = g.db.query(Submission).filter_by(id=post_id).one_or_none()
if not post:
abort(400)
post.state_mod = StateMod.REMOVED
post.state_mod_set_by = v.username
post.stickied = None
post.is_pinned = False
g.db.add(post)
ma=ModAction(
kind="remove_post",
user_id=v.id,
target_submission_id=post.id,
)
g.db.add(ma)
invalidate_cache(frontlist=True)
v.coins += 1
g.db.add(v)
requests.post(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/purge_cache', headers=CF_HEADERS, json={'files': [f"{SITE_FULL}/logged_out/"]}, timeout=5)
g.db.commit()
return {"message": "Post removed!"}
@app.post("/unremove_post/<post_id>")
@limiter.exempt
@admin_level_required(2)
def unremove_post(post_id, v):
post = g.db.query(Submission).filter_by(id=post_id).one_or_none()
if not post:
abort(400)
if post.state_mod != StateMod.VISIBLE:
ma=ModAction(
kind="unremove_post",
user_id=v.id,
target_submission_id=post.id,
)
g.db.add(ma)
post.state_mod = StateMod.VISIBLE
post.state_mod_set_by = v.username
g.db.add(post)
invalidate_cache(frontlist=True)
v.coins -= 1
g.db.add(v)
g.db.commit()
return {"message": "Post approved!"}
@app.post("/distinguish/<post_id>")
@limiter.exempt
@admin_level_required(1)
@ -1307,59 +1241,10 @@ def unsticky_comment(cid, v):
return {"message": "Comment unpinned!"}
@app.post("/remove_comment/<c_id>")
@limiter.exempt
@admin_level_required(2)
def api_remove_comment(c_id, v):
comment = g.db.query(Comment).filter_by(id=c_id).one_or_none()
if not comment:
abort(404)
comment.state_mod = StateMod.REMOVED
comment.state_mod_set_by = v.username
comment_on_unpublish(comment) # XXX: can cause discrepancies if removal state ≠ filter state
ma=ModAction(
kind="remove_comment",
user_id=v.id,
target_comment_id=comment.id,
)
g.db.add(ma)
g.db.commit()
return {"message": "Comment removed!"}
@app.post("/unremove_comment/<c_id>")
@limiter.exempt
@admin_level_required(2)
def api_unremove_comment(c_id, v):
comment = g.db.query(Comment).filter_by(id=c_id).one_or_none()
if not comment: abort(404)
if comment.state_mod == StateMod.REMOVED:
ma=ModAction(
kind="unremove_comment",
user_id=v.id,
target_comment_id=comment.id,
)
g.db.add(ma)
comment.state_mod = StateMod.VISIBLE
comment.state_mod_set_by = v.username
comment_on_publish(comment) # XXX: can cause discrepancies if removal state ≠ filter state
g.db.add(comment)
g.db.commit()
return {"message": "Comment approved!"}
@app.post("/distinguish_comment/<c_id>")
@limiter.exempt
@admin_level_required(1)
def admin_distinguish_comment(c_id, v):
comment = get_comment(c_id, v=v)
if comment.author_id != v.id: abort(403)

View file

@ -19,10 +19,12 @@
{% endif %}
{% endif %}
{% if v and v.admin_level >= 2 and c.state_mod == StateMod.FILTERED %}
<button class="btn" role="button" id="filter-approve" onclick="filter_new_comment_status({{ c.id }}, 'normal')"><span>Approve</span></button>
<button class="btn" role="button" id="filter-remove" onclick="filter_new_comment_status({{ c.id }}, 'removed')"><span>Remove</span></button>
{% endif %}
{%- if v.admin_level >= PERMS['POST_COMMENT_MODERATION'] -%}
{%- set show_approve = p.state_mod != StateMod.VISIBLE or "/reported/" in request.path -%}
{%- set show_remove = p.state_mod != StateMod.REMOVED -%}
<button id="remove-{{c.id}}" class="btn caction py-0 nobackground px-1 text-danger{% if not show_remove %} d-none{% endif %}" role="button" onclick="removeCommentDesktop('{{c.id}}','approve-{{c.id}}','remove-{{c.id}}');"><i class="fas fa-ban"></i>Remove</a>
<button id="approve-{{c.id}}" class="btn caction py-0 nobackground px-1 text-success{% if not show_approve %} d-none{% endif %}" role="button" onclick="approveCommentDesktop('{{c.id}}','approve-{{c.id}}','remove-{{c.id}}');"><i class="fas fa-check"></i>Approve</a>
{%- endif -%}
{% if v %}
<button style="margin-top:0.2rem" class="btn caction py-0 nobackground px-1 text-muted" data-bs-toggle="dropdown" aria-expanded="false"><i class="fas fa-ellipsis-h fa-fw"></i></button>
@ -45,16 +47,6 @@
{% endif %}
{% endif %}
{% if v.admin_level >= 2 %}
{% if "/reported/" in request.path %}
<button class="dropdown-item list-inline-item text-success" onclick="approveCommentDesktop('{{c.id}}')"><i class="fas fa-check text-success fa-fw"></i>Approve</button>
<button class="dropdown-item list-inline-item text-danger" onclick="removeCommentDesktop('{{c.id}}')"><i class="fas fa-ban text-danger fa-fw"></i>Remove</button>
{% else %}
<button id="approve-{{c.id}}" class="dropdown-item list-inline-item d-none {% if c.state_mod != StateMod.VISIBLE %}d-md-block{% endif %} text-success" onclick="approveCommentDesktop('{{c.id}}','approve-{{c.id}}','remove-{{c.id}}')"><i class="fas fa-check text-success fa-fw"></i>Approve</button>
<button id="remove-{{c.id}}" class="dropdown-item list-inline-item d-none {% if c.state_mod != StateMod.REMOVED %}d-md-block{% endif %} text-danger" onclick="removeCommentDesktop('{{c.id}}','approve-{{c.id}}','remove-{{c.id}}')"><i class="fas fa-ban text-danger fa-fw"></i>Remove</button>
{% endif %}
{% endif %}
{% if c.parent_submission and (c.author_id==v.id or v.admin_level >= 2) %}
<button id="unmark-{{c.id}}" class="dropdown-item list-inline-item d-none {% if c.over_18 %}d-md-block{% endif %} text-danger" onclick="post_toast3(this,'/toggle_comment_nsfw/{{c.id}}','mark-{{c.id}}','unmark-{{c.id}}')"><i class="fas fa-eye-evil text-danger fa-fw"></i>Unmark +18</button>
<button id="mark-{{c.id}}" class="dropdown-item list-inline-item d-none {% if not c.over_18 %}d-md-block{% endif %} text-danger" onclick="post_toast3(this,'/toggle_comment_nsfw/{{c.id}}','mark-{{c.id}}','unmark-{{c.id}}')"><i class="fas fa-eye-evil text-danger fa-fw"></i>Mark +18</button>

View file

@ -27,13 +27,12 @@
<a id="unban2-{{c.id}}" class="{% if not c.author.is_banned %}d-none{% endif %} list-group-item text-success" role="button" onclick="post_toast2(this,'/unban_user/{{c.author_id}}','ban2-{{c.id}}','unban2-{{c.id}}')" data-bs-dismiss="modal"><i class="fas fa-user-minus fa-fw text-success mr-2"></i>Unban user</a>
{% endif %}
{% if "/reported/" in request.path %}
<a class="list-group-item text-danger" role="button" onclick="removeCommentMobile('{{c.id}}')" data-bs-dismiss="modal"><i class="fas fa-ban text-danger mr-2"></i>Remove</a>
<a class="list-group-item text-success" role="button" onclick="approveCommentMobile('{{c.id}}')" data-bs-dismiss="modal"><i class="fas fa-check text-success mr-2"></i>Approve</a>
{% else %}
<a id="remove2-{{c.id}}" class="{% if c.state_mod != StateMod.VISIBLE %}d-none{% endif %} list-group-item text-danger" role="button" onclick="removeCommentMobile('{{c.id}}','approve2-{{c.id}}','remove2-{{c.id}}')" data-bs-dismiss="modal"><i class="fas fa-ban text-danger mr-2"></i>Remove</a>
<a id="approve2-{{c.id}}" class="{% if c.state_mod != StateMod.REMOVED %}d-none{% endif %} list-group-item text-success" role="button" onclick="approveCommentMobile('{{c.id}}','approve2-{{c.id}}','remove2-{{c.id}}')" data-bs-dismiss="modal"><i class="fas fa-check text-success mr-2"></i>Approve</a>
{% endif %}
{%- if v.admin_level >= PERMS['POST_COMMENT_MODERATION'] -%}
{%- set show_approve = p.state_mod != StateMod.VISIBLE or "/reported/" in request.path -%}
{%- set show_remove = p.state_mod == StateMod.VISIBLE -%}
<a id="remove2-{{c.id}}" class="dropdown-item list-inline-item text-danger{% if not show_remove %} d-none{% endif %}" role="button" onclick="removeCommentMobile('{{c.id}}','approve2-{{c.id}}','remove2-{{c.id}}');"><i class="fas fa-ban"></i>Remove</a>
<a id="approve2-{{c.id}}" class="dropdown-item list-inline-item text-success{% if not show_approve %} d-none{% endif %}" role="button" onclick="approveCommentMobile('{{c.id}}','approve2-{{c.id}}','remove2-{{c.id}}');"><i class="fas fa-check"></i>Approve</a>
{%- endif -%}
{% if c.oauth_app %}
<a href="{{c.oauth_app.permalink}}/comments" class="list-group-item text-info"><i class="fas fa-code text-info mr-2"></i>API App</a>

View file

@ -58,15 +58,14 @@
<a id="unclub-{{p.id}}" class="dropdown-item {% if not p.club %}d-none{% endif %} list-inline-item text-info" role="button" onclick="post_toast2(this,'/toggle_club/{{p.id}}','club-{{p.id}}','unclub-{{p.id}}')"><i class="fas fa-eye"></i>Unmark club</a>
{% endif %} #}
{% if v.admin_level > 1 %}
{% 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,'/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,'/unremove_post/{{p.id}}')"><i class="fas fa-check"></i>Approve</a>
{% else %}
{% if v.id != p.author.id %}<a id="remove-{{p.id}}" class="dropdown-item {% if p.state_mod == StateMod.REMOVED %}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 p.state_mod == StateMod.VISIBLE %}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 %}
{%- if v.admin_level >= PERMS['POST_COMMENT_MODERATION'] -%}
{%- set show_approve = p.state_mod != StateMod.VISIBLE or "/reported/" in request.path -%}
{%- set show_remove = p.state_mod == StateMod.VISIBLE -%}
<a id="remove-{{p.id}}" class="dropdown-item list-inline-item text-danger{% if not show_remove %} d-none{% endif %}" role="button" onclick="filter_new_status({{p.id}}, 'removed');"><i class="fas fa-ban"></i>Remove</a>
<a id="approve-{{p.id}}" class="dropdown-item list-inline-item text-success{% if not show_approve %} d-none{% endif %}" role="button" onclick="filter_new_status({{p.id}}, 'normal');"><i class="fas fa-check"></i>Approve</a>
{%- endif -%}
{% if v.admin_level >= 2 %}
{% if p.oauth_app %}
<a class="dropdown-item list-inline-item" href="{{p.oauth_app.permalink}}"><i class="fas fa-code"></i>API App</a>
{% endif %}

View file

@ -20,21 +20,14 @@
<button id="undistinguish2-{{p.id}}" class="{% if not p.distinguish_level %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-left text-primary" role="button" onclick="post_toast2(this,'/distinguish/{{p.id}}','distinguish2-{{p.id}}','undistinguish2-{{p.id}}')" data-bs-dismiss="modal"><i class="fas fa-crown text-center text-primary mr-3"></i>Undistinguish</button> #}
<button id="pin2-{{p.id}}" class="{% if p.stickied %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-left text-primary" role="button" onclick="post_toast2(this,'/sticky/{{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>Pin</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 %}
<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,'/unremove_post/{{p.id}}')" data-bs-dismiss="modal"><i class="far fa-check text-center mr-3"></i>Approve</button>
{% else %}
<button id="remove2-{{p.id}}" class="{% if p.state_mod == StateMod.REMOVED %}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 p.state_mod == StateMod.VISIBLE %}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 %}
{% if v and v.admin_level >= 2 and p.state_mod == StateMod.FILTERED %}
<button id="mobile-filter-approve-{{p.id}}" class="nobackground btn btn-link btn-block btn-lg text-success text-left" role="button" onclick="filter_new_status({{p.id}}, 'normal')"><i class="far fa-check text-center mr-3"></i>Filter Approve</a>
<button id="mobile-filter-remove-{{p.id}}" class="nobackground btn btn-link btn-block btn-lg text-danger text-left" role="button" onclick="filter_new_status({{p.id}}, 'removed')"><i class="far fa-ban text-center mr-3"></i>Filter Remove</a>
{% endif %}
{%- if v.admin_level >= PERMS['POST_COMMENT_MODERATION'] -%}
{%- set show_approve = p.state_mod != StateMod.VISIBLE or "/reported/" in request.path -%}
{%- set show_remove = p.state_mod == StateMod.VISIBLE -%}
<a id="remove2-{{p.id}}" class="dropdown-item list-inline-item text-danger{% if not show_remove %} d-none{% endif %}" role="button" onclick="filter_new_status({{p.id}}, 'removed');"><i class="fas fa-ban"></i>Remove</a>
<a id="approve2-{{p.id}}" class="dropdown-item list-inline-item text-success{% if not show_approve %} d-none{% endif %}" role="button" onclick="filter_new_status({{p.id}}, 'normal');"><i class="fas fa-check"></i>Approve</a>
{%- endif -%}
{% if p.oauth_app %}
<a href="{{p.oauth_app.permalink}}"><button class="nobackground btn btn-link btn-block btn-lg text-muted text-left"><i class="far fa-code text-center text-info mr-3"></i>API App</button></a>
@ -47,7 +40,6 @@
<button id="ban2-{{p.id}}" data-bs-dismiss="modal" data-bs-toggle="modal" data-bs-target="#banModal" onclick="banModal('/post/{{p.id}}', '{{p.author.id}}', '{{p.author_name}}')" class="{% if p.author.is_suspended %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-danger text-left" role="button"><i class="fas fa-user-minus mr-3"></i>Ban user</button>
<button id="unban2-{{p.id}}" class="{% if not p.author.is_suspended %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-success text-left" role="button" onclick="post_toast2(this,'/unban_user/{{p.author_id}}','ban2-{{p.id}}','unban2-{{p.id}}')" data-bs-dismiss="modal"><i class="fas fa-user-minus mr-3"></i>Unban user</button>
{% endif %}
</ul>
</div>
</div>