Adds button to disable more than one domain at a time

Buttons added to the Domains table which enable and
disable selected domains from the table. Buttons to
execute as BatchAction action.

Change-Id: I1c42382d1e36c362021e60998ba12f8b110150df
Closes-Bug: #1365359
This commit is contained in:
Martin Hickey 2015-08-14 16:09:24 +01:00
parent 5796aa97a7
commit a71e25ecab
2 changed files with 127 additions and 1 deletions

View File

@ -123,6 +123,86 @@ class DeleteDomainsAction(tables.DeleteAction):
api.keystone.domain_delete(request, obj_id)
class DisableDomainsAction(tables.BatchAction):
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Disable Domain",
u"Disable Domains",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Disabled Domain",
u"Disabled Domains",
count
)
name = "disable"
policy_rules = (('identity', 'identity:update_domain'),)
verbose_name = _("Disable Domains")
def allowed(self, request, datum):
return api.keystone.keystone_can_edit_domain() \
and (datum is None or datum.enabled)
def action(self, request, obj_id):
domain = self.table.get_object_by_id(obj_id)
if domain.enabled:
LOG.info('Disabling domain "%s".' % obj_id)
try:
api.keystone.domain_update(request,
domain_id=domain.id,
name=domain.name,
description=domain.description,
enabled=False)
except Exception:
exceptions.handle(request, ignore=True)
return False
class EnableDomainsAction(tables.BatchAction):
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Enable Domain",
u"Enable Domains",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Enabled Domain",
u"Enabled Domains",
count
)
name = "enable"
policy_rules = (('identity', 'identity:update_domain'),)
verbose_name = _("Enable Domains")
def allowed(self, request, datum):
return api.keystone.keystone_can_edit_domain() \
and (datum is None or not datum.enabled)
def action(self, request, obj_id):
domain = self.table.get_object_by_id(obj_id)
if not domain.enabled:
LOG.info('Enabling domain "%s".' % obj_id)
try:
api.keystone.domain_update(request,
domain_id=domain.id,
name=domain.name,
description=domain.description,
enabled=True)
except Exception:
exceptions.handle(request, ignore=True)
return False
class DomainFilterAction(tables.FilterAction):
def allowed(self, request, datum):
multidomain_support = getattr(settings,
@ -206,7 +286,9 @@ class DomainsTable(tables.DataTable):
class Meta(object):
name = "domains"
verbose_name = _("Domains")
table_actions_menu = (EnableDomainsAction, DisableDomainsAction)
row_actions = (SetDomainContext, UpdateUsersLink, UpdateGroupsLink,
EditDomainLink, DeleteDomainsAction)
EditDomainLink, EnableDomainsAction,
DisableDomainsAction, DeleteDomainsAction)
table_actions = (DomainFilterAction, CreateDomainLink,
DeleteDomainsAction, UnsetDomainContext)

View File

@ -49,6 +49,8 @@ class DomainsViewTests(test.BaseAdminViewTests):
self.assertContains(res, 'Create Domain')
self.assertContains(res, 'Edit')
self.assertContains(res, 'Delete Domain')
self.assertContains(res, 'Disable Domain')
self.assertContains(res, 'Enable Domain')
@test.create_stubs({api.keystone: ('domain_list',
'keystone_can_edit_domain')})
@ -66,6 +68,8 @@ class DomainsViewTests(test.BaseAdminViewTests):
self.assertNotContains(res, 'Create Domain')
self.assertNotContains(res, 'Edit')
self.assertNotContains(res, 'Delete Domain')
self.assertNotContains(res, 'Disable Domain')
self.assertNotContains(res, 'Enable Domain')
@test.create_stubs({api.keystone: ('domain_list',
'domain_delete')})
@ -96,6 +100,46 @@ class DomainsViewTests(test.BaseAdminViewTests):
self.assertRedirectsNoFollow(res, DOMAINS_INDEX_URL)
self.assertMessageCount(error=2)
@test.create_stubs({api.keystone: ('domain_list',
'domain_update')})
def test_disable(self):
domain = self.domains.get(id="1")
api.keystone.domain_list(IgnoreArg()).AndReturn(self.domains.list())
api.keystone.domain_update(IsA(http.HttpRequest),
description=domain.description,
domain_id=domain.id,
enabled=False,
name=domain.name).AndReturn(None)
self.mox.ReplayAll()
formData = {'action': 'domains__disable__%s' % domain.id}
res = self.client.post(DOMAINS_INDEX_URL, formData)
self.assertRedirectsNoFollow(res, DOMAINS_INDEX_URL)
self.assertMessageCount(error=0)
@test.create_stubs({api.keystone: ('domain_list',
'domain_update')})
def test_enable(self):
domain = self.domains.get(id="2")
api.keystone.domain_list(IgnoreArg()).AndReturn(self.domains.list())
api.keystone.domain_update(IsA(http.HttpRequest),
description=domain.description,
domain_id=domain.id,
enabled=True,
name=domain.name).AndReturn(None)
self.mox.ReplayAll()
formData = {'action': 'domains__enable__%s' % domain.id}
res = self.client.post(DOMAINS_INDEX_URL, formData)
self.assertRedirectsNoFollow(res, DOMAINS_INDEX_URL)
self.assertMessageCount(error=0)
@test.create_stubs({api.keystone: ('domain_get',
'domain_list', )})
def test_set_clear_domain_context(self):