fix activedomain
This commit is contained in:
@@ -368,21 +368,21 @@ async def userdomain_delete(
|
|||||||
|
|
||||||
@r.get(
|
@r.get(
|
||||||
"/activedomain",
|
"/activedomain",
|
||||||
response_model=ApiReturnModel[Domain],
|
response_model=ApiReturnModel[ActiveDomain|None],
|
||||||
response_model_exclude_none=True,
|
response_model_exclude_none=True,
|
||||||
)
|
)
|
||||||
async def get_useractivedomain(
|
async def get_activeuserdomain(
|
||||||
request: Request,
|
request: Request,
|
||||||
userId: Optional[int] = Query(None, alias="userId"),
|
|
||||||
user=Depends(get_current_active_user),
|
user=Depends(get_current_active_user),
|
||||||
db=Depends(get_db),
|
db=Depends(get_db),
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
# domain = get_activedomain(db, user.id)
|
# domain = get_activedomain(db, user.id)
|
||||||
domain = get_activedomain(db, userId if userId is not None else user.id)
|
domain = get_activedomain(db, user.id)
|
||||||
# if domain is None:
|
# if domain is None:
|
||||||
# return JSONResponse(content=None,status_code=HTTPStatus.OK)
|
# return JSONResponse(content=None,status_code=HTTPStatus.OK)
|
||||||
return ApiReturnModel(data =domain)
|
return ApiReturnModel(data = domain)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise APIException('platform:activedomain',request.url._url,f"Error occurred while get user({user.id}) activedomain:",e)
|
raise APIException('platform:activedomain',request.url._url,f"Error occurred while get user({user.id}) activedomain:",e)
|
||||||
|
|
||||||
|
|||||||
@@ -371,14 +371,15 @@ def active_userdomain(db: Session, userid: int,domainid: int):
|
|||||||
db.commit()
|
db.commit()
|
||||||
return db_userdomains
|
return db_userdomains
|
||||||
|
|
||||||
def get_activedomain(db: Session, userid: int)-> t.Optional[models.Domain]:
|
def get_activedomain(db: Session, userid: int):
|
||||||
user_domains = (db.query(models.Domain,models.UserDomain.active)
|
# user_domains = (db.query(models.Domain,models.UserDomain.active)
|
||||||
.join(models.UserDomain,models.UserDomain.domainid == models.Domain.id )
|
# .join(models.UserDomain,models.UserDomain.domainid == models.Domain.id )
|
||||||
.filter(models.UserDomain.userid == userid)
|
# .filter(models.UserDomain.userid == userid)
|
||||||
.all())
|
# .all())
|
||||||
db_domain=None
|
db_domain=(db.query(models.Domain).filter(models.Domain.is_active)
|
||||||
if len(user_domains)==1:
|
.join(models.UserDomain,models.UserDomain.domainid == models.Domain.id).filter(and_(models.UserDomain.active,models.UserDomain.userid == userid)).first())
|
||||||
db_domain = user_domains[0][0];
|
# if len(user_domains)==1:
|
||||||
|
# db_domain = user_domains[0][0];
|
||||||
# else:
|
# else:
|
||||||
# db_domain = next((domain for domain,active in user_domains if active),None)
|
# db_domain = next((domain for domain,active in user_domains if active),None)
|
||||||
# raise HTTPException(status.HTTP_404_NOT_FOUND, detail="Domain not found")
|
# raise HTTPException(status.HTTP_404_NOT_FOUND, detail="Domain not found")
|
||||||
|
|||||||
@@ -157,6 +157,13 @@ class DomainIn(BaseModel):
|
|||||||
encrypted_pwd = chacha20Encrypt(self.kintonepwd)
|
encrypted_pwd = chacha20Encrypt(self.kintonepwd)
|
||||||
self.kintonepwd = encrypted_pwd
|
self.kintonepwd = encrypted_pwd
|
||||||
|
|
||||||
|
class ActiveDomain(BaseModel):
|
||||||
|
id: int
|
||||||
|
tenantid: str
|
||||||
|
name: str
|
||||||
|
url: str
|
||||||
|
is_active: bool
|
||||||
|
|
||||||
class Domain(Base):
|
class Domain(Base):
|
||||||
id: int
|
id: int
|
||||||
tenantid: str
|
tenantid: str
|
||||||
|
|||||||
Reference in New Issue
Block a user