Notification emails #80

Merged
Oleg-Komarov merged 31 commits from notifications into main 2024-04-18 16:11:20 +02:00
2 changed files with 22 additions and 9 deletions
Showing only changes of commit 5e31fdcc84 - Show all commits

View File

@ -1,16 +1,14 @@
from typing import Union
from actstream.actions import follow
from django.contrib.auth.models import Group
from django.db.models.signals import pre_save, post_save, post_delete
from django.dispatch import receiver
import django.dispatch
import extensions.models
import extensions.tasks
import files.models
version_changed = django.dispatch.Signal()
version_uploaded = django.dispatch.Signal()
@receiver(post_delete, sender=extensions.models.Preview)
def _delete_file(sender: object, instance: extensions.models.Preview, **kwargs: object) -> None:
@ -39,8 +37,20 @@ def _update_search_index(sender, instance, **kw):
pass # TODO: update search index
def send_notifications(sender=None, instance=None, signal=None, **kw):
pass # TODO: send email notification about new version upload
@receiver(post_save, sender=extensions.models.Extension)
def setup_initial_followers(
sender: object,
instance: extensions.models.Extension,
created: bool,
**kwargs: object,
) -> None:
if not created:
return
moderators = Group.objects.get(name='moderators').user_set.all()
audience = list(moderators) + list(instance.authors.all())
for recipient in audience:
follow(recipient, instance, send_action=False)
def extension_should_be_listed(extension):
@ -84,6 +94,3 @@ def _set_is_listed(
extension.is_listed = new_is_listed
extension.save()
version_uploaded.connect(send_notifications, dispatch_uid='send_notifications')

View File

@ -1,4 +1,5 @@
"""Contains views allowing developers to manage their add-ons."""
from actstream import action
from django import forms
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.contrib.messages.views import SuccessMessageMixin
@ -394,6 +395,11 @@ class DraftExtensionView(
extension_form.save()
add_preview_formset.save()
form.save()
action.send(
self.request.user,
verb='submitted for review', # FIXME map the type into a "registered" verb
target=extension_form.instance,
)
return super().form_valid(form)
except forms.ValidationError as e:
if 'hash' in e.error_dict: