diff options
author | maxbr <maxbr@mi.fu-berlin.de> | 2016-08-19 17:15:28 +0200 |
---|---|---|
committer | maxbr <maxbr@mi.fu-berlin.de> | 2016-08-19 17:15:28 +0200 |
commit | ebaa05ab2b53634a7a3e738618a031fd1518d796 (patch) | |
tree | 2df4bf769f6ed52f4b9109a96d3194aa5a95e453 /tools/pharos-dashboard/booking | |
parent | 54322038f766be460b676d60974886be5f04d8f3 (diff) |
Use Jira Oauth for user authentication
JIRA: RELENG-12
Users can use their jira accounts for the dashboard. This also allows
the dasboard to open jira tickets for bookings.
Signed-off-by: maxbr <maxbr@mi.fu-berlin.de>
Diffstat (limited to 'tools/pharos-dashboard/booking')
-rw-r--r-- | tools/pharos-dashboard/booking/tests/test_views.py | 7 | ||||
-rw-r--r-- | tools/pharos-dashboard/booking/views.py | 15 |
2 files changed, 15 insertions, 7 deletions
diff --git a/tools/pharos-dashboard/booking/tests/test_views.py b/tools/pharos-dashboard/booking/tests/test_views.py index 4f5ee8bd..b0c4b498 100644 --- a/tools/pharos-dashboard/booking/tests/test_views.py +++ b/tools/pharos-dashboard/booking/tests/test_views.py @@ -56,13 +56,8 @@ class BookingViewTestCase(TestCase): url = reverse('booking:create', kwargs={'resource_id': 0}) self.assertEqual(self.client.get(url).status_code, 404) - # anonymous user - url = reverse('booking:create', kwargs={'resource_id': self.res1.id}) - response = self.client.get(url, follow=True) - self.assertRedirects(response, reverse('account:login') + '?next=/booking/' + str( - self.res1.id) + '/') - # authenticated user + url = reverse('booking:create', kwargs={'resource_id': self.res1.id}) self.client.login(username='user1',password='user1') response = self.client.get(url) self.assertEqual(response.status_code, 200) diff --git a/tools/pharos-dashboard/booking/views.py b/tools/pharos-dashboard/booking/views.py index bc00d3eb..c461aef4 100644 --- a/tools/pharos-dashboard/booking/views.py +++ b/tools/pharos-dashboard/booking/views.py @@ -6,17 +6,29 @@ from django.urls import reverse from django.views import View from django.views.generic import FormView +from account.jira_util import get_jira from booking.forms import BookingForm from booking.models import Booking from dashboard.models import Resource + class BookingFormView(LoginRequiredMixin, FormView): template_name = "booking/booking_calendar.html" form_class = BookingForm + def open_jira_issue(self,booking): + jira = get_jira(self.request.user) + issue_dict = { + 'project': 'PHAROS', + 'summary': 'Booking: ' + str(self.resource), + 'description': str(booking), + 'issuetype': {'name': 'Task'}, + } + jira.create_issue(fields=issue_dict) + def dispatch(self, request, *args, **kwargs): self.resource = get_object_or_404(Resource, id=self.kwargs['resource_id']) - return super(BookingFormView, self).dispatch(request,*args, **kwargs) + return super(BookingFormView, self).dispatch(request, *args, **kwargs) def get_context_data(self, **kwargs): title = 'Booking: ' + self.resource.name @@ -39,6 +51,7 @@ class BookingFormView(LoginRequiredMixin, FormView): except PermissionError as err: messages.add_message(self.request, messages.ERROR, err) return super(BookingFormView, self).form_invalid(form) + self.open_jira_issue(booking) messages.add_message(self.request, messages.SUCCESS, 'Booking saved') return super(BookingFormView, self).form_valid(form) |