mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
Template for Banned from Community Notification to lead to #400
This commit is contained in:
parent
eb7af155ee
commit
29d450d75a
3 changed files with 62 additions and 4 deletions
|
@ -1483,7 +1483,7 @@ def ban_user(blocker, blocked, community, core_activity):
|
||||||
|
|
||||||
# Notify banned person
|
# Notify banned person
|
||||||
notify = Notification(title=shorten_string('You have been banned from ' + community.title),
|
notify = Notification(title=shorten_string('You have been banned from ' + community.title),
|
||||||
url=f'/notifications', user_id=blocked.id,
|
url=f'/chat/ban_from_mod/{blocked.id}/{community.id}', user_id=blocked.id,
|
||||||
author_id=blocker.id)
|
author_id=blocker.id)
|
||||||
db.session.add(notify)
|
db.session.add(notify)
|
||||||
if not current_app.debug: # user.unread_notifications += 1 hangs app if 'user' is the same person
|
if not current_app.debug: # user.unread_notifications += 1 hangs app if 'user' is the same person
|
||||||
|
@ -1503,7 +1503,10 @@ def ban_user(blocker, blocked, community, core_activity):
|
||||||
|
|
||||||
|
|
||||||
def unban_user(blocker, blocked, community, core_activity):
|
def unban_user(blocker, blocked, community, core_activity):
|
||||||
reason = core_activity['summary'] if 'summary' in core_activity else ''
|
if 'object' in core_activity and 'summary' in core_activity['object']:
|
||||||
|
reason = core_activity['object']['summary']
|
||||||
|
else:
|
||||||
|
reason = ''
|
||||||
db.session.query(CommunityBan).filter(CommunityBan.community_id == community.id, CommunityBan.user_id == blocked.id).delete()
|
db.session.query(CommunityBan).filter(CommunityBan.community_id == community.id, CommunityBan.user_id == blocked.id).delete()
|
||||||
community_membership_record = CommunityMember.query.filter_by(community_id=community.id, user_id=blocked.id).first()
|
community_membership_record = CommunityMember.query.filter_by(community_id=community.id, user_id=blocked.id).first()
|
||||||
if community_membership_record:
|
if community_membership_record:
|
||||||
|
@ -1513,7 +1516,7 @@ def unban_user(blocker, blocked, community, core_activity):
|
||||||
if blocked.is_local():
|
if blocked.is_local():
|
||||||
# Notify unbanned person
|
# Notify unbanned person
|
||||||
notify = Notification(title=shorten_string('You have been unbanned from ' + community.title),
|
notify = Notification(title=shorten_string('You have been unbanned from ' + community.title),
|
||||||
url=f'/notifications', user_id=blocked.id, author_id=blocker.id)
|
url=f'/chat/ban_from_mod/{blocked.id}/{community.id}', user_id=blocked.id, author_id=blocker.id)
|
||||||
db.session.add(notify)
|
db.session.add(notify)
|
||||||
if not current_app.debug: # user.unread_notifications += 1 hangs app if 'user' is the same person
|
if not current_app.debug: # user.unread_notifications += 1 hangs app if 'user' is the same person
|
||||||
blocked.unread_notifications += 1 # who pressed 'Re-submit this activity'.
|
blocked.unread_notifications += 1 # who pressed 'Re-submit this activity'.
|
||||||
|
|
|
@ -6,7 +6,7 @@ from sqlalchemy import desc, or_, and_, text
|
||||||
from app import db, celery
|
from app import db, celery
|
||||||
from app.chat.forms import AddReply, ReportConversationForm
|
from app.chat.forms import AddReply, ReportConversationForm
|
||||||
from app.chat.util import send_message
|
from app.chat.util import send_message
|
||||||
from app.models import Site, User, Report, ChatMessage, Notification, InstanceBlock, Conversation, conversation_member
|
from app.models import Site, User, Report, ChatMessage, Notification, InstanceBlock, Conversation, conversation_member, CommunityBan, ModLog
|
||||||
from app.user.forms import ReportUserForm
|
from app.user.forms import ReportUserForm
|
||||||
from app.utils import render_template, moderating_communities, joined_communities, menu_topics
|
from app.utils import render_template, moderating_communities, joined_communities, menu_topics
|
||||||
from app.chat import bp
|
from app.chat import bp
|
||||||
|
@ -103,6 +103,19 @@ def empty():
|
||||||
return render_template('chat/empty.html')
|
return render_template('chat/empty.html')
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/chat/ban_from_mod/<int:user_id>/<int:community_id>', methods=['GET'])
|
||||||
|
@login_required
|
||||||
|
def ban_from_mod(user_id, community_id):
|
||||||
|
active_ban = CommunityBan.query.filter_by(user_id=user_id, community_id=community_id).order_by(desc(CommunityBan.created_at)).first()
|
||||||
|
user_link = 'u/' + current_user.user_name
|
||||||
|
past_bans = ModLog.query.filter(ModLog.community_id == community_id, ModLog.link == user_link, or_(ModLog.action == 'ban_user', ModLog.action == 'unban_user')).order_by(desc(ModLog.created_at))
|
||||||
|
if active_ban:
|
||||||
|
past_bans = past_bans.offset(1)
|
||||||
|
#if active_ban and len(past_bans) > 1:
|
||||||
|
#past_bans = past_bans
|
||||||
|
return render_template('chat/ban_from_mod.html', active_ban=active_ban, past_bans=past_bans)
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/chat/<int:conversation_id>/options', methods=['GET', 'POST'])
|
@bp.route('/chat/<int:conversation_id>/options', methods=['GET', 'POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def chat_options(conversation_id):
|
def chat_options(conversation_id):
|
||||||
|
|
42
app/templates/chat/ban_from_mod.html
Normal file
42
app/templates/chat/ban_from_mod.html
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
{% if theme() and file_exists('app/templates/themes/' + theme() + '/base.html') %}
|
||||||
|
{% extends 'themes/' + theme() + '/base.html' %}
|
||||||
|
{% else %}
|
||||||
|
{% extends "base.html" %}
|
||||||
|
{% endif %}
|
||||||
|
{% set active_child = 'chats' %}
|
||||||
|
|
||||||
|
{% block app_content %}
|
||||||
|
<div class="row">
|
||||||
|
{% if active_ban %}
|
||||||
|
<h5> Active Ban</h5>
|
||||||
|
<table class="table">
|
||||||
|
<tr>
|
||||||
|
<th>Reason</th>
|
||||||
|
<th>From</th>
|
||||||
|
<th>Until</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{{ active_ban.reason }}</td>
|
||||||
|
<td>{{ active_ban.created_at.strftime('%Y-%m-%d') }}</td>
|
||||||
|
<td>{{ active_ban.ban_until.strftime('%Y-%m-%d') if active_ban.ban_until else '' }}</td>
|
||||||
|
</table>
|
||||||
|
{% endif %}
|
||||||
|
{% if past_bans.count() > 0 %}
|
||||||
|
<h5> Ban History</h5>
|
||||||
|
<table class="table">
|
||||||
|
<tr>
|
||||||
|
<th>Reason</th>
|
||||||
|
<th>From</th>
|
||||||
|
<th>Type</th>
|
||||||
|
</tr>
|
||||||
|
{% for past_ban in past_bans %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ past_ban.reason }}</td>
|
||||||
|
<td>{{ past_ban.created_at.strftime('%Y-%m-%d') }}</td>
|
||||||
|
<td>{{ past_ban.action }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
Loading…
Reference in a new issue