Fix policy function check error

Change in I8a346e55bb98e4e22e0c14a614c45d493d20feb4 to make
POLICY_CHECK_FUNCTION a string rather than a function was incomplete.

The case in horizon/tables/base.py is problematic in particular and results in
raising the TypeError: 'str' object is not callable error.

There is another instance that is not problematic, but is changed for
consistency sake.

Change-Id: Ifc616e322eb38ec7e5ac218f7f3c5ccec52e40f4
Closes-Bug: #1818292
This commit is contained in:
David Lyle
2019-03-01 14:15:21 -07:00
parent bdf7e69222
commit 78de547871
2 changed files with 4 additions and 3 deletions

View File

@@ -46,6 +46,7 @@ from horizon.tables.actions import BatchAction
from horizon.tables.actions import FilterAction from horizon.tables.actions import FilterAction
from horizon.tables.actions import LinkAction from horizon.tables.actions import LinkAction
from horizon.utils import html from horizon.utils import html
from horizon.utils import settings as utils_settings
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@@ -380,7 +381,7 @@ class Column(html.HTMLElement):
if not self.policy_rules: if not self.policy_rules:
return True return True
policy_check = getattr(settings, "POLICY_CHECK_FUNCTION", None) policy_check = utils_settings.import_setting("POLICY_CHECK_FUNCTION")
if policy_check: if policy_check:
return policy_check(self.policy_rules, request) return policy_check(self.policy_rules, request)

View File

@@ -12,18 +12,18 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from django.conf import settings
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from openstack_auth import utils from openstack_auth import utils
import horizon import horizon
from horizon.utils import settings as utils_settings
class Admin(horizon.Dashboard): class Admin(horizon.Dashboard):
name = _("Admin") name = _("Admin")
slug = "admin" slug = "admin"
if getattr(settings, 'POLICY_CHECK_FUNCTION', None): if utils_settings.import_setting("POLICY_CHECK_FUNCTION"):
policy_rules = (('identity', 'admin_required'), policy_rules = (('identity', 'admin_required'),
('image', 'context_is_admin'), ('image', 'context_is_admin'),
('volume', 'context_is_admin'), ('volume', 'context_is_admin'),