mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 05:22:16 +00:00
FEAT: Add admin email notif when an account is activated and awaiting approval
No async or time-since shenanigans yet!
This commit is contained in:
@@ -45,7 +45,7 @@ if not DEBUG:
|
||||
INTERNAL_IPS = ['127.0.0.1']
|
||||
|
||||
ADMINS = (
|
||||
('Tom Price', 'tomtom5152@gmail.com')
|
||||
[('Tom Price', 'tomtom5152@gmail.com'), ('IT Manager', 'it@nottinghamtec.co.uk'), ('Technical Director', 'td@nottinghamtec.co.uk')]
|
||||
)
|
||||
|
||||
# Application definition
|
||||
|
||||
@@ -2,6 +2,7 @@ from django import forms
|
||||
from django.utils import formats
|
||||
from django.conf import settings
|
||||
from django.core import serializers
|
||||
from django.core.mail import EmailMessage, EmailMultiAlternatives
|
||||
from django.contrib.auth.forms import UserCreationForm, UserChangeForm, AuthenticationForm, PasswordResetForm
|
||||
from registration.forms import RegistrationFormUniqueEmail
|
||||
from django.contrib.auth.forms import AuthenticationForm
|
||||
@@ -33,7 +34,6 @@ class ProfileRegistrationFormUniqueEmail(RegistrationFormUniqueEmail):
|
||||
raise forms.ValidationError("These initials are already in use. Please supply different initials.")
|
||||
return self.cleaned_data['initials']
|
||||
|
||||
|
||||
class CheckApprovedForm(AuthenticationForm):
|
||||
def confirm_login_allowed(self, user):
|
||||
if user.is_approved or user.is_superuser:
|
||||
|
||||
@@ -54,6 +54,9 @@ class Profile(AbstractUser):
|
||||
def latest_events(self):
|
||||
return self.event_mic.order_by('-start_date').select_related('person', 'organisation', 'venue', 'mic')
|
||||
|
||||
def users_awaiting_approval_count(self):
|
||||
return self.filter(models.Q(is_approved=False)).count()
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ from django.conf import settings
|
||||
from django.contrib.staticfiles.storage import staticfiles_storage
|
||||
from django.core.mail import EmailMessage, EmailMultiAlternatives
|
||||
from django.template.loader import get_template
|
||||
from registration.signals import user_activated
|
||||
from premailer import Premailer
|
||||
from z3c.rml import rml2pdf
|
||||
|
||||
@@ -102,3 +103,28 @@ def on_revision_commit(sender, instance, created, **kwargs):
|
||||
|
||||
|
||||
post_save.connect(on_revision_commit, sender=models.EventAuthorisation)
|
||||
|
||||
|
||||
def send_admin_awaiting_approval_email(user, request, **kwargs):
|
||||
for admin in settings.ADMINS:
|
||||
context = {
|
||||
'request': request,
|
||||
'link_suffix': 'admin/RIGS/profile/?is_approved__exact=0',
|
||||
'number_of_users': models.Profile.users_awaiting_approval_count(models.Profile.objects),
|
||||
'to_name': admin[0]
|
||||
}
|
||||
|
||||
email = EmailMultiAlternatives(
|
||||
"%s new users awaiting approval on RIGS" % (context['number_of_users']),
|
||||
get_template("RIGS/admin_awaiting_approval.txt").render(context),
|
||||
to=[admin[1]],
|
||||
reply_to=[user.email],
|
||||
)
|
||||
css = staticfiles_storage.path('css/email.css')
|
||||
html = Premailer(get_template("RIGS/admin_awaiting_approval.html").render(context),
|
||||
external_styles=css).transform()
|
||||
email.attach_alternative(html, 'text/html')
|
||||
email.send()
|
||||
|
||||
|
||||
user_activated.connect(send_admin_awaiting_approval_email)
|
||||
|
||||
9
RIGS/templates/RIGS/admin_awaiting_approval.html
Normal file
9
RIGS/templates/RIGS/admin_awaiting_approval.html
Normal file
@@ -0,0 +1,9 @@
|
||||
{% extends 'base_client_email.html' %}
|
||||
|
||||
{% block content %}
|
||||
<p>Hi {{ to_name|default_if_none:"Administrator" }},</p>
|
||||
|
||||
<p>{{ number_of_users|default_if_none:"Some" }} new users are awaiting administrator approval on RIGS. Click <a href="{{ request.scheme }}://{{ request.get_host }}{{ link_suffix }}">here</a> to approve them.</p>
|
||||
|
||||
<p>TEC PA & Lighting</p>
|
||||
{% endblock %}
|
||||
5
RIGS/templates/RIGS/admin_awaiting_approval.txt
Normal file
5
RIGS/templates/RIGS/admin_awaiting_approval.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
Hi {{ to_name|default_if_none:"Administrator" }},
|
||||
|
||||
{{ number_of_users|default_if_none:"Some" }} new users are awaiting administrator approval on RIGS. Use this link to approve them: {{ request.scheme }}://{{ request.get_host }}/{{ link_suffix }}
|
||||
|
||||
TEC PA & Lighting
|
||||
Reference in New Issue
Block a user