def _add_groups_data(self, req, allow_manual=False): perms = sorted(PermissionSystem(self.env).get_all_permissions()) autocomplete = AutoCompleteGroup(self.env) all_groups = set(Group.groupsBy(self.env)) # TODO: we should remove the autocomplete plugin, at least # once userfield can handle "cc style" fields (e.g., multiple # users selected) and then I think userfieldplugin should take over ownership # of the "shown_groups" settings shown_groups = autocomplete.get_autocomplete_values('shown_groups') groups = {} for group_name in shown_groups: group = Group(self.env, group_name) groups[group_name] = { 'label': group.label } if not group.external_group: groups[group_name]['members'] = [] for subject, permission in perms: if permission == group_name and subject not in all_groups: subject_data = {'id': subject} session = DetachedSession(self.env, subject) if 'name' in session: subject_data['name'] = session['name'] groups[group_name]['members'].append(subject_data) add_script_data(req, {'userGroups': groups })
def filter_stream(self, req, method, filename, stream, data): select = tag.select( id="select-user-groups", multiple="multiple", name="user_groups", ) edit_name = req.path_info.replace("/admin/ticket/customfields", "")[1:] valid_edit = re.search('^[a-zA-Z][a-zA-Z0-9_]+$', edit_name) currently_editing = edit_name and valid_edit if currently_editing: groups = self.config.get("ticket-custom", edit_name+".groups") groups = groups.split("|") else: groups = [] is_manual = self.config.getbool("ticket-custom", edit_name+".manual") manual = tag.div( tag.label( "Allow typing a name which is not in the list:", for_="manual_selection", class_="fixed-width-label" ), tag.input( value="manual", checked="checked" if is_manual else None, type_="checkbox", name="manual_selection" ), class_="field" ) radios = tag( tag.label( "All ", tag.input( type="radio", value="all", name="all_or_selection", checked=("checked" if "*" in groups else None), ) ), tag.span( " or ", class_="color-muted" ), tag.label( "Selection ", tag.input( type="radio", value="selection", name="all_or_selection", checked=(None if "*" in groups else "checked"), ), style="padding-right: 5px" )) autocomplete = AutoCompleteGroup(self.env) for sid in autocomplete.get_autocomplete_values('shown_groups'): select.append(tag.option( Group(self.env, sid).label, value=sid, selected=("selected" if sid in groups or "*" in groups else None) )) if filename == "customfieldadmin.html": add_script(req, 'userfield/js/customfield-admin.js') selected = None customfield = data['cfadmin'].get('customfield', None) if customfield: if customfield['type'] == 'user': selected = 'selected' stream = stream | Transformer('.//select[@id="type"]').append( tag.option('User List', value='user', id="user_type_option", selected=selected) ) stream = stream | Transformer( './/div[@id="field-label"]' ).after( tag.div( tag.div( tag.label( 'Included groups:', for_="user-groups", class_="fixed-width-label", ), radios, select, class_="field", ), tag.div( tag.label(class_="fixed-width-label"), tag.span('To have more groups listed here, check "Show by default in user drop down boxes" in ', tag.a("Manage Access and Groups", target="_blank", href=req.href.admin('access', 'access_and_groups')), ' administration page.'), id="group-selection-help" ), manual, id="user-groups", class_="hidden" ) ) return stream