From 9e185bca08510ec831afdd75013bb3655d9a6e76 Mon Sep 17 00:00:00 2001 From: Zhengwei Gao Date: Wed, 2 Aug 2017 20:05:20 +0800 Subject: [PATCH] Allow unprivileged users to get their quota usage When user try to get quota usage detail for their own project, it will return null. As process logic of details method is incorrect, it only allow admin to get other's project quota usage detail. Change-Id: I2e21dac497a6c5bffba6b55cb4456820900449df Closes-Bug: #1708133 --- neutron/extensions/quotasv2_detail.py | 4 ++-- neutron/tests/unit/api/v2/test_base.py | 6 +++--- neutron/tests/unit/extensions/test_quotasv2_detail.py | 5 ++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/neutron/extensions/quotasv2_detail.py b/neutron/extensions/quotasv2_detail.py index 9a673182c33..fc2f422d712 100644 --- a/neutron/extensions/quotasv2_detail.py +++ b/neutron/extensions/quotasv2_detail.py @@ -52,8 +52,8 @@ class DetailQuotaSetsController(quotasv2.QuotaSetsController): reason = _("Only admin is authorized to access quotas for" " another tenant") raise n_exc.AdminRequired(reason=reason) - return {self._resource_name: - self._get_detailed_quotas(request, id)} + return {self._resource_name: + self._get_detailed_quotas(request, id)} class Quotasv2_detail(api_extensions.ExtensionDescriptor): diff --git a/neutron/tests/unit/api/v2/test_base.py b/neutron/tests/unit/api/v2/test_base.py index d1d01cc2569..455b3183683 100644 --- a/neutron/tests/unit/api/v2/test_base.py +++ b/neutron/tests/unit/api/v2/test_base.py @@ -61,12 +61,12 @@ def _get_path(resource, id=None, action=None, if action is not None: path = path + '/%s' % action - if fmt is not None: - path = path + '.%s' % fmt - if endpoint is not None: path = path + '/%s' % endpoint + if fmt is not None: + path = path + '.%s' % fmt + return path diff --git a/neutron/tests/unit/extensions/test_quotasv2_detail.py b/neutron/tests/unit/extensions/test_quotasv2_detail.py index f24265c0b1f..0692a328167 100644 --- a/neutron/tests/unit/extensions/test_quotasv2_detail.py +++ b/neutron/tests/unit/extensions/test_quotasv2_detail.py @@ -69,8 +69,7 @@ class DetailQuotaExtensionDbTestCase(DetailQuotaExtensionTestCase): def test_show_detail_quotas(self): tenant_id = 'tenant_id1' - env = {'neutron.context': context.Context('', tenant_id, - is_admin=True)} + env = {'neutron.context': context.Context('', tenant_id)} res = self.api.get(_get_path('quotas', id=tenant_id, fmt=self.fmt, endpoint=DEFAULT_QUOTAS_ACTION), @@ -144,7 +143,7 @@ class DetailQuotaExtensionDbTestCase(DetailQuotaExtensionTestCase): def test_detail_quotas_without_admin_forbidden_returns_403(self): tenant_id = 'tenant_id1' - env = {'neutron.context': context.Context('', tenant_id, + env = {'neutron.context': context.Context('', tenant_id + '2', is_admin=False)} res = self.api.get(_get_path('quotas', id=tenant_id, fmt=self.fmt,