Merge "Add quota check for domain create"
This commit is contained in:
commit
6f01c060f7
@ -165,3 +165,10 @@ def record_update(request, domain_id, record_id, **kwargs):
|
|||||||
record.description = kwargs.get('description', None)
|
record.description = kwargs.get('description', None)
|
||||||
|
|
||||||
return d_client.records.update(domain_id, record)
|
return d_client.records.update(domain_id, record)
|
||||||
|
|
||||||
|
|
||||||
|
def quota_get(request, project_id=None):
|
||||||
|
if not project_id:
|
||||||
|
project_id = request.user.project_id
|
||||||
|
d_client = designateclient(request)
|
||||||
|
return d_client.quotas.get(project_id)
|
||||||
|
@ -17,6 +17,7 @@ from django.core import urlresolvers
|
|||||||
from django.utils.translation import ugettext_lazy as _ # noqa
|
from django.utils.translation import ugettext_lazy as _ # noqa
|
||||||
|
|
||||||
from horizon import tables
|
from horizon import tables
|
||||||
|
from horizon.utils import memoized
|
||||||
|
|
||||||
from designatedashboard import api
|
from designatedashboard import api
|
||||||
|
|
||||||
@ -44,6 +45,17 @@ class CreateDomain(tables.LinkAction):
|
|||||||
classes = ("ajax-modal", "btn-create")
|
classes = ("ajax-modal", "btn-create")
|
||||||
policy_rules = (("dns", "create_domain"),)
|
policy_rules = (("dns", "create_domain"),)
|
||||||
|
|
||||||
|
@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:
|
||||||
|
msg = _("The quotas could not be retrieved.")
|
||||||
|
messages.warning(request, msg)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class EditDomain(tables.LinkAction):
|
class EditDomain(tables.LinkAction):
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user