def get_from_user(pid, tids): ''' Get users from userdb by project, team :param str pid: pid :param str tids: team id or ids :return: fields, raws ''' if isinstance(tids, str): tids = (tids, ) team_users = Team.get_users(pid=pid, tids=tids) uids = [] for user_ids in team_users.values(): uids.extend(user_ids) user_infos = User.get_info(uids=uids) datas = [] for uid in user_infos: # append, plus more data here in the future datas.append({ 'name': user_infos[uid]['profile']['badge_name'], 'mail': user_infos[uid]['oauth']['email'], }) raws = [] for data in datas: raw = [] for field in ('name', 'mail'): raw.append(data[field]) raws.append(raw) return (('name', 'mail'), raws)
def get_from_user(pid: str, tids: Union[str, list[str]]) -> tuple[tuple[str, str], list[list[str]]]: ''' Get users from userdb by project, team Args: pid (str): Project id. tids (list): List of `tid`. Returns: Return a tuple with `('name', 'mail')` at first. The second is the all datas. ''' _tids: list[str] if isinstance(tids, str): _tids = [tids, ] else: _tids = tids team_users = Team.get_users(pid=pid, tids=_tids) uids = [] for user_ids in team_users.values(): uids.extend(user_ids) user_infos = User.get_info(uids=uids) datas = [] for value in user_infos.values(): # append, plus more data here in the future datas.append({ 'name': value['profile']['badge_name'], 'mail': value['oauth']['email'], }) raws = [] for data in datas: raw = [] for field in ('name', 'mail'): raw.append(data[field]) raws.append(raw) return (('name', 'mail'), raws)
def project_edit_create_team_api(pid): ''' Project edit create team API ''' project = Project.get(pid) if g.user['account']['_id'] not in project['owners']: return redirect( url_for('project.team_page', pid=pid, _scheme='https', _external=True)) if request.method == 'GET': _team = Team.get(pid, request.args['tid'].strip()) team = {} for k in ('name', 'chiefs', 'members', 'owners', 'tid', 'headcount', 'mailling', 'disabled'): if k in _team: team[k] = _team[k] if 'headcount' not in team: team['headcount'] = 0 else: team['headcount'] = max([0, int(team['headcount'])]) return jsonify(team) if request.method == 'POST': data = request.json if data['submittype'] == 'update': chiefs = data['chiefs'] members = data['members'] if isinstance(data['chiefs'], str): chiefs = [ _uid.strip() for _uid in data['chiefs'].split(',') if _uid.strip() ] if isinstance(data['members'], str): members = [ _uid.strip() for _uid in data['members'].split(',') if _uid.strip() ] new_members = set(chiefs + members) old_members = set( Team.get_users(pid=pid, tids=(data['tid'], ))[data['tid']]) TeamMemberChangedDB().make_record(pid=pid, tid=data['tid'], action={ 'add': new_members - old_members, 'del': old_members - new_members }) Team.update_setting(pid=pid, tid=data['tid'], data=data) service_sync_mattermost_add_channel.apply_async( kwargs={ 'pid': pid, 'uids': list(new_members) }) return f'{data}' if data['submittype'] == 'create': Team.create(pid=pid, tid=data['tid'], name=data['name'], owners=project['owners']) return f'{data}' return '', 404