diff --git a/app/activitypub/util.py b/app/activitypub/util.py index 5a53f6b2..5ba58ff0 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -1483,7 +1483,7 @@ def ban_user(blocker, blocked, community, core_activity): # Notify banned person 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) db.session.add(notify) 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): - 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() community_membership_record = CommunityMember.query.filter_by(community_id=community.id, user_id=blocked.id).first() if community_membership_record: @@ -1513,7 +1516,7 @@ def unban_user(blocker, blocked, community, core_activity): if blocked.is_local(): # Notify unbanned person 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) 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'. diff --git a/app/chat/routes.py b/app/chat/routes.py index 3ab13843..0b4dbfeb 100644 --- a/app/chat/routes.py +++ b/app/chat/routes.py @@ -6,7 +6,7 @@ from sqlalchemy import desc, or_, and_, text from app import db, celery from app.chat.forms import AddReply, ReportConversationForm 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.utils import render_template, moderating_communities, joined_communities, menu_topics from app.chat import bp @@ -103,6 +103,19 @@ def empty(): return render_template('chat/empty.html') +@bp.route('/chat/ban_from_mod//', 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//options', methods=['GET', 'POST']) @login_required def chat_options(conversation_id): diff --git a/app/templates/chat/ban_from_mod.html b/app/templates/chat/ban_from_mod.html new file mode 100644 index 00000000..186e0a8a --- /dev/null +++ b/app/templates/chat/ban_from_mod.html @@ -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 %} +
+{% if active_ban %} +
Active Ban
+ + + + + + + + + + +
ReasonFromUntil
{{ active_ban.reason }}{{ active_ban.created_at.strftime('%Y-%m-%d') }}{{ active_ban.ban_until.strftime('%Y-%m-%d') if active_ban.ban_until else '' }}
+{% endif %} +{% if past_bans.count() > 0 %} +
Ban History
+ + + + + + + {% for past_ban in past_bans %} + + + + + + {% endfor %} +
ReasonFromType
{{ past_ban.reason }}{{ past_ban.created_at.strftime('%Y-%m-%d') }}{{ past_ban.action }}
+{% endif %} +
+{% endblock %}