Merge pull request #2690 from bookwyrm-social/link-domain-notifications
Create notifications for link domains that need approval
This commit is contained in:
commit
05a303ea18
4 changed files with 93 additions and 3 deletions
46
bookwyrm/migrations/0174_auto_20230222_1742.py
Normal file
46
bookwyrm/migrations/0174_auto_20230222_1742.py
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
# Generated by Django 3.2.18 on 2023-02-22 17:42
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("bookwyrm", "0173_default_user_auth_group_setting"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="notification",
|
||||||
|
name="related_link_domains",
|
||||||
|
field=models.ManyToManyField(to="bookwyrm.LinkDomain"),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="notification",
|
||||||
|
name="notification_type",
|
||||||
|
field=models.CharField(
|
||||||
|
choices=[
|
||||||
|
("FAVORITE", "Favorite"),
|
||||||
|
("REPLY", "Reply"),
|
||||||
|
("MENTION", "Mention"),
|
||||||
|
("TAG", "Tag"),
|
||||||
|
("FOLLOW", "Follow"),
|
||||||
|
("FOLLOW_REQUEST", "Follow Request"),
|
||||||
|
("BOOST", "Boost"),
|
||||||
|
("IMPORT", "Import"),
|
||||||
|
("ADD", "Add"),
|
||||||
|
("REPORT", "Report"),
|
||||||
|
("LINK_DOMAIN", "Link Domain"),
|
||||||
|
("INVITE", "Invite"),
|
||||||
|
("ACCEPT", "Accept"),
|
||||||
|
("JOIN", "Join"),
|
||||||
|
("LEAVE", "Leave"),
|
||||||
|
("REMOVE", "Remove"),
|
||||||
|
("GROUP_PRIVACY", "Group Privacy"),
|
||||||
|
("GROUP_NAME", "Group Name"),
|
||||||
|
("GROUP_DESCRIPTION", "Group Description"),
|
||||||
|
],
|
||||||
|
max_length=255,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
|
@ -2,8 +2,8 @@
|
||||||
from django.db import models, transaction
|
from django.db import models, transaction
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from .base_model import BookWyrmModel
|
from .base_model import BookWyrmModel
|
||||||
from . import Boost, Favorite, GroupMemberInvitation, ImportJob, ListItem, Report
|
from . import Boost, Favorite, GroupMemberInvitation, ImportJob, LinkDomain
|
||||||
from . import Status, User, UserFollowRequest
|
from . import ListItem, Report, Status, User, UserFollowRequest
|
||||||
|
|
||||||
|
|
||||||
class Notification(BookWyrmModel):
|
class Notification(BookWyrmModel):
|
||||||
|
@ -28,6 +28,7 @@ class Notification(BookWyrmModel):
|
||||||
|
|
||||||
# Admin
|
# Admin
|
||||||
REPORT = "REPORT"
|
REPORT = "REPORT"
|
||||||
|
LINK_DOMAIN = "LINK_DOMAIN"
|
||||||
|
|
||||||
# Groups
|
# Groups
|
||||||
INVITE = "INVITE"
|
INVITE = "INVITE"
|
||||||
|
@ -43,7 +44,7 @@ class Notification(BookWyrmModel):
|
||||||
NotificationType = models.TextChoices(
|
NotificationType = models.TextChoices(
|
||||||
# there has got be a better way to do this
|
# there has got be a better way to do this
|
||||||
"NotificationType",
|
"NotificationType",
|
||||||
f"{FAVORITE} {REPLY} {MENTION} {TAG} {FOLLOW} {FOLLOW_REQUEST} {BOOST} {IMPORT} {ADD} {REPORT} {INVITE} {ACCEPT} {JOIN} {LEAVE} {REMOVE} {GROUP_PRIVACY} {GROUP_NAME} {GROUP_DESCRIPTION}",
|
f"{FAVORITE} {REPLY} {MENTION} {TAG} {FOLLOW} {FOLLOW_REQUEST} {BOOST} {IMPORT} {ADD} {REPORT} {LINK_DOMAIN} {INVITE} {ACCEPT} {JOIN} {LEAVE} {REMOVE} {GROUP_PRIVACY} {GROUP_NAME} {GROUP_DESCRIPTION}",
|
||||||
)
|
)
|
||||||
|
|
||||||
user = models.ForeignKey("User", on_delete=models.CASCADE)
|
user = models.ForeignKey("User", on_delete=models.CASCADE)
|
||||||
|
@ -64,6 +65,7 @@ class Notification(BookWyrmModel):
|
||||||
"ListItem", symmetrical=False, related_name="notifications"
|
"ListItem", symmetrical=False, related_name="notifications"
|
||||||
)
|
)
|
||||||
related_reports = models.ManyToManyField("Report", symmetrical=False)
|
related_reports = models.ManyToManyField("Report", symmetrical=False)
|
||||||
|
related_link_domains = models.ManyToManyField("LinkDomain", symmetrical=False)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
|
@ -241,6 +243,26 @@ def notify_admins_on_report(sender, instance, created, *args, **kwargs):
|
||||||
notification.related_reports.add(instance)
|
notification.related_reports.add(instance)
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(models.signals.post_save, sender=LinkDomain)
|
||||||
|
@transaction.atomic
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
def notify_admins_on_link_domain(sender, instance, created, *args, **kwargs):
|
||||||
|
"""a new link domain needs to be verified"""
|
||||||
|
if not created:
|
||||||
|
# otherwise you'll get a notification when you approve a domain
|
||||||
|
return
|
||||||
|
|
||||||
|
# moderators and superusers should be notified
|
||||||
|
admins = User.admins()
|
||||||
|
for admin in admins:
|
||||||
|
notification, _ = Notification.objects.get_or_create(
|
||||||
|
user=admin,
|
||||||
|
notification_type=Notification.LINK_DOMAIN,
|
||||||
|
read=False,
|
||||||
|
)
|
||||||
|
notification.related_link_domains.add(instance)
|
||||||
|
|
||||||
|
|
||||||
@receiver(models.signals.post_save, sender=GroupMemberInvitation)
|
@receiver(models.signals.post_save, sender=GroupMemberInvitation)
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def notify_user_on_group_invite(sender, instance, *args, **kwargs):
|
def notify_user_on_group_invite(sender, instance, *args, **kwargs):
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
{% include 'notifications/items/add.html' %}
|
{% include 'notifications/items/add.html' %}
|
||||||
{% elif notification.notification_type == 'REPORT' %}
|
{% elif notification.notification_type == 'REPORT' %}
|
||||||
{% include 'notifications/items/report.html' %}
|
{% include 'notifications/items/report.html' %}
|
||||||
|
{% elif notification.notification_type == 'LINK_DOMAIN' %}
|
||||||
|
{% include 'notifications/items/link_domain.html' %}
|
||||||
{% elif notification.notification_type == 'INVITE' %}
|
{% elif notification.notification_type == 'INVITE' %}
|
||||||
{% include 'notifications/items/invite.html' %}
|
{% include 'notifications/items/invite.html' %}
|
||||||
{% elif notification.notification_type == 'ACCEPT' %}
|
{% elif notification.notification_type == 'ACCEPT' %}
|
||||||
|
|
20
bookwyrm/templates/notifications/items/link_domain.html
Normal file
20
bookwyrm/templates/notifications/items/link_domain.html
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
{% extends 'notifications/items/layout.html' %}
|
||||||
|
{% load humanize %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
{% block primary_link %}{% spaceless %}
|
||||||
|
{% url 'settings-link-domain' %}
|
||||||
|
{% endspaceless %}{% endblock %}
|
||||||
|
|
||||||
|
{% block icon %}
|
||||||
|
<span class="icon icon-warning"></span>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block description %}
|
||||||
|
{% url 'settings-link-domain' as path %}
|
||||||
|
{% blocktrans trimmed count counter=notification.related_link_domains.count with display_count=notification.related_link_domains.count|intcomma %}
|
||||||
|
A new <a href="{{ path }}">link domain</a> needs review
|
||||||
|
{% plural %}
|
||||||
|
{{ display_count }} new <a href="{{ path }}">link domains</a> need moderation
|
||||||
|
{% endblocktrans %}
|
||||||
|
{% endblock %}
|
Loading…
Add table
Add a link
Reference in a new issue