diff --git a/RIGS/forms.py b/RIGS/forms.py index c19ac5b8..14df5772 100644 --- a/RIGS/forms.py +++ b/RIGS/forms.py @@ -175,3 +175,7 @@ class ExternalClientEventAuthorisationForm(BaseClientEventAuthorisationForm): class Meta: model = models.EventAuthorisation fields = ('tos', 'name', 'amount', 'po') + + +class EventAuthorisationRequestForm(forms.Form): + email = forms.EmailField(required=True, label='Authoriser Email') diff --git a/RIGS/rigboard.py b/RIGS/rigboard.py index 5584184d..f4ee7bd0 100644 --- a/RIGS/rigboard.py +++ b/RIGS/rigboard.py @@ -1,11 +1,8 @@ -import os import cStringIO as StringIO from io import BytesIO import urllib2 -import reversion from django.core.mail import EmailMessage -from django.db import transaction from django.views import generic from django.core.urlresolvers import reverse_lazy from django.shortcuts import get_object_or_404 @@ -293,3 +290,46 @@ class EventAuthorise(generic.UpdateView): raise SuspiciousOperation( "The security integrity of that URL is invalid. Please contact your event MIC to obtain a new URL") return super(EventAuthorise, self).dispatch(request, *args, **kwargs) + + +class EventAuthorisationRequest(generic.FormView, generic.detail.SingleObjectMixin): + model = models.Event + form_class = forms.EventAuthorisationRequestForm + template_name = 'RIGS/eventauthorisation_request.html' + + @property + def object(self): + return self.get_object() + + def get_success_url(self): + if self.request.is_ajax(): + url = reverse_lazy('closemodal') + messages.info(self.request, "$('.event-authorise-request').addClass('btn-success')") + else: + url = reverse_lazy('event_detail', kwargs={ + 'pk': self.object.pk, + }) + messages.add_message(self.request, messages.SUCCESS, "Authorisation request successfully sent.") + return url + + def form_valid(self, form): + email = form.cleaned_data['email'] + + context = { + 'object': self.object, + 'request': self.request, + 'hmac': signing.dumps({ + 'pk': self.object.pk, + 'email': email + }), + } + + msg = EmailMessage( + "N%05d | %s - Event Authorisation Request".format(self.object.pk, self.object.name), + get_template("RIGS/eventauthorisation_client_request.txt").render(context), + to=[email], + ) + + msg.send() + + return super(EventAuthorisationRequest, self).form_valid(form) diff --git a/RIGS/templates/RIGS/event_detail.html b/RIGS/templates/RIGS/event_detail.html index d4b089a9..92d97e46 100644 --- a/RIGS/templates/RIGS/event_detail.html +++ b/RIGS/templates/RIGS/event_detail.html @@ -11,34 +11,7 @@
-
- - {% if event.is_rig %} - - {% endif %} - - {% if event.is_rig %} - {% if perms.RIGS.add_invoice %} - - - {% endif %} - {% endif %} -
+ {% include 'RIGS/event_detail_buttons.html' %}
{% endif %} @@ -184,34 +157,7 @@ {% if not request.is_ajax %}
-
- - {% if event.is_rig %} - - {% endif %} - - {% if event.is_rig %} - {% if perms.RIGS.add_invoice %} - - - {% endif %} - {% endif %} -
+ {% include 'RIGS/event_detail_buttons.html' %}
{% endif %} {% if event.is_rig %} @@ -229,34 +175,7 @@ {% if not request.is_ajax %}
-
- - {% if event.is_rig %} - - {% endif %} - - {% if event.is_rig %} - {% if perms.RIGS.add_invoice %} - - - {% endif %} - {% endif %} -
+ {% include 'RIGS/event_detail_buttons.html' %}
{% endif %} {% endif %} diff --git a/RIGS/templates/RIGS/event_detail_buttons.html b/RIGS/templates/RIGS/event_detail_buttons.html new file mode 100644 index 00000000..7f91db83 --- /dev/null +++ b/RIGS/templates/RIGS/event_detail_buttons.html @@ -0,0 +1,33 @@ +
+ + {% if event.is_rig %} + + {% endif %} + + {% if event.is_rig %} + + + Authorisation Request + + {% if perms.RIGS.add_invoice %} + + + {% endif %} + {% endif %} +
diff --git a/RIGS/templates/RIGS/eventauthorisation_client_request.txt b/RIGS/templates/RIGS/eventauthorisation_client_request.txt new file mode 100644 index 00000000..959da694 --- /dev/null +++ b/RIGS/templates/RIGS/eventauthorisation_client_request.txt @@ -0,0 +1,12 @@ +Hi there, + +{{request.user.get_full_name}} has requested that you authorise N{{object.pk|stringformat:"05d"}} | {{object.name}}. + +Please find the link below to complete the event booking process. +{% if object.event.organisation and object.event.organisation.union_account %}{# internal #} +Remember that only Presidents or Treasurers are allowed to sign off payments. You may need to forward this email on. +{% endif %} + +{{request.scheme}}://{{request.get_host}}{% url 'event_authorise' object.pk hmac %} + +The TEC Rig Information Gathering System diff --git a/RIGS/templates/RIGS/eventauthorisation_request.html b/RIGS/templates/RIGS/eventauthorisation_request.html new file mode 100644 index 00000000..87880331 --- /dev/null +++ b/RIGS/templates/RIGS/eventauthorisation_request.html @@ -0,0 +1,32 @@ +{% extends request.is_ajax|yesno:'base_ajax.html,base.html' %} +{% load widget_tweaks %} + +{% block title %}Request Authorisation{% endblock %} + +{% block content %} +
+
+
{% csrf_token %} + +
+ {% include 'form_errors.html' %} + +
+ + +
+ {% render_field form.email type="email" class+="form-control" %} +
+
+ +
+
+ +
+
+
+
+
+
+{% endblock %} diff --git a/RIGS/test_functional.py b/RIGS/test_functional.py index 87452f11..ecaf3ac1 100644 --- a/RIGS/test_functional.py +++ b/RIGS/test_functional.py @@ -1042,3 +1042,33 @@ class ClientEventAuthorisationTest(TestCase): self.assertEqual(mail.outbox[0].to, ['authemail@function.test']) self.assertEqual(mail.outbox[1].to, [settings.AUTHORISATION_NOTIFICATION_ADDRESS]) + +class TECEventAuthorisationTest(TestCase): + @classmethod + def setUpTestData(cls): + cls.profile = models.Profile.objects.create( + name='Test TEC User', + email='teccie@functional.test', + is_superuser=True # lazily grant all permissions + ) + + def setUp(self): + venue = models.Venue.objects.create(name='Authorisation Test Venue') + client = models.Person.objects.create(name='Authorisation Test Person', email='authorisation@functional.test') + organisation = models.Organisation.objects.create(name='Authorisation Test Organisation', union_account=False) + self.event = models.Event.objects.create( + name='Authorisation Test', + start_date=date.today(), + venue=venue, + person=client, + organisation=organisation, + ) + self.url = reverse('event_authorise_request', kwargs={'pk': self.event.pk}) + + def test_request_send(self): + self.client.force_login(self.profile) + response = self.client.post(self.url) + self.assertContains(response, 'This field is required.') + + response = self.client.post(self.url, {'email': 'client@functional.test'}) + self.assertEqual(response.status_code, 301) diff --git a/RIGS/urls.py b/RIGS/urls.py index 2273fd01..93a95e6d 100644 --- a/RIGS/urls.py +++ b/RIGS/urls.py @@ -115,6 +115,11 @@ urlpatterns = patterns('', permission_required_with_403('RIGS.view_event')(versioning.VersionHistory.as_view()), name='event_history', kwargs={'model': models.Event}), + url(r'^event/(?P\d+)/auth/$', + permission_required_with_403('RIGS.change_event')( + rigboard.EventAuthorisationRequest.as_view() + ), + name='event_authorise_request'), url(r'^event/(?P\d+)/(?P[-:\w]+)/$', rigboard.EventAuthorise.as_view(), name='event_authorise'),