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 _get_valid_groups(self, field): allowed_groups = self.config.get("ticket-custom", field+".groups") if not allowed_groups: return [] elif allowed_groups == "*": return [sid for sid in Group.groupsBy(self.env)] else: return allowed_groups.split("|")
def render_admin_panel(self, req, cat, page, path_info): if 'LOGIN_ADMIN' in req.perm: if (page == 'project-message' and 'PROJECTMESSAGE_CREATE' in req.perm): groups = (sid for sid in Group.groupsBy(self.env)) previous_msgs = ProjectMessage.get_all_messages(self.env) for m in previous_msgs: for k in ('created_at', 'start', 'end'): m[k] = m[k].strftime('%Y-%m-%d') data = { 'mode_options': ProjectMessageSystem(self.env).mode_options, 'group_options': itertools.chain(groups, ['*']), 'msgs': previous_msgs, 'start_date': datetime.now().strftime("%Y-%m-%d"), 'end_date': (datetime.now() + timedelta(days=7)).strftime("%Y-%m-%d"), } # the message can be wiki mark-up Chrome(self.env).add_wiki_toolbars(req) add_script(req, 'projectmessage/js/project_message_admin.js') add_stylesheet(req, 'projectmessage/css/project_message_admin.css') if req.method == 'POST': name = req.args.get('name') message = req.args.get('message') button = req.args.get('button') mode = req.args.get('mode') groups = req.args.get('groups', []) start = req.args.get('start') end = req.args.get('end') if not all((name, message, button, mode, groups, start, end)): add_notice(req, "Please complete the form - some " "fields were left blank.") data.update(req.args) return 'project_message_admin.html', data new_msg = ProjectMessage(self.env) msg_args = copy.deepcopy(req.args) msg_args['author'] = req.authname msg_args['created_at'] = to_utimestamp(datetime.now(pytz.utc)) if isinstance(groups, basestring): msg_args['groups'] = [groups] new_msg.populate(msg_args) error = None if not new_msg.unique_name: add_warning(req, "There is already a project message " "with the name %s. Please choose " "a different name." % name) error = True elif not new_msg.valid_date_format: add_warning(req, "Incorrect format for date. " "Should be YYYY-MM-DD" ) error = True elif not new_msg.valid_date_range: add_warning(req, "The date difference between start date and " "end date should be of atleast 1 day.") error = True if error: data.update(req.args) return 'project_message_admin.html', data new_msg.insert() try: ProjectMessage(self.env, name) except ResourceNotFound: add_warning(req, "Unable to save project message. " "Please try again.") data.update(req.args) else: add_notice(req, "New project message created.") self.log.info("New project message '%s' created", name) # don't show a timestamp to the user - bad UI new_msg['created_at'] = from_utimestamp(new_msg['created_at']).strftime('%Y-%m-%d') data['msgs'].append(new_msg) return 'project_message_admin.html', data elif (page == 'project-message-records' and 'PROJECTMESSAGE_VIEW' in req.perm): records = ProjectMessageRecord.get_all_records(self.env) for r in records: r['agreed_at'] = r['agreed_at'].strftime("%Y-%m-%d %H:%M") data = { 'records': records, } return 'project_message_records.html', data