Add basic Buefy support for "find user/role with permission X"

still not totally polished, but works as expected
This commit is contained in:
Lance Edgar 2019-04-18 22:13:05 -05:00
parent ea54ca6c11
commit efb1a73e88
2 changed files with 144 additions and 2 deletions

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2018 Lance Edgar
# Copyright © 2010-2019 Lance Edgar
#
# This file is part of Rattail.
#
@ -30,6 +30,7 @@ import copy
from rattail.db.auth import has_permission
from rattail.core import Object
from rattail.util import OrderedDict
import wtforms
from webhelpers2.html import HTML
@ -84,8 +85,35 @@ class PrincipalMasterView(MasterView):
principals = self.find_principals_with_permission(self.Session(), permission)
context = {'form': form, 'permissions': sorted_perms, 'principals': principals}
if self.get_use_buefy():
perms = self.get_buefy_perms_data(sorted_perms)
context['buefy_perms'] = perms
context['buefy_sorted_groups'] = list(perms)
context['selected_group'] = self.request.POST.get('permission_group', 'common')
context['selected_permission'] = self.request.POST.get('permission', None)
return self.render_to_response('find_by_perm', context)
def get_buefy_perms_data(self, sorted_perms):
data = OrderedDict()
for gkey, group in sorted_perms:
gperms = []
for pkey, perm in group['perms']:
gperms.append({
'permkey': pkey,
'label': perm['label'],
})
data[gkey] = {
'groupkey': gkey,
'label': group['label'],
'permissions': gperms,
}
return data
@classmethod
def defaults(cls, config):
cls._principal_defaults(config)