misc: change admin to use front login/logout (#21910)

This commit is contained in:
Frédéric Péters 2018-11-14 20:40:44 +01:00
parent ac33f94f81
commit 0caf6fa965
2 changed files with 49 additions and 0 deletions

35
combo/public/admin.py Normal file
View File

@ -0,0 +1,35 @@
# combo - content management system
# Copyright (C) 2014-2018 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.contrib import admin
from django.core.urlresolvers import reverse
from django.shortcuts import redirect
from django.views.decorators.cache import never_cache
@never_cache
def login(request, extra_context=None):
auth_login_url = reverse('auth_login')
auth_login_url += '?%s' % request.GET.urlencode()
return redirect(auth_login_url)
admin.site.login = login
@never_cache
def logout(request, extra_context=None):
return redirect(reverse('auth_logout'))
admin.site.logout = logout

View File

@ -14,6 +14,7 @@ from django.template import TemplateSyntaxError
from django.test import override_settings
from django.utils.http import urlencode
from django.utils.six import BytesIO
from django.utils.six.moves.urllib import parse as urlparse
import pytest
from webtest import TestApp
@ -974,3 +975,16 @@ def test_page_versionning(app, admin_user):
assert Page.objects.count() == 1
assert TextCell.objects.count() == 3
assert JsonCell.objects.count() == 0
def test_django_admin(app, admin_user):
resp = app.get('/admin/')
resp = resp.follow() # -> /admin/login/
resp = resp.follow() # -> /login/
resp.form['username'] = 'admin'
resp.form['password'] = 'admin'
resp = resp.form.submit()
resp = resp.follow() # -> /admin/
assert '/admin/logout/' in resp.text
resp = resp.click(href='/admin/logout/')
resp = resp.follow() # -> /logout/
assert urlparse.urlparse(resp.location).path == '/'