diff --git a/tailbone/templates/principal/find_by_perm.mako b/tailbone/templates/principal/find_by_perm.mako
index 9cc5aa05..e0536324 100644
--- a/tailbone/templates/principal/find_by_perm.mako
+++ b/tailbone/templates/principal/find_by_perm.mako
@@ -16,44 +16,67 @@
${h.form(request.current_route_url(), method='GET', **{'@submit': 'formSubmitting = true'})}
+
-
-
-
-
-
+ ${h.hidden('permission_group', **{':value': 'selectedGroup'})}
+
+
+
+
+ {{ permissionGroups[selectedGroup].label }}
+
+
-
-
-
-
-
+ ${h.hidden('permission', **{':value': 'selectedPermission'})}
+
+
+
+
+ {{ selectedPermissionLabel }}
+
+
-
-
-
-
- {{ formSubmitting ? "Working, please wait..." : "Find ${model_title_plural}" }}
-
-
+
+
+
+
+
+ {{ formSubmitting ? "Working, please wait..." : "Find ${model_title_plural}" }}
+
+
+
+
${h.end_form()}
% if principals is not None:
@@ -91,24 +114,114 @@
data() {
return {
groupPermissions: ${json.dumps(buefy_perms.get(selected_group, {}).get('permissions', []))|n},
+ permissionGroupTerm: '',
+ permissionTerm: '',
selectedGroup: ${json.dumps(selected_group)|n},
- % if selected_permission:
selectedPermission: ${json.dumps(selected_permission)|n},
- % elif selected_group in buefy_perms:
- selectedPermission: ${json.dumps(buefy_perms[selected_group]['permissions'][0]['permkey'])|n},
- % else:
- selectedPermission: null,
- % endif
+ selectedPermissionLabel: ${json.dumps(selected_permission_label or '')|n},
formSubmitting: false,
}
},
+
+ computed: {
+
+ permissionGroupChoices() {
+
+ // collect all groups
+ let choices = []
+ for (let groupkey of this.sortedGroups) {
+ choices.push(this.permissionGroups[groupkey])
+ }
+
+ // parse list of search terms
+ let terms = []
+ for (let term of this.permissionGroupTerm.toLowerCase().split(' ')) {
+ term = term.trim()
+ if (term) {
+ terms.push(term)
+ }
+ }
+
+ // filter groups by search terms
+ choices = choices.filter(option => {
+ let label = option.label.toLowerCase()
+ for (let term of terms) {
+ if (label.indexOf(term) < 0) {
+ return false
+ }
+ }
+ return true
+ })
+
+ return choices
+ },
+
+ permissionChoices() {
+
+ // collect all permissions for current group
+ let choices = this.groupPermissions
+
+ // parse list of search terms
+ let terms = []
+ for (let term of this.permissionTerm.toLowerCase().split(' ')) {
+ term = term.trim()
+ if (term) {
+ terms.push(term)
+ }
+ }
+
+ // filter permissions by search terms
+ choices = choices.filter(option => {
+ let label = option.label.toLowerCase()
+ for (let term of terms) {
+ if (label.indexOf(term) < 0) {
+ return false
+ }
+ }
+ return true
+ })
+
+ return choices
+ },
+ },
+
methods: {
- selectGroup(groupkey) {
+ permissionGroupSelect(option) {
+ this.selectedPermission = null
+ this.selectedPermissionLabel = null
+ if (option) {
+ this.selectedGroup = option.groupkey
+ this.groupPermissions = this.permissionGroups[option.groupkey].permissions
+ this.$nextTick(() => {
+ this.$refs.permissionAutocomplete.focus()
+ })
+ }
+ },
- // re-populate Permission dropdown, auto-select first option
- this.groupPermissions = this.permissionGroups[groupkey].permissions
- this.selectedPermission = this.groupPermissions[0].permkey
+ permissionGroupReset() {
+ this.selectedGroup = null
+ this.selectedPermission = null
+ this.selectedPermissionLabel = ''
+ this.$nextTick(() => {
+ this.$refs.permissionGroupAutocomplete.focus()
+ })
+ },
+
+ permissionSelect(option) {
+ if (option) {
+ this.selectedPermission = option.permkey
+ this.selectedPermissionLabel = option.label
+ }
+ },
+
+ permissionReset() {
+ this.selectedPermission = null
+ this.selectedPermissionLabel = null
+ this.permissionTerm = ''
+ this.$nextTick(() => {
+ this.$refs.permissionAutocomplete.focus()
+ })
},
}
})
diff --git a/tailbone/templates/principal/index.mako b/tailbone/templates/principal/index.mako
index 4ed3ba5b..fa806455 100644
--- a/tailbone/templates/principal/index.mako
+++ b/tailbone/templates/principal/index.mako
@@ -3,8 +3,8 @@
<%def name="context_menu_items()">
${parent.context_menu_items()}
- % if request.has_perm('{}.find_by_perm'.format(permission_prefix)):
-
${h.link_to("Find {} with Permission X".format(model_title_plural), url('{}.find_by_perm'.format(route_prefix)))}
+ % if master.has_perm('find_by_perm'):
+
${h.link_to(f"Find {model_title_plural} by Permission", url(f'{route_prefix}.find_by_perm'))}
% endif
%def>
diff --git a/tailbone/views/principal.py b/tailbone/views/principal.py
index 5d477677..20f6b866 100644
--- a/tailbone/views/principal.py
+++ b/tailbone/views/principal.py
@@ -77,7 +77,20 @@ class PrincipalMasterView(MasterView):
perms = self.get_buefy_perms_data(sorted_perms)
context['buefy_perms'] = perms
context['buefy_sorted_groups'] = list(perms)
- context['selected_group'] = permission_group or 'common'
+
+ if permission_group and permission_group not in perms:
+ permission_group = None
+ if permission:
+ if permission_group:
+ group = dict([(p['permkey'], p) for p in perms[permission_group]['permissions']])
+ if permission in group:
+ context['selected_permission_label'] = group[permission]['label']
+ else:
+ permission = None
+ else:
+ permission = None
+
+ context['selected_group'] = permission_group
context['selected_permission'] = permission
return self.render_to_response('find_by_perm', context)