Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove platform schema #10

Merged
merged 5 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 12 additions & 45 deletions server/model/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="头像")
Expand All @@ -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="描述")
Expand All @@ -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"),
Expand All @@ -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"),
Expand All @@ -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(
Expand Down Expand Up @@ -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")
Expand Down
27 changes: 20 additions & 7 deletions server/model/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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,
)
)
Expand Down
8 changes: 4 additions & 4 deletions server/routes/team.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
},
}
)
Expand Down