Use self.has_perm() within MasterView

This commit is contained in:
Lance Edgar 2019-10-12 18:35:11 -05:00
parent 1e0f707a6d
commit 6c228a59f2

View file

@ -372,14 +372,12 @@ class MasterView(View):
Return a dictionary of kwargs to be passed to the factory when creating
new grid instances.
"""
permission_prefix = self.get_permission_prefix()
checkboxes = self.checkboxes
if not checkboxes and self.mergeable and self.request.has_perm('{}.merge'.format(permission_prefix)):
if not checkboxes and self.mergeable and self.has_perm('merge'):
checkboxes = True
if not checkboxes and self.supports_set_enabled_toggle and self.request.has_perm('{}.enable_disable_set'.format(permission_prefix)):
if not checkboxes and self.supports_set_enabled_toggle and self.has_perm('enable_disable_set'):
checkboxes = True
if not checkboxes and self.set_deletable and self.request.has_perm('{}.delete_set'.format(permission_prefix)):
if not checkboxes and self.set_deletable and self.has_perm('delete_set'):
checkboxes = True
defaults = {
@ -468,8 +466,6 @@ class MasterView(View):
"""
Return a dict of kwargs to be used when constructing a new rows grid.
"""
permission_prefix = self.get_permission_prefix()
defaults = {
'model_class': self.model_row_class,
'width': 'full',
@ -497,7 +493,7 @@ class MasterView(View):
actions.append(self.make_action('edit', icon=icon, url=self.row_edit_action_url))
# delete action
if self.rows_deletable and self.request.has_perm('{}.delete_row'.format(permission_prefix)):
if self.rows_deletable and self.has_perm('delete_row'):
actions.append(self.make_action('delete', icon='trash', url=self.row_delete_action_url))
defaults['delete_speedbump'] = self.rows_deletable_speedbump
@ -2480,9 +2476,8 @@ class MasterView(View):
Return a list of 'main' actions for the grid.
"""
actions = []
prefix = self.get_permission_prefix()
use_buefy = self.get_use_buefy()
if self.viewable and self.request.has_perm('{}.view'.format(prefix)):
if self.viewable and self.has_perm('view'):
url = self.get_view_index_url if self.use_index_links else None
icon = 'eye' if use_buefy else 'zoomin'
actions.append(self.make_action('view', icon=icon, url=url))
@ -2497,16 +2492,15 @@ class MasterView(View):
Return a list of 'more' actions for the grid.
"""
actions = []
prefix = self.get_permission_prefix()
use_buefy = self.get_use_buefy()
# Edit
if self.editable and self.request.has_perm('{}.edit'.format(prefix)):
if self.editable and self.has_perm('edit'):
icon = 'edit' if use_buefy else 'pencil'
actions.append(self.make_action('edit', icon=icon, url=self.default_edit_url))
# Delete
if self.deletable and self.request.has_perm('{}.delete'.format(prefix)):
if self.deletable and self.has_perm('delete'):
kwargs = {}
if use_buefy and self.delete_confirm == 'simple':
kwargs['click_handler'] = 'deleteObject'