2013-05-15 14:45:03 -06:00
|
|
|
# Copyright 2013 Hewlett-Packard Development Company, L.P.
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2017-01-11 15:03:37 -06:00
|
|
|
from django.conf import settings
|
2014-01-03 17:31:49 +01:00
|
|
|
from django.core.urlresolvers import reverse
|
|
|
|
from django.core.urlresolvers import reverse_lazy
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2013-05-15 14:45:03 -06:00
|
|
|
|
|
|
|
from horizon import exceptions
|
|
|
|
from horizon import forms
|
2014-02-05 12:08:15 -07:00
|
|
|
from horizon import messages
|
2013-05-15 14:45:03 -06:00
|
|
|
from horizon import tables
|
2013-10-28 11:24:00 +01:00
|
|
|
from horizon.utils import memoized
|
2013-05-15 14:45:03 -06:00
|
|
|
|
|
|
|
from openstack_dashboard import api
|
2014-02-05 12:08:15 -07:00
|
|
|
from openstack_dashboard import policy
|
2013-06-10 14:29:44 +02:00
|
|
|
|
2014-02-05 12:08:15 -07:00
|
|
|
from openstack_dashboard.dashboards.identity.roles \
|
2013-08-02 13:23:46 +04:00
|
|
|
import forms as project_forms
|
2014-02-05 12:08:15 -07:00
|
|
|
from openstack_dashboard.dashboards.identity.roles \
|
2013-08-02 13:23:46 +04:00
|
|
|
import tables as project_tables
|
2013-05-15 14:45:03 -06:00
|
|
|
|
|
|
|
|
|
|
|
class IndexView(tables.DataTableView):
|
2013-08-02 13:23:46 +04:00
|
|
|
table_class = project_tables.RolesTable
|
2015-02-10 13:33:56 +00:00
|
|
|
page_title = _("Roles")
|
2013-05-15 14:45:03 -06:00
|
|
|
|
2017-01-11 15:03:37 -06:00
|
|
|
def needs_filter_first(self, table):
|
|
|
|
return self._needs_filter_first
|
|
|
|
|
2013-05-15 14:45:03 -06:00
|
|
|
def get_data(self):
|
|
|
|
roles = []
|
2016-06-01 21:56:41 +00:00
|
|
|
filters = self.get_filters()
|
2017-01-11 15:03:37 -06:00
|
|
|
|
|
|
|
self._needs_filter_first = False
|
|
|
|
|
2014-02-05 12:08:15 -07:00
|
|
|
if policy.check((("identity", "identity:list_roles"),),
|
|
|
|
self.request):
|
2017-01-11 15:03:37 -06:00
|
|
|
|
|
|
|
# If filter_first is set and if there are not other filters
|
|
|
|
# selected, then search criteria must be provided
|
|
|
|
# and return an empty list
|
|
|
|
filter_first = getattr(settings, 'FILTER_DATA_FIRST', {})
|
|
|
|
if filter_first.get('identity.roles', False) and len(filters) == 0:
|
|
|
|
self._needs_filter_first = True
|
|
|
|
return roles
|
|
|
|
|
2014-02-05 12:08:15 -07:00
|
|
|
try:
|
2016-06-01 21:56:41 +00:00
|
|
|
roles = api.keystone.role_list(self.request,
|
|
|
|
filters=filters)
|
2014-02-05 12:08:15 -07:00
|
|
|
except Exception:
|
|
|
|
exceptions.handle(self.request,
|
|
|
|
_('Unable to retrieve roles list.'))
|
|
|
|
else:
|
|
|
|
msg = _("Insufficient privilege level to view role information.")
|
|
|
|
messages.info(self.request, msg)
|
2013-05-15 14:45:03 -06:00
|
|
|
return roles
|
|
|
|
|
|
|
|
|
|
|
|
class UpdateView(forms.ModalFormView):
|
2014-02-05 12:08:15 -07:00
|
|
|
template_name = 'identity/roles/update.html'
|
2014-12-11 18:03:13 -08:00
|
|
|
form_id = "update_role_form"
|
|
|
|
form_class = project_forms.UpdateRoleForm
|
|
|
|
submit_label = _("Update Role")
|
|
|
|
submit_url = "horizon:identity:roles:update"
|
2014-02-05 12:08:15 -07:00
|
|
|
success_url = reverse_lazy('horizon:identity:roles:index')
|
2015-02-10 13:33:56 +00:00
|
|
|
page_title = _("Update Role")
|
2013-05-15 14:45:03 -06:00
|
|
|
|
2013-10-28 11:24:00 +01:00
|
|
|
@memoized.memoized_method
|
2013-05-15 14:45:03 -06:00
|
|
|
def get_object(self):
|
2013-10-28 11:24:00 +01:00
|
|
|
try:
|
|
|
|
return api.keystone.role_get(self.request, self.kwargs['role_id'])
|
|
|
|
except Exception:
|
2014-02-05 12:08:15 -07:00
|
|
|
redirect = reverse("horizon:identity:roles:index")
|
2013-10-28 11:24:00 +01:00
|
|
|
exceptions.handle(self.request,
|
|
|
|
_('Unable to update role.'),
|
|
|
|
redirect=redirect)
|
2013-05-15 14:45:03 -06:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(UpdateView, self).get_context_data(**kwargs)
|
2014-12-11 18:03:13 -08:00
|
|
|
args = (self.get_object().id,)
|
|
|
|
context['submit_url'] = reverse(self.submit_url, args=args)
|
2013-05-15 14:45:03 -06:00
|
|
|
return context
|
|
|
|
|
|
|
|
def get_initial(self):
|
|
|
|
role = self.get_object()
|
|
|
|
return {'id': role.id,
|
|
|
|
'name': role.name}
|
|
|
|
|
|
|
|
|
|
|
|
class CreateView(forms.ModalFormView):
|
2014-02-05 12:08:15 -07:00
|
|
|
template_name = 'identity/roles/create.html'
|
2014-12-11 18:03:13 -08:00
|
|
|
form_id = "create_role_form"
|
|
|
|
form_class = project_forms.CreateRoleForm
|
|
|
|
submit_label = _("Create Role")
|
|
|
|
submit_url = reverse_lazy("horizon:identity:roles:create")
|
2014-02-05 12:08:15 -07:00
|
|
|
success_url = reverse_lazy('horizon:identity:roles:index')
|
2015-02-10 13:33:56 +00:00
|
|
|
page_title = _("Create Role")
|