forked from mirrors/bookwyrm
notify group members of group changes
Send a notification to all group members when group name, description, or privacy are changed.
This commit is contained in:
parent
c9deda8fdd
commit
6bc86f189f
4 changed files with 60 additions and 1 deletions
|
@ -7,7 +7,7 @@ from . import Boost, Favorite, ImportJob, Report, Status, User
|
|||
# pylint: disable=line-too-long
|
||||
NotificationType = models.TextChoices(
|
||||
"NotificationType",
|
||||
"FAVORITE REPLY MENTION TAG FOLLOW FOLLOW_REQUEST BOOST IMPORT ADD REPORT INVITE ACCEPT JOIN LEAVE REMOVE",
|
||||
"FAVORITE REPLY MENTION TAG FOLLOW FOLLOW_REQUEST BOOST IMPORT ADD REPORT INVITE ACCEPT JOIN LEAVE REMOVE GROUP_PRIVACY GROUP_NAME GROUP_DESCRIPTION",
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -27,4 +27,10 @@
|
|||
{% include 'notifications/items/leave.html' %}
|
||||
{% elif notification.notification_type == 'REMOVE' %}
|
||||
{% include 'notifications/items/remove.html' %}
|
||||
{% elif notification.notification_type == 'GROUP_PRIVACY' %}
|
||||
{% include 'notifications/items/update.html' %}
|
||||
{% elif notification.notification_type == 'GROUP_NAME' %}
|
||||
{% include 'notifications/items/update.html' %}
|
||||
{% elif notification.notification_type == 'GROUP_DESCRIPTION' %}
|
||||
{% include 'notifications/items/update.html' %}
|
||||
{% endif %}
|
||||
|
|
28
bookwyrm/templates/notifications/items/update.html
Normal file
28
bookwyrm/templates/notifications/items/update.html
Normal file
|
@ -0,0 +1,28 @@
|
|||
{% extends 'notifications/items/item_layout.html' %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load utilities %}
|
||||
|
||||
{% block primary_link %}{% spaceless %}
|
||||
{{ notification.related_group.local_path }}
|
||||
{% endspaceless %}{% endblock %}
|
||||
|
||||
{% block icon %}
|
||||
<span class="icon icon-local"></span>
|
||||
{% endblock %}
|
||||
|
||||
{% block description %}
|
||||
{% if notification.notification_type == 'GROUP_PRIVACY' %}
|
||||
{% blocktrans with group_name=notification.related_group.name group_path=notification.related_group.local_path %}
|
||||
has changed the privacy level for <a href="{{ group_path }}">{{ group_name }}</a>
|
||||
{% endblocktrans %}
|
||||
{% elif notification.notification_type == 'GROUP_NAME' %}
|
||||
{% blocktrans with group_name=notification.related_group.name group_path=notification.related_group.local_path %}
|
||||
has changed the name of <a href="{{ group_path }}">{{ group_name }}</a>
|
||||
{% endblocktrans %}
|
||||
{% else %}
|
||||
{% blocktrans with group_name=notification.related_group.name group_path=notification.related_group.local_path %}
|
||||
has changed the description of <a href="{{ group_path }}">{{ group_name }}</a>
|
||||
{% endblocktrans %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
|
@ -47,6 +47,31 @@ class Group(View):
|
|||
if not form.is_valid():
|
||||
return redirect("group", user_group.id)
|
||||
user_group = form.save()
|
||||
|
||||
# let the other members know something about the group changed
|
||||
memberships = models.GroupMember.objects.filter(group=user_group)
|
||||
model = apps.get_model("bookwyrm.Notification", require_ready=True)
|
||||
for field in form.changed_data:
|
||||
notification_type = (
|
||||
"GROUP_PRIVACY"
|
||||
if field == "privacy"
|
||||
else "GROUP_NAME"
|
||||
if field == "name"
|
||||
else "GROUP_DESCRIPTION"
|
||||
if field == "description"
|
||||
else None
|
||||
)
|
||||
if notification_type:
|
||||
for membership in memberships:
|
||||
member = membership.user
|
||||
if member != request.user:
|
||||
model.objects.create(
|
||||
user=member,
|
||||
related_user=request.user,
|
||||
related_group=user_group,
|
||||
notification_type=notification_type,
|
||||
)
|
||||
|
||||
return redirect("group", user_group.id)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue