add admin notes

pull/225/head
Aevann 2024-03-05 03:16:47 +02:00
parent 20ac2346e8
commit 0a70c741c3
9 changed files with 67 additions and 32 deletions

View File

@ -220,6 +220,7 @@
.fa-scarecrow:before{content:"\f70d"}
.fa-chart-simple:before{content:"\e473"}
.fa-memo:before{content:"\e1d8"}
.fa-file-pen:before{content:"\f31c"}
/* do not remove - fixes hand, talking, marsey-love components
from breaking out of the comment box

View File

@ -281,6 +281,10 @@ function post_comment(fullname, hide){
}
catch(e) {}
const admin_note_el = document.getElementById('admin-note-'+fullname)
if (admin_note_el)
form.append('admin_note', admin_note_el.checked);
const xhr = new XMLHttpRequest();
url = '/comment';
xhr.open("POST", url);

View File

@ -29,6 +29,8 @@ def can_see(user, obj):
if SITE == 'watchpeopledie.tv' and obj.id in {5, 17212, 22653, 23814}:
return False
else:
if obj.pinned == "Admin Note":
return user.admin_level >= PERMS['ADMIN_NOTES']
if hasattr(obj, 'is_blocking') and obj.is_blocking and not request.path.endswith(f'/{obj.id}'):
return False
if obj.parent_post:

View File

@ -175,6 +175,7 @@ PERMS = { # Minimum admin_level to perform action.
'NOTIFICATIONS_MODERATOR_ACTIONS': 1,
'EXEMPT_FROM_IP_LOGGING': 1,
'USER_BADGES': 1,
'ADMIN_NOTES': 1,
'IS_PERMA_PROGSTACKED': 2,
'USER_LINK': 2,

View File

@ -249,6 +249,12 @@ def comment(v):
g.db.add(c)
g.db.flush()
if not posting_to_post and request.values.get('admin_note') and v.admin_level >= PERMS['ADMIN_NOTES']:
c.pinned = "Admin Note"
if c.parent_comment_id and c.parent_comment.pinned == "Admin Note":
c.pinned = "Admin Note"
process_options(v, c)
execute_blackjack(v, c, c.body, "comment")
@ -297,39 +303,40 @@ def comment(v):
execute_longpostbot(c, level, body, body_html, post_target, v)
execute_zozbot(c, level, post_target, v)
notify_users = NOTIFY_USERS(body, v, ghost=c.ghost, obj=c, commenters_ping_post_id=commenters_ping_post_id)
if c.pinned != "Admin Note":
notify_users = NOTIFY_USERS(body, v, ghost=c.ghost, obj=c, commenters_ping_post_id=commenters_ping_post_id)
if notify_users == 'everyone':
alert_everyone(c.id)
else:
push_notif(notify_users, f'New mention of you by @{c.author_name}', c.body, c)
if notify_users == 'everyone':
alert_everyone(c.id)
else:
push_notif(notify_users, f'New mention of you by @{c.author_name}', c.body, c)
if c.level == 1 and posting_to_post:
subscriber_ids = [x[0] for x in g.db.query(Subscription.user_id).filter(Subscription.post_id == post_target.id, Subscription.user_id != v.id)]
if c.level == 1 and posting_to_post:
subscriber_ids = [x[0] for x in g.db.query(Subscription.user_id).filter(Subscription.post_id == post_target.id, Subscription.user_id != v.id)]
notify_users.update(subscriber_ids)
notify_users.update(subscriber_ids)
push_notif(subscriber_ids, f'New comment in subscribed thread by @{c.author_name}', c.body, c)
push_notif(subscriber_ids, f'New comment in subscribed thread by @{c.author_name}', c.body, c)
if parent_user.id != v.id and notify_op:
notify_users.add(parent_user.id)
if parent_user.id != v.id and notify_op:
notify_users.add(parent_user.id)
notify_users -= BOT_IDs
notify_users -= BOT_IDs
if v.shadowbanned or c.is_banned:
notify_users = [x[0] for x in g.db.query(User.id).filter(User.id.in_(notify_users), User.admin_level >= PERMS['USER_SHADOWBAN']).all()]
if v.shadowbanned or c.is_banned:
notify_users = [x[0] for x in g.db.query(User.id).filter(User.id.in_(notify_users), User.admin_level >= PERMS['USER_SHADOWBAN']).all()]
for x in notify_users:
n = Notification(comment_id=c.id, user_id=x)
g.db.add(n)
for x in notify_users:
n = Notification(comment_id=c.id, user_id=x)
g.db.add(n)
if parent_user.id != v.id and notify_op:
if isinstance(parent, User):
title = f"New comment on your wall by @{c.author_name}"
else:
title = f'New reply by @{c.author_name}'
if parent_user.id != v.id and notify_op:
if isinstance(parent, User):
title = f"New comment on your wall by @{c.author_name}"
else:
title = f'New reply by @{c.author_name}'
push_notif({parent_user.id}, title, c.body, c)
push_notif({parent_user.id}, title, c.body, c)
vote = CommentVote(user_id=v.id,
comment_id=c.id,

View File

@ -899,15 +899,19 @@ def u_username_wall(v, username):
comments = comments.join(Comment.author).filter(or_(User.id == v.id, User.shadowbanned == None))
total = comments.count()
comments = comments.order_by(Comment.created_utc.desc()) \
.offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
if v:
comments = [c[0] for c in comments]
if v and v.client:
if v.admin_level >= PERMS['ADMIN_NOTES']:
pinned = [c[0] for c in comments.filter(Comment.pinned != None).order_by(Comment.created_utc.desc())]
else:
pinned = []
comments = comments.filter(Comment.pinned == None).order_by(Comment.created_utc.desc()) .offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
comments = [c[0] for c in comments]
if v.client:
return {"data": [c.json for c in comments]}
return render_template("userpage/wall.html", u=u, v=v, listing=comments, page=page, total=total, is_following=is_following, standalone=True, render_replies=True, wall=True)
return render_template("userpage/wall.html", u=u, v=v, pinned=pinned, listing=comments, page=page, total=total, is_following=is_following, standalone=True, render_replies=True, wall=True)
@app.get("/@<username>/wall/comment/<int:cid>")

View File

@ -149,8 +149,10 @@
{%- include 'admin/shadowbanned_tooltip.html' -%}
{% endwith %}
{% if c.pinned %}
<i id='pinned-{{c.id}}'class="fas fa-thumbtack fa-rotate--45 pr-1 text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Pinned by @{{c.pinned}}" {% if c.pinned_utc %}data-onmouseover="pinned_timestamp('pinned-{{c.id}}')" data-timestamp={{c.pinned_utc}} data-nonce="{{g.nonce}}"{% endif %}></i>
{% if c.pinned == 'Admin Note' %}
<i id='pinned-{{c.id}}' class="fas fa-file-pen pr-1 text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{c.pinned}}"></i>
{% elif c.pinned %}
<i id='pinned-{{c.id}}' class="fas fa-thumbtack fa-rotate--45 pr-1 text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Pinned by @{{c.pinned}}" {% if c.pinned_utc %}data-onmouseover="pinned_timestamp('pinned-{{c.id}}')" data-timestamp={{c.pinned_utc}} data-nonce="{{g.nonce}}"{% endif %}></i>
{% endif %}
{% if c.distinguished and not c.ghost %}

View File

@ -10,6 +10,13 @@
<div class="row no-gutters px-3 p-md-0 userpage-wall" style="margin-top: 10px">
<div class="col">
<div class="comment-section" id="replies-of-{{u.fullname}}">
{% if pinned %}
{% with comments=pinned %}
{% include "comments.html" %}
{% endwith %}
<hr class="mt-5">
{% endif %}
{% with comments=listing %}
{% include "comments.html" %}
{% endwith %}
@ -22,7 +29,7 @@
{% endif %}
{{macros.ghost_box(text, '', 1)}}
{% endif %}
</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -171,6 +171,13 @@
{{file_btn('file-upload-reply-' ~ target_fullname)}}
</div>
{% if v.admin_level >= PERMS['ADMIN_NOTES'] and target_fullname.startswith('u_') %}
<div class="custom-control custom-checkbox mt-3 d-inline-block">
<input data-nonce="{{g.nonce}}" autocomplete="off" type="checkbox" class="custom-control-input" id="admin-note-{{target_fullname}}">
<label class="custom-control-label" for="admin-note-{{target_fullname}}">Admin Note</label>
</div>
{% endif %}
<button type="button" id="save-reply-to-{{target_fullname}}" class="btn btn-primary text-whitebtn ml-auto fl-r handle_disabled disabled" disabled data-nonce="{{g.nonce}}" data-onclick="post_comment('{{target_fullname}}', '{{hide}}')">Comment</button>
{% if enable_cancel_button %}