0001-backoffice-support-next-url-after-user-creation-2665.patch
src/authentic2/manager/templates/authentic2/manager/form.html | ||
---|---|---|
91 | 91 |
} |
92 | 92 |
}) |
93 | 93 |
</script> |
94 |
{% block hidden_inputs %} |
|
95 |
{% endblock %} |
|
94 | 96 |
</form> |
95 | 97 |
{% endblock %} |
src/authentic2/manager/templates/authentic2/manager/user_add.html | ||
---|---|---|
5 | 5 |
{% trans "Add an user" %} |
6 | 6 |
{% endblock %} |
7 | 7 | |
8 |
{% block hidden_inputs %} |
|
9 |
{{ block.super }} |
|
10 |
{% if next_url %}<input type="hidden" name="next_url" value="{{ next_url}}">{% endif %} |
|
11 |
{% endblock %} |
|
12 | ||
8 | 13 |
{% block breadcrumb %} |
9 | 14 |
{{ block.super }} |
10 | 15 |
<a href="{% url 'a2-manager-users' %}{% if multiple_ou and ou %}?search-ou={{ ou.pk }}{% endif %}">{% trans 'Users' %}{% if multiple_ou and ou %} : {{ ou }}{% endif %}</a> |
src/authentic2/manager/user_views.py | ||
---|---|---|
129 | 129 |
return fields |
130 | 130 | |
131 | 131 |
def get_success_url(self): |
132 |
return reverse('a2-manager-user-detail', kwargs={'pk': self.object.pk}) |
|
132 |
return self.request.POST.get('next_url') or \ |
|
133 |
reverse('a2-manager-user-detail', kwargs={'pk': self.object.pk}) |
|
133 | 134 | |
134 | 135 |
def get_context_data(self, **kwargs): |
135 | 136 |
context = super(UserAddView, self).get_context_data(**kwargs) |
136 | 137 |
context['cancel_url'] = '../..' |
137 | 138 |
context['ou'] = self.ou |
139 |
if hasattr(self.request, 'GET') and 'next_url' in self.request.GET: |
|
140 |
context['next_url'] = self.request.GET['next_url'] |
|
138 | 141 |
return context |
139 | 142 | |
140 | 143 |
def form_valid(self, form): |
tests/test_manager.py | ||
---|---|---|
687 | 687 |
manager_home_page = login(app, superuser, reverse('a2-manager-homepage')) |
688 | 688 |
response = manager_home_page.click('Logout').maybe_follow() |
689 | 689 |
assert response.request.query_string == 'next=/manage/' |
690 | ||
691 | ||
692 |
def test_manager_create_user_next_url(superuser_or_admin, app, ou1): |
|
693 |
next_url = u'https://example.nowhere.null/' |
|
694 |
url = u'/manage/users/%s/add/?next_url=%s' % (ou1.pk, next_url) |
|
695 |
login(app, superuser_or_admin, '/manage/') |
|
696 |
response = app.get(url) |
|
697 |
form = response.form |
|
698 |
form.set('first_name', 'John') |
|
699 |
form.set('last_name', 'Doe') |
|
700 |
form.set('email', 'john.doe@gmail.com') |
|
701 |
form.set('password1', 'ABcd1234') |
|
702 |
form.set('password2', 'ABcd1234') |
|
703 |
assert form.submit().location == next_url |
|
704 | ||
705 | ||
706 |
def test_manager_create_user_next_url_form_cancelation(superuser_or_admin, app, ou1): |
|
707 |
next_url = u'https://example.nowhere.null/' |
|
708 |
url = u'/manage/users/%s/add/?next_url=%s' % (ou1.pk, next_url) |
|
709 |
login(app, superuser_or_admin, '/manage/') |
|
710 |
response = app.get(url) |
|
711 |
form = response.form |
|
712 |
form.set('first_name', 'John') |
|
713 |
form.set('last_name', 'Doe') |
|
714 |
form.set('email', 'john.doe@gmail.com') |
|
715 |
form.set('password1', 'ABcd1234') |
|
716 |
form.set('password2', 'ABcd1234') |
|
717 |
assert form.submit('cancel').location == next_url |
|
718 | ||
719 | ||
720 |
def test_manager_create_user_next_url_form_error(superuser_or_admin, app, ou1): |
|
721 |
next_url = u'https://example.nowhere.null/' |
|
722 |
url = u'/manage/users/%s/add/?next_url=%s' % (ou1.pk, next_url) |
|
723 |
login(app, superuser_or_admin, '/manage/') |
|
724 |
response = app.get(url) |
|
725 |
form = response.form |
|
726 |
form.set('first_name', 'John') |
|
727 |
form.set('last_name', 'Doe') |
|
728 |
form.set('email', 'jd') # erroneous |
|
729 |
form.set('password1', 'notvalid') # erroneous |
|
730 |
assert '<input type="hidden" name="next_url" value="%s">' % next_url in form.submit().body |
|
690 |
- |