Implement notifications for admin users (#700)

* First stab at notification settings

* Add "global" setting for notification levels

* Trigger notification task

* Get users with permission for event

* Actually send notification emails

* More notifications

* Allow to turn off notifications

* Link in email to pause all notifications

* Add NotificationType to wordlist

* Add notification tests

* Add documentation

* Rebase fixes
This commit is contained in:
Raphael Michel
2017-12-14 22:06:08 +01:00
committed by GitHub
parent f0a1397eea
commit 128203800c
28 changed files with 1363 additions and 172 deletions

View File

@@ -0,0 +1,89 @@
{% extends "pretixcontrol/base.html" %}
{% load i18n %}
{% load bootstrap3 %}
{% block title %}{% trans "Notification settings" %}{% endblock %}
{% block content %}
<h1>{% trans "Notification settings" %}</h1>
<form method="post">
{% csrf_token %}
<fieldset>
{% if request.user.notifications_send %}
<div class="alert alert-info">
<button name="notifications_send" value="off" type="submit" class="pull-right btn btn-default">
<span class="fa fa-bell-slash"></span>
{% trans "Disable" %}
</button>
{% trans "Notifications are turned on according to the settings below." %}
<div class="clearfix"></div>
</div>
{% else %}
<div class="alert alert-warning">
<button name="notifications_send" value="on" type="submit" class="pull-right btn btn-default">
<span class="fa fa-bell"></span>
{% trans "Enable" %}
</button>
{% trans "All notifications are turned off globally." %}
<div class="clearfix"></div>
</div>
{% endif %}
</fieldset>
</form>
<form class="form-inline" method="get">
<fieldset>
<legend>{% trans "Choose event" %}</legend>
<p>
<select name="event" class="form-control">
<option value="">{% trans "All my events" %}</option>
{% for e in events %}
<option value="{{ e.pk }}"
{% if e.pk|floatformat:0 == request.GET.event %}selected="selected"{% endif %}>
{{ e.name }} {{ e.get_date_range_display }}
</option>
{% endfor %}
</select>
<button class="btn btn-primary" type="submit">{% trans "Choose" %}</button>
<span class="help-block">{% trans "Save your modifications before switching events." %}</span>
</p>
</fieldset>
</form>
<form method="post">
{% csrf_token %}
<fieldset>
<legend>{% trans "Choose notifications to get" %}</legend>
<table class="table">
<thead>
<tr>
<th>{% trans "Notification type" %}</th>
<th class="text-center">{% trans "E-Mail notification" %}</th>
</tr>
</thead>
<tbody>
{% for type, enabled, global in types %}
<tr>
<td>
{{ type.verbose_name }}
</td>
<td class="text-center">
{% if not event or type.required_permission in permset %}
<select name="mail:{{ type.action_type }}" class="form-control">
{% if event %}
<option value="global">{% trans "Global" %} ({% if global.mail %}{% trans "On" %}{% else %}{% trans "Off" %}{% endif %})</option>{% endif %}
<option value="off" {% if "mail" in enabled and enabled.mail == False %}selected{% endif %}>{% trans "Off" %}</option>
<option value="on" {% if enabled.mail %}selected{% endif %}>{% trans "On" %}</option>
</select>
{% else %}
<span class="fa fa-lock" data-toggle="tooltip" title="{% trans "You have no permission to receive this notification" %}"></span>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</fieldset>
<div class="form-group submit-group">
<button type="submit" class="btn btn-primary btn-save">
{% trans "Save" %}
</button>
</div>
</form>
{% endblock %}

View File

@@ -12,6 +12,24 @@
{% bootstrap_field form.fullname layout='horizontal' %}
{% bootstrap_field form.locale layout='horizontal' %}
{% bootstrap_field form.timezone layout='horizontal' %}
<div class="form-group">
<label class="col-md-3 control-label" for="id_new_pw_repeat">{% trans "Notifications" %}</label>
<div class="col-md-9 static-form-row">
{% if request.user.notifications_send and request.user.notification_settings.exists %}
<span class="label label-success">
<span class="fa fa-bell-o"></span> {% trans "On" %}
</span>
{% else %}
<span class="label label-warning">
<span class="fa fa-bell-slash-o"></span> {% trans "Off" %}
</span>
{% endif %}
&nbsp;
<a href="{% url "control:user.settings.notifications" %}">
{% trans "Change notification settings" %}
</a>
</div>
</div>
</fieldset>
<fieldset>
<legend>{% trans "Login settings" %}</legend>
@@ -23,12 +41,12 @@
<label class="col-md-3 control-label" for="id_new_pw_repeat">{% trans "Two-factor authentication" %}</label>
<div class="col-md-9 static-form-row">
{% if user.require_2fa %}
<span class="label label-success">{% trans "Enabled" %}</span>
<span class="label label-success">{% trans "Enabled" %}</span> &nbsp;
<a href="{% url "control:user.settings.2fa" %}">
{% trans "Change two-factor settings" %}
</a>
{% else %}
<span class="label label-default">{% trans "Disabled" %}</span>
<span class="label label-default">{% trans "Disabled" %}</span> &nbsp;
<a href="{% url "control:user.settings.2fa" %}">
{% trans "Enable" %}
</a>