Check for get_quota policy before calling the API
When displaying the "Create Domain" button, if the user does not have the permission to get the quota, he would get a warning: "The quotas could not be retrieved." The warning shows every time when the user clicks on the Domains tab and is confusing. Add a policy check for rule get_quota before calling the designate quota_get() API and skip the call if the user does not have the permission. Change-Id: Ib0a0767b97257f7322ac326c24570a7a4cfc49b7 Closes-Bug: #1513586
This commit is contained in:
parent
a111b05f7d
commit
a4c131e42c
@ -22,6 +22,8 @@ from horizon.utils import memoized
|
||||
|
||||
from designatedashboard import api
|
||||
|
||||
from openstack_dashboard import policy
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
EDITABLE_RECORD_TYPES = (
|
||||
@ -48,13 +50,14 @@ class CreateDomain(tables.LinkAction):
|
||||
|
||||
@memoized.memoized_method
|
||||
def allowed(self, request, datum):
|
||||
try:
|
||||
if self.table:
|
||||
quota = api.designate.quota_get(request)
|
||||
return quota['domains'] > len(self.table.data)
|
||||
except Exception:
|
||||
msg = _("The quotas could not be retrieved.")
|
||||
messages.warning(request, msg)
|
||||
if policy.check((("dns", "get_quota"),), request):
|
||||
try:
|
||||
if self.table:
|
||||
quota = api.designate.quota_get(request)
|
||||
return quota['domains'] > len(self.table.data)
|
||||
except Exception:
|
||||
msg = _("The quotas could not be retrieved.")
|
||||
messages.warning(request, msg)
|
||||
return True
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user