Add ability to send email to attendees with wiki permissions
authorMagnus Hagander <magnus@hagander.net>
Tue, 19 Mar 2024 19:27:46 +0000 (20:27 +0100)
committerMagnus Hagander <magnus@hagander.net>
Tue, 19 Mar 2024 19:39:49 +0000 (20:39 +0100)
Sometimes we have wiki pages available only to a specific subset of
users - in this case, it can be useful to be able to send emails
directly to those users from the wiki admin page.

Fixes #73

docs/confreg/wiki.md
postgresqleu/confwiki/views.py
postgresqleu/urls.py
template/confwiki/admin_edit_form.html

index 820da7be19aa88a357f5a27f3c3109acb4163371..ddcce73a332e54f8b3df5bd5558fc2033c7edb40 100644 (file)
@@ -77,3 +77,16 @@ do *not* trigger emails.
 New wiki pages and edits *in the backend system* will generate an
 email to the conference contact address (but not to regular attendees,
 subscribed or not).
+
+## Sending email
+
+Using the send email functionality, it is possible to send an email to
+attendees that have explicit permissions on a wiki page. This is a
+one-time email that goes to the attendees email and is optionally
+stored on their registration page.
+
+It is not possible to send an email to a public wiki page - for those,
+using a regular attendee email is better. The same applies to wiki
+pages where the permissions are set by registration type. If a page
+has both registration type and direct attendee permissions, email will
+be sent only to the direct attendees.
index 058341b6054cb5abf11ceb6cfddd3835e347ddbc..c8f54368b6aaf6bb38733a7d12b86811c834ac84 100644 (file)
@@ -18,6 +18,7 @@ from postgresqleu.confreg.util import render_conference_response
 from postgresqleu.confreg.util import get_authenticated_conference, get_conference_or_404
 from postgresqleu.confreg.util import reglog
 from postgresqleu.confreg.util import send_conference_notification_template
+from postgresqleu.confreg.mail import attendee_email_form
 
 from postgresqleu.util.db import exec_to_scalar, exec_to_list
 from postgresqleu.util.request import get_int_or_error
@@ -297,6 +298,36 @@ def admin_edit_page(request, urlname, pageid):
     })
 
 
+@transaction.atomic
+def admin_sendmail(request, urlname, pageid):
+    conference = get_authenticated_conference(request, urlname)
+
+    page = get_object_or_404(Wikipage, conference=conference, pk=pageid)
+
+    if 'idlist' in request.GET or 'idlist' in request.POST:
+        return attendee_email_form(
+            request,
+            conference,
+            breadcrumbs=[
+                ('../../', 'Wiki pages'),
+                ('../', page.title),
+            ],
+        )
+
+    if page.publicview:
+        messages.error(request, "Cannot send wiki page email to public pages. Use regular attendee emails instead.")
+        return HttpResponseRedirect("../")
+
+    if page.viewer_regtype.exists():
+        if page.viewer_attendee.exists():
+            messages.warning(request, "Will not send wiki page emails based on regtype, only direct attendees. Use regular attendee emails to send to regtypes!")
+        else:
+            messages.error(request, "Cannot send wiki page email to pages with regtype permissions. Use regular attendee emails instead.")
+            return HttpResponseRedirect("../")
+
+    return HttpResponseRedirect("?idlist={}".format(",".join([str(r.id) for r in page.viewer_attendee.all()])))
+
+
 @login_required
 @transaction.atomic
 def signup(request, urlname, signupid):
@@ -563,8 +594,6 @@ def signup_admin_sendmail(request, urlname, signupid):
     optionstrings = signup.options.split(',')
 
     if 'idlist' in request.GET or 'idlist' in request.POST:
-        from postgresqleu.confreg.mail import attendee_email_form
-
         def _get_query(idlist):
             return _get_signup_email_query(signup, idlist, optionstrings)
 
index f4b90cb02e2cb10d4a7716f5859e9a0c1f1fb2c4..a269752feeafd47308b2407b923dfac8fe881851 100644 (file)
@@ -230,6 +230,7 @@ urlpatterns.extend([
     url(r'^events/admin/(\w+)/waitlist/sendmail/$', postgresqleu.confreg.views.admin_waitlist_sendmail),
     url(r'^events/admin/(\w+)/wiki/$', postgresqleu.confwiki.views.admin),
     url(r'^events/admin/(\w+)/wiki/(new|\d+)/$', postgresqleu.confwiki.views.admin_edit_page),
+    url(r'^events/admin/(\w+)/wiki/(\d+)/sendmail/$', postgresqleu.confwiki.views.admin_sendmail),
     url(r'^events/admin/(\w+)/signups/$', postgresqleu.confwiki.views.signup_admin),
     url(r'^events/admin/(\w+)/signups/(new|\d+)/$', postgresqleu.confwiki.views.signup_admin_edit),
     url(r'^events/admin/(\w+)/signups/(\d+)/sendmail/$', postgresqleu.confwiki.views.signup_admin_sendmail),
index 6f7b61cf5212fec35a8d62c1beb100462bda0128..f6b0788d5a869ed8461e2d7d7055d03372ebbe42 100644 (file)
@@ -27,6 +27,10 @@ history. Instead, they will be emailed to the conference list.
 {%include "confreg/admin_backend_form_content.html" %}
 </form>
 
+<p>
+ <a class="btn btn-default" href="sendmail/">Send email</a>
+</p>
+
 <a class="btn btn-default btn-block" href="../">Back</a>
 
 {%endblock%}