diff --git a/backend/app/api/api_v1/routers/platform.py b/backend/app/api/api_v1/routers/platform.py index 82fa504..5857c02 100644 --- a/backend/app/api/api_v1/routers/platform.py +++ b/backend/app/api/api_v1/routers/platform.py @@ -1,5 +1,7 @@ +from http import HTTPStatus from fastapi import Query, Request,Depends, APIRouter, UploadFile,HTTPException,File -from app.core.operation import log_operation +from fastapi.responses import JSONResponse +# from app.core.operation import log_operation from app.db import Base,engine from app.db.session import get_db from app.db.crud import * @@ -25,9 +27,9 @@ async def apps_list( db=Depends(get_db), ): try: - platformapps = get_apps(db) - domain = get_activedomain(db, user.id) + domain = get_activedomain(db, user.id) + platformapps = get_apps(db,domain.url) kintoneevn = config.KINTONE_ENV(domain) headers={config.API_V1_AUTH_KEY:kintoneevn.API_V1_AUTH_VALUE} url = f"{kintoneevn.BASE_URL}{config.API_V1_STR}/apps.json" @@ -44,17 +46,13 @@ async def apps_list( break offset += limit - tempapps = platformapps.copy() - for papp in tempapps: - exist = False - for kapp in all_apps: - if kapp['appId'] == papp.appid: - exist = True - break - if not exist: - platformapps.remove(papp) - - return platformapps + kintone_apps_dict = {app['appId']: app for app in all_apps} + filtered_apps = [] + for papp in platformapps: + if papp.appid in kintone_apps_dict: + papp.appname = kintone_apps_dict[papp.appid]["name"] + filtered_apps.append(papp) + return filtered_apps except Exception as e: raise APIException('platform:apps',request.url._url,f"Error occurred while get apps:",e) @@ -258,10 +256,11 @@ async def domain_details( async def domain_create( request: Request, domain: DomainBase, + user=Depends(get_current_user), db=Depends(get_db), ): try: - return create_domain(db, domain) + return create_domain(db, domain,user.id) except Exception as e: raise APIException('platform:domain',request.url._url,f"Error occurred while create domain:",e) @@ -354,8 +353,9 @@ async def get_useractivedomain( ): try: # domain = get_activedomain(db, user.id) - domain = get_activedomain(db, userId if userId is not None else user.id) + if domain is None: + return JSONResponse(content=None,status_code=HTTPStatus.OK) return domain except Exception as e: raise APIException('platform:activedomain',request.url._url,f"Error occurred while get user({user.id}) activedomain:",e) diff --git a/backend/app/db/crud.py b/backend/app/db/crud.py index 8970081..ebd19fb 100644 --- a/backend/app/db/crud.py +++ b/backend/app/db/crud.py @@ -70,9 +70,10 @@ def edit_user( return db_user def get_apps( - db: Session + db: Session, + domain_url:str ) -> t.List[schemas.AppList]: - return db.query(models.App).all() + return db.query(models.App).filter(models.App.domainurl == domain_url).all() def update_appversion(db: Session, appedit: schemas.AppVersion,userid:int): app = db.query(models.App).filter(and_(models.App.domainurl == appedit.domainurl,models.App.appid == appedit.appid)).first() @@ -223,7 +224,7 @@ def get_flows_by_app(db: Session,domainurl: str, appid: str): raise Exception("Data not found") return flows -def create_domain(db: Session, domain: schemas.DomainBase): +def create_domain(db: Session, domain: schemas.DomainBase,userid:int): domain.encrypt_kintonepwd() db_domain = models.Domain( tenantid = domain.tenantid, @@ -233,6 +234,8 @@ def create_domain(db: Session, domain: schemas.DomainBase): kintonepwd=domain.kintonepwd ) db.add(db_domain) + db.flush() + add_userdomain(db,userid,db_domain.id) db.commit() db.refresh(db_domain) return db_domain @@ -264,7 +267,13 @@ def edit_domain( db.refresh(db_domain) return db_domain -def add_userdomain(db: Session, userid:int,domainids:list[str]): + +def add_userdomain(db: Session, userid:int,domainid:int): + user_domain = models.UserDomain(userid = userid, domainid = domainid ) + db.add(user_domain) + return user_domain + +def add_userdomains(db: Session, userid:int,domainids:list[str]): dbCommits = list(map(lambda domainid: models.UserDomain(userid = userid, domainid = domainid ), domainids)) db.bulk_save_objects(dbCommits) db.commit() @@ -291,16 +300,23 @@ def active_userdomain(db: Session, userid: int,domainid: int): db.commit() return db_userdomains -def get_activedomain(db: Session, userid: int): - db_domain = db.query(models.Domain).join(models.UserDomain,models.UserDomain.domainid == models.Domain.id ).filter(and_(models.UserDomain.userid == userid,models.UserDomain.active == True)).first() - # if not db_domain: - # raise HTTPException(status.HTTP_404_NOT_FOUND, detail="Domain not found") +def get_activedomain(db: Session, userid: int)-> t.Optional[models.Domain]: + user_domains = (db.query(models.Domain,models.UserDomain.active) + .join(models.UserDomain,models.UserDomain.domainid == models.Domain.id ) + .filter(models.UserDomain.userid == userid) + .all()) + db_domain=None + if len(user_domains)==1: + db_domain = user_domains[0][0]; + else: + db_domain = next((domain for domain,active in user_domains if active),None) + # raise HTTPException(status.HTTP_404_NOT_FOUND, detail="Domain not found") return db_domain def get_domain(db: Session, userid: str): domains = db.query(models.Domain).join(models.UserDomain,models.UserDomain.domainid == models.Domain.id ).filter(models.UserDomain.userid == userid).all() - if not domains: - raise HTTPException(status_code=404, detail="Data not found") + # if not domains: + # raise HTTPException(status_code=404, detail="Data not found") # for domain in domains: # decrypted_pwd = chacha20Decrypt(domain.kintonepwd) # domain.kintonepwd = decrypted_pwd diff --git a/document/ALCKintone_20231012.drawio b/document/ALCKintone_20231012.drawio index cd65d9c..28bc9c3 100644 --- a/document/ALCKintone_20231012.drawio +++ b/document/ALCKintone_20231012.drawio @@ -1,4 +1,4 @@ - + @@ -134,7 +134,7 @@ - + @@ -552,15 +552,15 @@ - + - + - + @@ -578,28 +578,28 @@ - + - + - + - + - + - + @@ -978,217 +978,358 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -1215,7 +1356,7 @@ - + @@ -1268,9 +1409,17 @@ - + + + + + + + + + @@ -1301,15 +1450,7 @@ - - - - - - - - - + @@ -1349,7 +1490,7 @@ - + diff --git a/frontend/src/pages/AppManagement.vue b/frontend/src/pages/AppManagement.vue index bf2ed31..254efab 100644 --- a/frontend/src/pages/AppManagement.vue +++ b/frontend/src/pages/AppManagement.vue @@ -16,7 +16,13 @@ - +