新增应用管理授权链接,授权公司

This commit is contained in:
18610128193
2026-06-10 16:37:43 +08:00
parent 488f0e082e
commit f46a0da040
5 changed files with 55 additions and 2 deletions
@@ -0,0 +1,31 @@
"""user_oauth表新增归属公司应用,新增授权链接字段
Revision ID: 6101ba8d5761
Revises: 9ac2212e1b8e
Create Date: 2026-06-10 16:34:38.842582
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '6101ba8d5761'
down_revision: Union[str, None] = '9ac2212e1b8e'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('user_oauth_app', sa.Column('auth_url', sa.String(length=256), nullable=True, comment='应用授权链接'))
op.add_column('user_oauth_app', sa.Column('company', sa.String(length=256), nullable=True, comment='应用归属公司名称'))
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('user_oauth_app', 'company')
op.drop_column('user_oauth_app', 'auth_url')
# ### end Alembic commands ###
+2 -2
View File
@@ -41,7 +41,7 @@ async def create_app(
db: AsyncSession = Depends(get_db),
):
try:
app = await create_user_oauth_app(db, req.app_id, req.secret, req.open_type, admin.id, req.count)
app = await create_user_oauth_app(db, req.app_id, req.secret, req.open_type, admin.id, req.count, req.auth_url, req.company)
return UserOAuthAppOut.model_validate(app)
except ValueError as e:
raise HTTPException(
@@ -72,7 +72,7 @@ async def update_app(
admin: User = Depends(get_admin_user),
db: AsyncSession = Depends(get_db),
):
app = await update_user_oauth_app(db, id, req.secret, req.open_type, req.status, req.count, admin.id)
app = await update_user_oauth_app(db, id, req.secret, req.open_type, req.status, req.count, req.auth_url, req.company, admin.id)
if not app:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
@@ -22,6 +22,12 @@ class UserOAuthApp(Base, TimestampMixin, SoftDeleteMixin):
count: Mapped[int] = mapped_column(
BigInteger, nullable=False, default=100, comment="应用最大可以授权多少个用户"
)
auth_url: Mapped[str] = mapped_column(
String(256), nullable=True, comment="应用授权链接"
)
company: Mapped[str] = mapped_column(
String(256), nullable=True, comment="应用归属公司名称"
)
open_type: Mapped[int] = mapped_column(
BigInteger, nullable=False, index=True, comment="开户方式(1=千川,2=广告,3=本地推,4=星图,5=快手代理商,6=巨量星图,7=巨量服务单,8=腾讯服务单,9=腾讯营销K2,10=腾讯营销K3)"
)
@@ -13,6 +13,8 @@ class UserOAuthAppCreate(BaseModel):
description="开户方式(1=千川,2=广告,3=本地推,4=星图,5=快手代理商,6=巨量星图,7=巨量服务单,8=腾讯服务单,9=腾讯营销K2,10=腾讯营销K3)",
)
count: int = Field(100, ge=1, description="应用最大可以授权多少个用户")
auth_url: str | None = Field(None, max_length=256, description="应用授权链接")
company: str | None = Field(None, max_length=256, description="应用归属公司名称")
class UserOAuthAppUpdate(BaseModel):
@@ -25,6 +27,8 @@ class UserOAuthAppUpdate(BaseModel):
)
status: int | None = Field(None, ge=1, le=2, description="应用状态(1=正常,2=禁用)")
count: int | None = Field(None, ge=1, description="应用最大可以授权多少个用户")
auth_url: str | None = Field(None, max_length=256, description="应用授权链接")
company: str | None = Field(None, max_length=256, description="应用归属公司名称")
class UserOAuthAppOut(BaseModel):
@@ -34,6 +38,8 @@ class UserOAuthAppOut(BaseModel):
status: int = Field(..., description="状态,1=正常,2=禁用")
count: int = Field(..., description="应用最大可以授权多少个用户")
open_type: int = Field(..., description="开户方式")
auth_url: str | None = Field(None, description="应用授权链接")
company: str | None = Field(None, description="应用归属公司名称")
create_by: str | None = Field(None, description="创建者")
created_at: NaiveDatetime = Field(..., description="创建时间")
updated_at: NaiveDatetime = Field(..., description="更新时间")
@@ -63,6 +63,8 @@ async def create_user_oauth_app(
open_type: int,
create_by: str | None = None,
count: int = 100,
auth_url: str | None = None,
company: str | None = None,
) -> UserOAuthApp:
existing = await get_user_oauth_app_by_app_id(db, app_id)
if existing:
@@ -74,6 +76,8 @@ async def create_user_oauth_app(
secret=secret,
open_type=open_type,
count=count,
auth_url=auth_url,
company=company,
create_by=create_by,
)
db.add(app)
@@ -90,6 +94,8 @@ async def update_user_oauth_app(
open_type: int | None = None,
status: int | None = None,
count: int | None = None,
auth_url: str | None = None,
company: str | None = None,
create_by: str | None = None,
) -> UserOAuthApp | None:
app = await get_user_oauth_app_by_id(db, id)
@@ -104,6 +110,10 @@ async def update_user_oauth_app(
app.status = status
if count is not None:
app.count = count
if auth_url is not None:
app.auth_url = auth_url
if company is not None:
app.company = company
if create_by is not None:
app.create_by = create_by