Source code for openstack_dashboard.dashboards.admin.domains.tables

# 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.

import logging

from django.conf import settings  # noqa
from django.core.urlresolvers import reverse  # noqa
from django.utils.http import urlencode  # noqa
from django.utils.translation import ugettext_lazy as _  # noqa

from keystoneclient import exceptions

from horizon import messages
from horizon import tables

from openstack_dashboard import api

from openstack_dashboard.dashboards.admin.domains import constants


LOG = logging.getLogger(__name__)


class ViewGroupsLink(tables.LinkAction):
    name = "groups"



[docs] data_type_singular = _("Domain") data_type_plural = _("Domains") policy_rules = (('identity', 'identity:delete_domain'),) def allowed(self, request, datum): return api.keystone.keystone_can_edit_domain()
[docs] def delete(self, request, obj_id): domain = self.table.get_object_by_id(obj_id)
[docs] if domain.enabled: msg = _('Domain "%s" must be disabled before it can be deleted.') \ % domain.name messages.error(request, msg) raise exceptions.ClientException(409, msg) else: LOG.info('Deleting domain "%s".' % obj_id) api.keystone.domain_delete(request, obj_id) class DomainFilterAction(tables.FilterAction): def allowed(self, request, datum):
[docs] multidomain_support = getattr(settings,
[docs] 'OPENSTACK_KEYSTONE_MULTIDOMAIN_SUPPORT', False) return multidomain_support def filter(self, table, domains, filter_string): """ Naive case-insensitive search """
[docs] q = filter_string.lower() def comp(domain): if q in domain.name.lower(): return True return False return filter(comp, domains) class SetDomainContext(tables.Action): name = "set_domain_context"
[docs] verbose_name = _("Set Domain Context") url = constants.DOMAINS_INDEX_URL preempt = True policy_rules = (('identity', 'admin_required'),) def allowed(self, request, datum): multidomain_support = getattr(settings,
[docs] 'OPENSTACK_KEYSTONE_MULTIDOMAIN_SUPPORT', False) if not multidomain_support: return False ctx = request.session.get("domain_context", None) if ctx and datum.id == ctx: return False return True def single(self, table, request, obj_id): if ('domain_context' not in request.session or
[docs] request.session['domain_context'] != obj_id): try: domain = api.keystone.domain_get(request, obj_id) request.session['domain_context'] = obj_id request.session['domain_context_name'] = domain.name messages.success(request, _('Domain Context updated to Domain %s.') % domain.name) except Exception: messages.error(request, _('Unable to set Domain Context.')) class UnsetDomainContext(tables.Action): name = "clear_domain_context"
[docs] verbose_name = _("Clear Domain Context") url = constants.DOMAINS_INDEX_URL preempt = True requires_input = False policy_rules = (('identity', 'admin_required'),) def allowed(self, request, datum): ctx = request.session.get("domain_context", None)
[docs] return ctx is not None def single(self, table, request, obj_id): if 'domain_context' in request.session:
[docs] request.session.pop("domain_context") request.session.pop("domain_context_name") messages.success(request, _('Domain Context cleared.')) class DomainsTable(tables.DataTable): name = tables.Column('name', verbose_name=_('Name'))
[docs] description = tables.Column(lambda obj: getattr(obj, 'description', None), verbose_name=_('Description')) id = tables.Column('id', verbose_name=_('Domain ID')) enabled = tables.Column('enabled', verbose_name=_('Enabled'), status=True) class Meta: name = "domains"
[docs] verbose_name = _("Domains") row_actions = (SetDomainContext, ViewGroupsLink, EditDomainLink, DeleteDomainsAction) table_actions = (DomainFilterAction, CreateDomainLink, DeleteDomainsAction, UnsetDomainContext)