Add message show for switch project
When we switch the project admin to demo there is no message show althrough success, we can add message show. Closes-bug:#1436709 Change-Id: Ie06c2c955939f73d89583e40f03cca6428695a6e
This commit is contained in:
@@ -20,6 +20,7 @@ INSTALLED_APPS = [
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'openstack_auth',
|
||||
'openstack_auth.tests'
|
||||
]
|
||||
@@ -28,7 +29,8 @@ MIDDLEWARE_CLASSES = [
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware'
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware'
|
||||
]
|
||||
|
||||
AUTHENTICATION_BACKENDS = ['openstack_auth.backend.KeystoneBackend']
|
||||
|
||||
@@ -18,10 +18,12 @@ from django.conf import settings
|
||||
from django.contrib import auth
|
||||
from django.contrib.auth.decorators import login_required # noqa
|
||||
from django.contrib.auth import views as django_auth_views
|
||||
from django.contrib import messages
|
||||
from django import http as django_http
|
||||
from django import shortcuts
|
||||
from django.utils import functional
|
||||
from django.utils import http
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.views.decorators.cache import never_cache # noqa
|
||||
from django.views.decorators.csrf import csrf_exempt # noqa
|
||||
from django.views.decorators.csrf import csrf_protect # noqa
|
||||
@@ -217,9 +219,10 @@ def switch(request, tenant_id, redirect_field_name=auth.REDIRECT_FIELD_NAME):
|
||||
{'username': request.user.username}
|
||||
LOG.info(msg)
|
||||
except keystone_exceptions.ClientException:
|
||||
msg = 'Project switch failed for user "%(username)s".' % \
|
||||
{'username': request.user.username}
|
||||
LOG.warning(msg)
|
||||
msg = (
|
||||
_('Project switch failed for user "%(username)s".') %
|
||||
{'username': request.user.username})
|
||||
messages.error(request, msg)
|
||||
auth_ref = None
|
||||
LOG.exception('An error occurred while switching sessions.')
|
||||
|
||||
@@ -239,6 +242,10 @@ def switch(request, tenant_id, redirect_field_name=auth.REDIRECT_FIELD_NAME):
|
||||
auth_user.Token(auth_ref, unscoped_token=unscoped_token),
|
||||
endpoint)
|
||||
auth_user.set_session_from_user(request, user)
|
||||
message = (
|
||||
_('Switch to project "%(project_name)s" successful.') %
|
||||
{'project_name': request.user.project_name})
|
||||
messages.success(request, message)
|
||||
response = shortcuts.redirect(redirect_to)
|
||||
utils.set_response_cookie(response, 'recent_project',
|
||||
request.user.project_id)
|
||||
|
||||
Reference in New Issue
Block a user