def item(self, group_id): """ 获取某个用户组 /group/<int:group_id> :param group_id: :return: """ ## sqlalchemy版本 group_model = MemberModel() group = group_model.members(group_id=group_id) if group: return self.render_json(data=group) return self.render_json(code=-1) ## mixin 版本 group_model = TagModel().get_by_id(group_id) if not group_model: return self.render_json(code=-1) user_model = UserModel() user_info = user_model.fetch_by_uid(uids=group_model.users) group_info = group_model.to_dict() group_info['members'] = user_info group_info['users'] = len(user_info) group_info['group_name'] = group_info['name'] group_info['group_id'] = group_info['id'] return self.render_json(data=group_info)
def to_json(self): item = { 'id': self.id, 'user_id': self.user_id, 'name': self.name, 'environment_id': self.environment_id, 'space_id': self.space_id, 'status': self.status, 'master': UserModel.fetch_by_uid(self.master.split(',')) if self.master else '', 'version': self.version, 'excludes': self.excludes, 'target_user': self.target_user, 'target_port': self.target_port, 'target_root': self.target_root, 'target_releases': self.target_releases, 'server_ids': self.server_ids, 'task_vars': self.task_vars, 'prev_deploy': self.prev_deploy, 'post_deploy': self.post_deploy, 'prev_release': self.prev_release, 'post_release': self.post_release, 'keep_version_num': self.keep_version_num, 'repo_url': self.repo_url, 'repo_username': self.repo_username, 'repo_password': self.repo_password, 'repo_mode': self.repo_mode, 'repo_type': self.repo_type, 'notice_type': self.notice_type, 'notice_hook': self.notice_hook, 'enable_audit': self.enable_audit, 'created_at': self.created_at.strftime('%Y-%m-%d %H:%M:%S'), 'updated_at': self.updated_at.strftime('%Y-%m-%d %H:%M:%S'), } item.update(self.enable()) return item
def to_json(self): item = { 'id': self.id, 'user_id': self.user_id, 'name': self.name, 'environment_id': self.environment_id, 'space_id': self.space_id, 'status': self.status, 'master': UserModel.fetch_by_uid(self.master.split(',')) if self.master else '', 'version': self.version, 'excludes': self.excludes, 'is_include': self.is_include, 'target_root': self.target_root, 'target_releases': self.target_releases, 'server_ids': self.server_ids, 'task_vars': self.task_vars, 'prev_deploy': self.prev_deploy, 'post_deploy': self.post_deploy, 'prev_release': self.prev_release, 'post_release': self.post_release, 'keep_version_num': self.keep_version_num, 'repo_url': self.repo_url, 'repo_username': self.repo_username, 'repo_password': self.repo_password, 'repo_mode': self.repo_mode, 'repo_type': self.repo_type, 'notice_type': self.notice_type, 'notice_hook': self.notice_hook, 'task_audit': self.task_audit, 'created_at': self.created_at.strftime('%Y-%m-%d %H:%M:%S'), 'updated_at': self.updated_at.strftime('%Y-%m-%d %H:%M:%S'), } item.update(self.enable()) return item
def item(self, group_id): """ 获取某个用户组 /group/<int:group_id> :param group_id: :return: """ ## sqlalchemy版本 group_model = MemberModel() group = group_model.members(group_id=group_id) if group: return self.render_json(data=group) return self.render_json(code=-1) ## mixin 版本 group_model = TagModel().get_by_id(group_id) if not group_model: return self.render_json(code=-1) user_model = UserModel() user_info = user_model.fetch_by_uid(uids=group_model.users) group_info = group_model.to_dict() group_info['members'] = user_info group_info['users'] = len(user_info) group_info['group_name'] = group_info['name'] group_info['group_id'] = group_info['id'] return self.render_json(data=group_info)
def members(self, group_id=None, project_id=None, page=1, size=10, kw=None): """ 获取单条记录 :param role_id: :return: """ group_id = group_id if group_id else self.group_id project_id = project_id if project_id else self.project_id source_id = group_id if group_id else project_id source_type = self.source_type_group if group_id else self.source_type_project filters = { 'status': { 'nin': [self.status_remove] }, 'source_id': { '=': source_id }, 'source_type': { '=': source_type }, } # if kw: # filters['email'] = {'like': kw} # TODO groups, count = MemberModel.query_paginate(page=page, limit=size, filter_name_dict=filters) user_ids = [] user_role = members = {} current_app.logger.info(groups) for group_info in groups: user_ids.append(group_info.user_id) # TODO user_role[group_info.user_id] = group_info.access_level current_app.logger.info(user_ids) user_model = UserModel() user_info = user_model.fetch_by_uid(uids=set(user_ids)) if user_info: for user in user_info: if user_role.has_key(user['id']): user['role'] = user_role[user['id']] members['user_ids'] = user_ids members['members'] = user_info members['count'] = count return members
def members_new(self, group_id=None, project_id=None, page=1, size=10, kw=None): """ 获取单条记录 :param role_id: :return: """ group_id = group_id if group_id else self.group_id project_id = project_id if project_id else self.project_id source_id = group_id if group_id else project_id source_type = self.source_type_group if group_id else self.source_type_project query = self.query.filter(MemberModel.source_id == source_id).filter(MemberModel.source_type == source_type) query = query.join(UserModel, UserModel.id == MemberModel.user_id) if kw: query = query.filter(or_(UserModel.username.like('%' + kw + '%'), UserModel.email.like('%' + kw + '%'))) query = query.add_columns(UserModel.username) count = query.count() data = query.order_by(MemberModel.id.asc()).offset(int(size) * int(page)).limit(size).all() list = [] for p in data: item = p[0].to_json() item['username'] = p[1] list.append(item) return list, count # TODO groups, count = MemberModel.query_paginate(page=page, limit=size, filter_name_dict=filters) user_ids = [] user_role = members = {} current_app.logger.info(groups) for group_info in groups: user_ids.append(group_info.user_id) # TODO user_role[group_info.user_id] = group_info.access_level current_app.logger.info(user_ids) user_model = UserModel() user_info = user_model.fetch_by_uid(uids=set(user_ids)) if user_info: for user in user_info: if user_role.has_key(user['id']): user['role'] = user_role[user['id']] members['user_ids'] = user_ids members['members'] = user_info members['count'] = count return members
def members(self, group_id=None, project_id=None, page=1, size=10, kw=None): """ 获取单条记录 :param role_id: :return: """ group_id = group_id if group_id else self.group_id project_id = project_id if project_id else self.project_id source_id = group_id if group_id else project_id source_type = self.source_type_group if group_id else self.source_type_project filters = { 'status': {'nin': [self.status_remove]}, 'source_id': {'=': source_id}, 'source_type': {'=': source_type}, } # if kw: # filters['email'] = {'like': kw} # TODO groups, count = MemberModel.query_paginate(page=page, limit=size, filter_name_dict=filters) user_ids = [] user_role = members = {} current_app.logger.info(groups) for group_info in groups: user_ids.append(group_info.user_id) # TODO user_role[group_info.user_id] = group_info.access_level current_app.logger.info(user_ids) user_model = UserModel() user_info = user_model.fetch_by_uid(uids=set(user_ids)) if user_info: for user in user_info: if user_role.has_key(user['id']): user['role'] = user_role[user['id']] members['user_ids'] = user_ids members['members'] = user_info members['count'] = count return members
def members_new(self, group_id=None, project_id=None, page=1, size=10, kw=None): """ 获取单条记录 :param role_id: :return: """ group_id = group_id if group_id else self.group_id project_id = project_id if project_id else self.project_id source_id = group_id if group_id else project_id source_type = self.source_type_group if group_id else self.source_type_project query = self.query.filter(MemberModel.source_id == source_id).filter( MemberModel.source_type == source_type) query = query.join(UserModel, UserModel.id == MemberModel.user_id) if kw: query = query.filter( or_(UserModel.username.like('%' + kw + '%'), UserModel.email.like('%' + kw + '%'))) query = query.add_columns(UserModel.username) count = query.count() data = query.order_by(MemberModel.id.asc()).offset( int(size) * int(page)).limit(size).all() list = [] for p in data: item = p[0].to_json() item['username'] = p[1] list.append(item) return list, count # TODO groups, count = MemberModel.query_paginate(page=page, limit=size, filter_name_dict=filters) user_ids = [] user_role = members = {} current_app.logger.info(groups) for group_info in groups: user_ids.append(group_info.user_id) # TODO user_role[group_info.user_id] = group_info.access_level current_app.logger.info(user_ids) user_model = UserModel() user_info = user_model.fetch_by_uid(uids=set(user_ids)) if user_info: for user in user_info: if user_role.has_key(user['id']): user['role'] = user_role[user['id']] members['user_ids'] = user_ids members['members'] = user_info members['count'] = count return members