mirror of
https://github.com/langgenius/dify.git
synced 2026-04-28 20:17:29 +08:00
feat: support both code and id for access mode api
This commit is contained in:
parent
2cb36a5b70
commit
14ddb90525
@ -60,9 +60,12 @@ class InstalledAppsListApi(Resource):
|
|||||||
user_id = current_user.id
|
user_id = current_user.id
|
||||||
res = []
|
res = []
|
||||||
app_ids = [installed_app["app"].id for installed_app in installed_app_list]
|
app_ids = [installed_app["app"].id for installed_app in installed_app_list]
|
||||||
access_modes = EnterpriseService.WebAppAuth.batch_get_app_access_mode_by_id(app_ids)
|
webapp_settings = EnterpriseService.WebAppAuth.batch_get_app_access_mode_by_id(app_ids)
|
||||||
for installed_app in installed_app_list:
|
for installed_app in installed_app_list:
|
||||||
if access_modes.get(installed_app["app"].id).access_mode == "sso_verified":
|
webapp_setting = webapp_settings.get(installed_app["app"].id)
|
||||||
|
if not webapp_setting:
|
||||||
|
continue
|
||||||
|
if webapp_setting.access_mode == "sso_verified":
|
||||||
continue
|
continue
|
||||||
app_code = AppService.get_app_code_by_id(str(installed_app["app"].id))
|
app_code = AppService.get_app_code_by_id(str(installed_app["app"].id))
|
||||||
if EnterpriseService.WebAppAuth.is_user_allowed_to_access_webapp(
|
if EnterpriseService.WebAppAuth.is_user_allowed_to_access_webapp(
|
||||||
|
|||||||
@ -46,10 +46,18 @@ class AppMeta(WebApiResource):
|
|||||||
class AppAccessMode(Resource):
|
class AppAccessMode(Resource):
|
||||||
def get(self):
|
def get(self):
|
||||||
parser = reqparse.RequestParser()
|
parser = reqparse.RequestParser()
|
||||||
parser.add_argument("appId", type=str, required=True, location="args")
|
parser.add_argument("appId", type=str, required=False, location="args")
|
||||||
|
parser.add_argument("appCode", type=str, required=False, location="args")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
app_id = args["appId"]
|
app_id = args.get("appId")
|
||||||
|
if args.get("appCode"):
|
||||||
|
app_code = args["appCode"]
|
||||||
|
app_id = AppService.get_app_id_by_code(app_code)
|
||||||
|
|
||||||
|
if not app_id:
|
||||||
|
raise ValueError("appId or appCode must be provided")
|
||||||
|
|
||||||
res = EnterpriseService.WebAppAuth.get_app_access_mode_by_id(app_id)
|
res = EnterpriseService.WebAppAuth.get_app_access_mode_by_id(app_id)
|
||||||
|
|
||||||
return {"accessMode": res.access_mode}
|
return {"accessMode": res.access_mode}
|
||||||
|
|||||||
@ -395,3 +395,15 @@ class AppService:
|
|||||||
if not site:
|
if not site:
|
||||||
raise ValueError(f"App with id {app_id} not found")
|
raise ValueError(f"App with id {app_id} not found")
|
||||||
return str(site.code)
|
return str(site.code)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_app_id_by_code(app_code: str) -> str:
|
||||||
|
"""
|
||||||
|
Get app id by app code
|
||||||
|
:param app_code: app code
|
||||||
|
:return: app id
|
||||||
|
"""
|
||||||
|
site = db.session.query(Site).filter(Site.code == app_code).first()
|
||||||
|
if not site:
|
||||||
|
raise ValueError(f"App with code {app_code} not found")
|
||||||
|
return str(site.app_id)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user