]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix for showing default quotas to non-admin user
authorSzymon Borkowski <szymon.borkowski@intel.com>
Fri, 11 Dec 2015 11:20:03 +0000 (12:20 +0100)
committerSzymon Borkowski <szymon.borkowski@intel.com>
Fri, 11 Dec 2015 11:33:01 +0000 (12:33 +0100)
Earlier, when non-admin user wanted to get quotas for his own
projects, if there were no custom quota values set, the API
used to return zero values.

Change-Id: I753af89aa5aae5ad20abe48441df3dbd02b8e05e
Closes-Bug: 1523928

cinder/api/contrib/quotas.py
cinder/tests/unit/api/contrib/test_quotas.py

index e513f410b78da84d48deb45e775ac05357a19aad..13edb857da31ee1a89c2b6f3d7457fe31d1552ba 100644 (file)
@@ -231,7 +231,7 @@ class QuotaSetsController(wsgi.Controller):
             # NOTE(e0ne): Keystone API v2 requires admin permissions for
             # project_get method. We ignore Forbidden exception for
             # non-admin users.
-            parent_project_id = target_project_id
+            parent_project_id = None
 
         try:
             sqlalchemy_api.authorize_project_context(context,
index 398f096d961500703fec65853a94d106f5f14f10..021f094f5f5db5f735381f8fae1cbada90ee9018 100644 (file)
@@ -32,6 +32,7 @@ from cinder import db
 from cinder import test
 from cinder.tests.unit import test_db_api
 
+from keystoneclient import exceptions
 from keystonemiddleware import auth_token
 from oslo_config import cfg
 from oslo_config import fixture as config_fixture
@@ -207,6 +208,17 @@ class QuotaSetsControllerTest(test.TestCase):
         self.assertRaises(webob.exc.HTTPForbidden, self.controller.show,
                           self.req, 'foo')
 
+    def test_show_non_admin_user(self):
+        self.controller._get_project = mock.Mock()
+        self.controller._get_project.side_effect = exceptions.Forbidden
+        self.controller._get_quotas = mock.Mock(side_effect=
+                                                self.controller._get_quotas)
+        result = self.controller.show(self.req, 'foo')
+        self.assertDictMatch(make_body(), result)
+        self.controller._get_quotas.assert_called_with(
+            self.req.environ['cinder.context'], 'foo', False,
+            parent_project_id=None)
+
     def test_subproject_show_not_authorized(self):
         self.controller._get_project = mock.Mock()
         self.controller._get_project.side_effect = self._get_project