diff --git a/server/model/schema.py b/server/model/schema.py index 6214167c..8a9f514d 100644 --- a/server/model/schema.py +++ b/server/model/schema.py @@ -117,16 +117,13 @@ class Account(User): class BindUser(Base): __tablename__ = "bind_user" user_id = db.Column(ObjID(12), ForeignKey("user.id"), nullable=True, comment="用户ID") - # 这里如果是飞书租户,可能会有不同的name等,但是在github这边不管是哪一个org,都是一样的 - # 这里如何统一? - # 是不是说这里暂时不需要这个platform_id,还是说这个字段为空就好? - platform_id = db.Column( - ObjID(12), ForeignKey("im_platform.id"), nullable=True, comment="平台" - ) - unionid = db.Column(db.String(128), nullable=True, comment="飞书的unionid") - # 这里还是用platform标记一下 platform = db.Column(db.String(128), nullable=True, comment="平台:github/lark") + # 实际关联的,可能是code_application.id或者im_application.id + application_id = db.Column(ObjID(12), nullable=True, comment="应用ID") + unionid = db.Column(db.String(128), nullable=True, comment="飞书的unionid") + openid = db.Column(db.String(128), nullable=True, comment="飞书的openid") + email = db.Column(db.String(128), nullable=True, comment="邮箱") name = db.Column(db.String(128), nullable=True, comment="用户名") avatar = db.Column(db.String(128), nullable=True, comment="头像") @@ -138,12 +135,7 @@ class BindUser(Base): class Team(Base): __tablename__ = "team" user_id = db.Column(ObjID(12), ForeignKey("user.id"), nullable=True, comment="用户ID") - code_platform_id = db.Column( - ObjID(12), ForeignKey("code_platform.id"), nullable=True, comment="代码平台" - ) - im_platform_id = db.Column( - ObjID(12), ForeignKey("im_platform.id"), nullable=True, comment="协同平台" - ) + # 移除从team到application_id的关联,使用application.team_id关联 name = db.Column(db.String(128), nullable=True, comment="名称") description = db.Column(db.String(1024), nullable=True, comment="描述") @@ -164,30 +156,18 @@ class TeamMember(Base): ObjID(12), ForeignKey("bind_user.id"), nullable=True, - comment="从code_platform关联过来的用户", + comment="从code_application关联过来的用户", ) im_user_id = db.Column( ObjID(12), ForeignKey("bind_user.id"), nullable=True, - comment="从im_platform关联过来的用户", - ) - - -class CodePlatform(Base): - __tablename__ = "code_platform" - name = db.Column(db.String(128), nullable=True, comment="名称") - description = db.Column(db.String(1024), nullable=True, comment="描述") - extra = db.Column( - JSONStr(1024), nullable=True, server_default=text("'{}'"), comment="其他字段" + comment="从im_application关联过来的用户", ) class Repo(Base): __tablename__ = "repo" - code_platform_id = db.Column( - ObjID(12), ForeignKey("code_platform.id"), nullable=True, comment="属于哪一个org" - ) application_id = db.Column( ObjID(12), ForeignKey("code_application.id"), @@ -203,9 +183,6 @@ class Repo(Base): class RepoUser(Base): __tablename__ = "repo_user" - code_platform_id = db.Column( - ObjID(12), ForeignKey("code_platform.id"), nullable=True, comment="属于哪一个org" - ) application_id = db.Column( ObjID(12), ForeignKey("code_application.id"), @@ -217,20 +194,10 @@ class RepoUser(Base): ) -class IMPlatform(Base): - __tablename__ = "im_platform" - tenant_key = db.Column(db.String(128), nullable=True, comment="飞书租户id") - name = db.Column(db.String(128), nullable=True, comment="名称") - description = db.Column(db.String(1024), nullable=True, comment="描述") - extra = db.Column( - JSONStr(1024), nullable=True, server_default=text("'{}'"), comment="其他字段" - ) - - class CodeApplication(Base): __tablename__ = "code_application" - platform_id = db.Column( - ObjID(12), ForeignKey("code_platform.id"), nullable=True, comment="代码平台" + team_id = db.Column( + ObjID(12), ForeignKey("team.id"), nullable=True, comment="属于哪一个组" ) installation_id = db.Column(db.String(128), nullable=True, comment="安装id") extra = db.Column( @@ -267,8 +234,8 @@ class CodeAction(Base): class IMApplication(Base): __tablename__ = "im_application" - platform_id = db.Column( - ObjID(12), ForeignKey("code_platform.id"), nullable=True, comment="协同平台" + team_id = db.Column( + ObjID(12), ForeignKey("team.id"), nullable=True, comment="属于哪一个组" ) app_id = db.Column(db.String(128), nullable=True, comment="app_id") app_secret = db.Column(db.String(128), nullable=True, comment="app_id") diff --git a/server/model/team.py b/server/model/team.py index 69b8f85d..1ae49502 100644 --- a/server/model/team.py +++ b/server/model/team.py @@ -2,7 +2,7 @@ from sqlalchemy import and_, or_ from utils.utils import query_one_page -from .schema import Team, TeamMember, db +from .schema import * def get_team_list_by_user_id(user_id, page=1, size=100): @@ -58,9 +58,22 @@ def get_team_by_id(team_id, user_id): return team -def get_platform_info_by_team_id(team_id): +def get_application_info_by_team_id(team_id): # TODO - return None, None + return ( + db.session.query(CodeApplication) + .filter( + CodeApplication.team_id == team_id, + CodeApplication.status == 0, + ) + .first(), + db.session.query(IMApplication) + .filter( + IMApplication.team_id == team_id, + IMApplication.status == 0, + ) + .first(), + ) def get_team_member(team_id, user_id, page=1, size=20): @@ -83,12 +96,12 @@ def get_im_user_by_team_id(team_id, page=1, size=20): query = ( db.session.query(BindUser) .join( - IMPlatform, - IMPlatform.id == BindUser.platform_id, + IMApplication, + IMApplication.id == BindUser.application_id, ) .filter( - IMPlatform.team_id == team_id, - IMPlatform.status == 0, + IMApplication.team_id == team_id, + IMApplication.status == 0, BindUser.status == 0, ) ) diff --git a/server/routes/team.py b/server/routes/team.py index 13f72ff7..68ce9b8b 100644 --- a/server/routes/team.py +++ b/server/routes/team.py @@ -1,8 +1,8 @@ from app import app from flask import Blueprint, abort, jsonify, redirect, request, session from model.team import ( + get_application_info_by_team_id, get_im_user_by_team_id, - get_platform_info_by_team_id, get_team_by_id, get_team_list_by_user_id, get_team_member, @@ -29,15 +29,15 @@ def get_team_list(): @authenticated def get_team_detail(team_id): team = get_team_by_id(team_id, session["user_id"]) - code_platform, im_platform = get_platform_info_by_team_id(team_id) + code_application, im_application = get_application_info_by_team_id(team_id) return jsonify( { "code": 0, "msg": "success", "data": { "team": team, - "code_platform": code_platform, - "im_platform": im_platform, + "code_application": code_application, + "im_application": im_application, }, } )