0004-manager-accept-a-cancel_url-parameter-on-UserAddView.patch
src/authentic2/manager/user_views.py | ||
---|---|---|
144 | 144 | |
145 | 145 |
def get_context_data(self, **kwargs): |
146 | 146 |
context = super(UserAddView, self).get_context_data(**kwargs) |
147 |
context['cancel_url'] = select_next_url(self.request, default='../..', include_post=True) |
|
147 |
context['cancel_url'] = select_next_url( |
|
148 |
self.request, |
|
149 |
default='../..', |
|
150 |
field_name='cancel') |
|
148 | 151 |
context['next'] = select_next_url(self.request, default=None, include_post=True) |
149 | 152 |
context['ou'] = self.ou |
150 | 153 |
return context |
tests/test_manager.py | ||
---|---|---|
735 | 735 | |
736 | 736 | |
737 | 737 |
def test_manager_create_user_next(superuser_or_admin, app, ou1): |
738 |
login(app, superuser_or_admin, '/manage/') |
|
739 | ||
738 | 740 |
next_url = u'/example.nowhere.null/' |
739 | 741 |
url = u'/manage/users/%s/add/?next=%s' % (ou1.pk, next_url) |
740 |
login(app, superuser_or_admin, '/manage/') |
|
741 | 742 |
response = app.get(url) |
742 | 743 | |
743 |
# cancel if not handled through form submission |
|
744 |
assert response.pyquery.remove_namespaces()('a.cancel').attr('href') == next_url |
|
744 |
# cancel is not handled through form submission, it's a link |
|
745 |
# next without cancel, no cancel button |
|
746 |
assert response.pyquery.remove_namespaces()('a.cancel').attr('href') == '../..' |
|
747 |
assert response.pyquery.remove_namespaces()('input[name="next"]').attr('value') == next_url |
|
748 | ||
749 |
next_url = u'/example.nowhere.null/' |
|
750 |
cancel_url = u'/example.nowhere.cancel/' |
|
751 |
url = u'/manage/users/%s/add/?next=%s&cancel=%s' % (ou1.pk, next_url, cancel_url) |
|
752 |
response = app.get(url) |
|
753 | ||
754 |
assert response.pyquery.remove_namespaces()('a.cancel').attr('href') == cancel_url |
|
755 |
assert response.pyquery.remove_namespaces()('input[name="next"]').attr('value') == next_url |
|
745 | 756 | |
746 | 757 |
form = response.form |
747 | 758 |
form.set('first_name', 'John') |
748 |
- |