Permalink
Browse files

Merge pull request #1373 from pbanaszkiewicz/disable-profile-update-r…

…equests

Disable profile update requests
  • Loading branch information...
pbanaszkiewicz committed Oct 11, 2018
2 parents 6f813a6 + f0fe3cb commit 1d5495e2ce55fc5d202a3e88f359f3827057ca2a
View
@@ -12,12 +12,9 @@
url(r'^dc/request/confirm/$', views.DCEventRequestConfirm.as_view(), name='dc_workshop_request_confirm'),
url(r'^dc/request_selforganized/$', views.DCSelfOrganizedEventRequest.as_view(), name='dc_workshop_selforganized_request'),
url(r'^dc/request_selforganized/confirm/$', views.DCSelfOrganizedEventRequestConfirm.as_view(), name='dc_workshop_selforganized_request_confirm'),
# an existing SWC workshop submission has been turned off
url(r'^submit/$', views.EventSubmission.as_view(), name='event_submit'),
# disabled as per @maneesha's request
# url(r'^submit/confirm/$', views.EventSubmissionConfirm.as_view(), name='event_submission_confirm'),
url(r'^update_profile/$', views.ProfileUpdateRequestView.as_view(), name='profileupdate_request'),
url(r'^update_profile/confirm/$', views.ProfileUpdateRequestConfirm.as_view(), name='profileupdate_request_confirm'),
url(r'^request_training/$', views.TrainingRequestCreate.as_view(), name='training_request'),
url(r'^request_training/confirm/$', views.TrainingRequestConfirm.as_view(), name='training_request_confirm'),
# forms below have been turned off:
url(r'^submit/$', views.EventSubmission.as_view(), name='event_submit'),
url(r'^update_profile/$', views.ProfileUpdateRequestView.as_view(), name='profileupdate_request'),
]
View
@@ -3,7 +3,7 @@
from django.shortcuts import render
from django.template.loader import get_template
from django.urls import reverse_lazy
from django.views.generic import TemplateView
from django.views.generic import TemplateView, RedirectView
from workshops.forms import (
SWCEventRequestForm,
@@ -113,130 +113,23 @@ class DCEventRequestConfirm(SWCEventRequestConfirm):
template_name = 'forms/workshop_dc_request_confirm.html'
class ProfileUpdateRequestView(LoginNotRequiredMixin, EmailSendMixin,
AMYCreateView):
model = ProfileUpdateRequest
form_class = ProfileUpdateRequestForm
page_title = 'Update Instructor Profile'
template_name = 'forms/profileupdate.html'
success_url = reverse_lazy('profileupdate_request_confirm')
email_fail_silently = False
email_kwargs = {
'to': settings.REQUEST_NOTIFICATIONS_RECIPIENTS,
'reply_to': None,
}
def get_success_message(self, *args, **kwargs):
"""Don't display a success message."""
return ''
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['title'] = self.page_title
return context
def get_subject(self):
subject = (
'New instructor profile update request: {name}, {affiliation}'
).format(
name=self.object.get_full_name(),
affiliation=self.object.affiliation,
)
return subject
def get_body(self):
link = self.object.get_absolute_url()
link_domain = settings.SITE_URL
body_txt = get_template(
'mailing/profileupdaterequest.txt'
).render({
'object': self.object,
'link': link,
'link_domain': link_domain,
})
body_html = get_template(
'mailing/profileupdaterequest.html'
).render({
'object': self.object,
'link': link,
'link_domain': link_domain,
})
return body_txt, body_html
def form_valid(self, form):
"""Send email to admins if the form is valid."""
data = form.cleaned_data
self.email_kwargs['reply_to'] = (data['email'], )
result = super().form_valid(form)
return result
class ProfileUpdateRequestConfirm(LoginNotRequiredMixin, TemplateView):
"""Display confirmation of received workshop request."""
template_name = 'forms/profileupdate_confirm.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['title'] = 'Thank you for updating your instructor profile'
return context
# This form is disabled
class ProfileUpdateRequestView(LoginNotRequiredMixin, RedirectView):
permanent = False
query_string = False
url = 'https://static.carpentries.org/instructors/'
# This form is disabled as per @maneesha's request
# class EventSubmission(LoginNotRequiredMixin, EmailSendMixin,
# AMYCreateView):
# This form is disabled
class EventSubmission(LoginNotRequiredMixin, TemplateView):
"""Display form for submitting existing workshops."""
model = EventSubmissionModel
form_class = EventSubmitForm
template_name = 'forms/event_submit.html'
success_url = reverse_lazy('event_submission_confirm')
email_fail_silently = False
email_kwargs = {
'to': settings.REQUEST_NOTIFICATIONS_RECIPIENTS,
}
def get_success_message(self, *args, **kwargs):
"""Don't display a success message."""
return ''
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['title'] = 'Tell us about your workshop'
return context
def get_subject(self):
return ('New workshop submission from {}'
.format(self.object.contact_name))
def get_body(self):
link = self.object.get_absolute_url()
link_domain = settings.SITE_URL
body_txt = get_template('mailing/eventsubmission.txt') \
.render({
'object': self.object,
'link': link,
'link_domain': link_domain,
})
body_html = get_template('mailing/eventsubmission.html') \
.render({
'object': self.object,
'link': link,
'link_domain': link_domain,
})
return body_txt, body_html
class EventSubmissionConfirm(LoginNotRequiredMixin, TemplateView):
"""Display confirmation of received workshop submission."""
template_name = 'forms/event_submission_confirm.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['title'] = 'Thanks for your submission'
return context
class DCSelfOrganizedEventRequest(LoginNotRequiredMixin, EmailSendMixin,
AMYCreateView):

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -3,6 +3,10 @@
{% load pagination %}
{% block content %}
<div class="alert alert-warning">
<strong>Warning!</strong> This feature was disabled. Users are no longer able to add profile update requests.
</div>
<div class="btn-group" role="group" aria-label="Type of requests">
<a href="{% url 'all_profileupdaterequests' %}" class="btn btn-secondary{% if active_requests %} active{% endif %}">New</a>
<a href="{% url 'all_closed_profileupdaterequests' %}" class="btn btn-secondary{% if not active_requests %} active{% endif %}">Closed</a>
@@ -10,7 +10,7 @@
</div>
</div>
{% include "mailing/eventsubmission.html" with object=object load=1 %}
{% include "includes/eventsubmission.html" with object=object load=1 %}
<div class="hidden" id="loaded_data">
<h3>Workshop data</h3>
@@ -4,7 +4,7 @@
{% block title-left %}<h1>Workshop submission #{{ object.pk }}</h1>{% endblock %}
{% block content-left %}
{% include "mailing/eventsubmission.html" with object=object %}
{% include "includes/eventsubmission.html" with object=object %}
{% endblock %}
{% block title-right %}<h1>New event</h1>{% endblock %}
{% block content-right %}
@@ -82,7 +82,8 @@ def test_anonymous_user(self):
reverse('dc_workshop_request'),
reverse('dc_workshop_selforganized_request'),
reverse('event_submit'),
reverse('profileupdate_request'),
# below always redirects, as it's been deprecated
# reverse('profileupdate_request'),
reverse('training_request'),
reverse('training_request_confirm'),
]
@@ -25,39 +25,6 @@ def setUp(self):
self._setUpInstructors()
self._setUpUsersAndLogin()
def test_request_added(self):
"""Test if ProfileUpdateRequest is successfully added."""
data = {
'g-recaptcha-response': 'PASSED', # to auto-pass RECAPTCHA
'personal': 'Harry', 'family': 'Potter',
'email': 'harry@potter.com', 'airport_iata': 'LON',
'affiliation': 'Auror at Ministry of Magic',
'occupation': '', 'occupation_other': 'Auror',
'github': 'hpotter', 'twitter': 'hpotter',
'orcid': '', 'website': '', 'gender': 'M',
'domains': [1, 2], # IDs
'lessons': [1, 2], # IDs
'privacy_consent': True,
}
rv = self.client.post(reverse('profileupdate_request'), data,
follow=True)
assert rv.status_code == 200
content = rv.content.decode('utf-8')
assert 'Fix errors below' not in content
assert \
'Thank you for updating your instructor profile' in content
assert ProfileUpdateRequest.objects.all().count() == 1
assert ProfileUpdateRequest.objects.all()[0].active is True
# check if an email was sent
self.assertEqual(len(mail.outbox), 1)
msg = mail.outbox[0]
self.assertEqual(
msg.subject,
'New instructor profile update request: Harry Potter, '
'Auror at Ministry of Magic',
)
def test_request_discarded(self):
"""Ensure the request is discarded properly."""
# add a minimal request

0 comments on commit 1d5495e

Please sign in to comment.