2012-02-04 23:40:31 +00:00
|
|
|
# Copyright 2012 Nebula, Inc.
|
2011-07-04 03:55:00 +00:00
|
|
|
#
|
2011-01-12 21:43:31 +00:00
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License. You may obtain
|
|
|
|
# a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
2011-07-04 03:55:00 +00:00
|
|
|
|
2015-12-03 20:34:01 +00:00
|
|
|
from django.conf import settings
|
2012-10-04 22:43:40 +00:00
|
|
|
from django import shortcuts
|
2014-07-29 14:57:39 +00:00
|
|
|
import django.views.decorators.vary
|
2011-10-31 18:31:05 +00:00
|
|
|
|
|
|
|
import horizon
|
2014-04-11 22:26:35 +00:00
|
|
|
from horizon import base
|
2015-02-05 09:25:24 +00:00
|
|
|
from horizon import exceptions
|
2015-12-03 20:34:01 +00:00
|
|
|
from horizon import notifications
|
|
|
|
|
|
|
|
|
|
|
|
MESSAGES_PATH = getattr(settings, 'MESSAGES_PATH', None)
|
2011-01-15 09:16:25 +00:00
|
|
|
|
2012-03-27 01:08:48 +00:00
|
|
|
|
2012-10-04 22:43:40 +00:00
|
|
|
def get_user_home(user):
|
2014-04-11 22:26:35 +00:00
|
|
|
dashboard = None
|
2012-10-04 22:43:40 +00:00
|
|
|
if user.is_superuser:
|
2014-04-11 22:26:35 +00:00
|
|
|
try:
|
|
|
|
dashboard = horizon.get_dashboard('admin')
|
|
|
|
except base.NotRegistered:
|
|
|
|
pass
|
|
|
|
|
|
|
|
if dashboard is None:
|
|
|
|
dashboard = horizon.get_default_dashboard()
|
|
|
|
|
2015-01-18 03:19:37 +00:00
|
|
|
# Domain Admin, Project Admin will default to identity
|
|
|
|
if (user.token.project.get('id') is None or
|
|
|
|
(user.is_superuser and user.token.project.get('id'))):
|
|
|
|
dashboard = horizon.get_dashboard('identity')
|
|
|
|
|
2014-04-11 22:26:35 +00:00
|
|
|
return dashboard.get_absolute_url()
|
2012-03-27 01:08:48 +00:00
|
|
|
|
2011-01-12 21:43:31 +00:00
|
|
|
|
2014-07-29 14:57:39 +00:00
|
|
|
@django.views.decorators.vary.vary_on_cookie
|
2012-10-04 22:43:40 +00:00
|
|
|
def splash(request):
|
2015-02-05 09:25:24 +00:00
|
|
|
if not request.user.is_authenticated():
|
|
|
|
raise exceptions.NotAuthenticated()
|
|
|
|
|
|
|
|
response = shortcuts.redirect(horizon.get_user_home(request.user))
|
2014-11-20 15:49:09 +00:00
|
|
|
if 'logout_reason' in request.COOKIES:
|
|
|
|
response.delete_cookie('logout_reason')
|
2015-12-03 20:34:01 +00:00
|
|
|
# Display Message of the Day message from the message files
|
|
|
|
# located in MESSAGES_PATH
|
|
|
|
if MESSAGES_PATH:
|
|
|
|
notifications.process_message_notification(request, MESSAGES_PATH)
|
2014-06-18 11:04:59 +00:00
|
|
|
return response
|