Notification emails #80

Merged
Oleg-Komarov merged 31 commits from notifications into main 2024-04-18 16:11:20 +02:00
Showing only changes of commit 49d73d1b9f - Show all commits

View File

@ -0,0 +1,34 @@
"""Create all necessary follow records."""
import logging
from actstream.actions import follow
from django.contrib.auth.models import Group
from django.core.management.base import BaseCommand
from constants.activity import Flag
from extensions.models import Extension
from reviewers.models import ApprovalActivity
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
class Command(BaseCommand):
def handle(self, *args, **options): # noqa: D102
extensions = Extension.objects.all()
moderators = Group.objects.get(name='moderators').user_set.all()
for extension in extensions:
authors = extension.authors.all()
for recipient in authors:
_follow_with_log(recipient, extension, Flag.AUTHOR)
for recipient in moderators:
_follow_with_log(recipient, extension, Flag.MODERATOR)
approval_activity_items = ApprovalActivity.objects.all().select_related('extension', 'user')
for item in approval_activity_items:
_follow_with_log(item.user, item.extension, Flag.MODERATOR)
def _follow_with_log(user, target, flag):
follow(user, target, send_action=False, flag=flag)
logger.info(f'{user} follows {target} with flag={flag}')