mirror of
https://github.com/langgenius/dify.git
synced 2026-05-13 08:57:28 +08:00
fix: api reformat
This commit is contained in:
parent
233e826778
commit
3b554dbac7
@ -65,9 +65,7 @@ class InstalledAppsListApi(Resource):
|
|||||||
):
|
):
|
||||||
res.append(installed_app)
|
res.append(installed_app)
|
||||||
installed_app_list = res
|
installed_app_list = res
|
||||||
logging.info(
|
logging.info(f"installed_app_list: {installed_app_list}, user_id: {user_id}")
|
||||||
f"installed_app_list: {installed_app_list}, user_id: {user_id}"
|
|
||||||
)
|
|
||||||
|
|
||||||
installed_app_list.sort(
|
installed_app_list.sort(
|
||||||
key=lambda app: (
|
key=lambda app: (
|
||||||
|
|||||||
@ -70,6 +70,7 @@ def user_allowed_to_access_app(view=None):
|
|||||||
return view(installed_app, *args, **kwargs)
|
return view(installed_app, *args, **kwargs)
|
||||||
|
|
||||||
return decorated
|
return decorated
|
||||||
|
|
||||||
if view:
|
if view:
|
||||||
return decorator(view)
|
return decorator(view)
|
||||||
return decorator
|
return decorator
|
||||||
@ -78,4 +79,9 @@ def user_allowed_to_access_app(view=None):
|
|||||||
class InstalledAppResource(Resource):
|
class InstalledAppResource(Resource):
|
||||||
# must be reversed if there are multiple decorators
|
# must be reversed if there are multiple decorators
|
||||||
|
|
||||||
method_decorators = [user_allowed_to_access_app, installed_app_required, account_initialization_required, login_required]
|
method_decorators = [
|
||||||
|
user_allowed_to_access_app,
|
||||||
|
installed_app_required,
|
||||||
|
account_initialization_required,
|
||||||
|
login_required,
|
||||||
|
]
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
from flask import request
|
from flask import request
|
||||||
from flask_restful import Resource, reqparse
|
from flask_restful import Resource, reqparse
|
||||||
from jwt import InvalidTokenError # type: ignore
|
from jwt import InvalidTokenError # type: ignore
|
||||||
from web import api
|
|
||||||
from werkzeug.exceptions import BadRequest
|
from werkzeug.exceptions import BadRequest
|
||||||
|
|
||||||
import services
|
import services
|
||||||
from controllers.console.auth.error import EmailCodeError, EmailOrPasswordMismatchError, InvalidEmailError
|
from controllers.console.auth.error import EmailCodeError, EmailOrPasswordMismatchError, InvalidEmailError
|
||||||
from controllers.console.error import AccountBannedError, AccountNotFound
|
from controllers.console.error import AccountBannedError, AccountNotFound
|
||||||
from controllers.console.wraps import setup_required
|
from controllers.console.wraps import setup_required
|
||||||
|
from controllers.web import api
|
||||||
from libs.helper import email
|
from libs.helper import email
|
||||||
from libs.password import valid_password
|
from libs.password import valid_password
|
||||||
from services.account_service import AccountService
|
from services.account_service import AccountService
|
||||||
@ -119,3 +119,5 @@ api.add_resource(LoginApi, "/login")
|
|||||||
# api.add_resource(LogoutApi, "/logout")
|
# api.add_resource(LogoutApi, "/logout")
|
||||||
api.add_resource(EmailCodeLoginSendEmailApi, "/email-code-login")
|
api.add_resource(EmailCodeLoginSendEmailApi, "/email-code-login")
|
||||||
api.add_resource(EmailCodeLoginApi, "/email-code-login/validity")
|
api.add_resource(EmailCodeLoginApi, "/email-code-login/validity")
|
||||||
|
api.add_resource(EmailCodeLoginSendEmailApi, "/email-code-login")
|
||||||
|
api.add_resource(EmailCodeLoginApi, "/email-code-login/validity")
|
||||||
|
|||||||
@ -29,7 +29,7 @@ def validate_jwt_token(view=None):
|
|||||||
|
|
||||||
def decode_jwt_token():
|
def decode_jwt_token():
|
||||||
system_features = FeatureService.get_system_features()
|
system_features = FeatureService.get_system_features()
|
||||||
app_code = request.headers.get("X-App-Code")
|
app_code = str(request.headers.get("X-App-Code"))
|
||||||
try:
|
try:
|
||||||
auth_header = request.headers.get("Authorization")
|
auth_header = request.headers.get("Authorization")
|
||||||
if auth_header is None:
|
if auth_header is None:
|
||||||
@ -71,7 +71,7 @@ def decode_jwt_token():
|
|||||||
except Unauthorized as e:
|
except Unauthorized as e:
|
||||||
if system_features.webapp_auth.enabled:
|
if system_features.webapp_auth.enabled:
|
||||||
app_web_auth_enabled = (
|
app_web_auth_enabled = (
|
||||||
EnterpriseService.WebAppAuth.get_app_access_mode_by_code(app_code=app_code).access_mode != "public"
|
EnterpriseService.WebAppAuth.get_app_access_mode_by_code(app_code=str(app_code)).access_mode != "public"
|
||||||
)
|
)
|
||||||
if app_web_auth_enabled:
|
if app_web_auth_enabled:
|
||||||
raise WebAppAuthRequiredError()
|
raise WebAppAuthRequiredError()
|
||||||
|
|||||||
@ -932,9 +932,10 @@ class RegisterService:
|
|||||||
if open_id is not None and provider is not None:
|
if open_id is not None and provider is not None:
|
||||||
AccountService.link_account_integrate(provider, open_id, account)
|
AccountService.link_account_integrate(provider, open_id, account)
|
||||||
|
|
||||||
if (FeatureService.get_system_features().is_allow_create_workspace
|
if (
|
||||||
and create_workspace_required
|
FeatureService.get_system_features().is_allow_create_workspace
|
||||||
and FeatureService.get_system_features().license.workspaces.is_available()
|
and create_workspace_required
|
||||||
|
and FeatureService.get_system_features().license.workspaces.is_available()
|
||||||
):
|
):
|
||||||
tenant = TenantService.create_tenant(f"{account.name}'s Workspace")
|
tenant = TenantService.create_tenant(f"{account.name}'s Workspace")
|
||||||
TenantService.create_tenant_member(tenant, account, role="owner")
|
TenantService.create_tenant_member(tenant, account, role="owner")
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
from services.enterprise.base import EnterpriseRequest
|
from services.enterprise.base import EnterpriseRequest
|
||||||
@ -18,12 +17,12 @@ class EnterpriseService:
|
|||||||
return EnterpriseRequest.send_request("GET", "/info")
|
return EnterpriseRequest.send_request("GET", "/info")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_workspace_info(cls, tenant_id:str):
|
def get_workspace_info(cls, tenant_id: str):
|
||||||
return EnterpriseRequest.send_request("GET", f"/workspace/{tenant_id}/info")
|
return EnterpriseRequest.send_request("GET", f"/workspace/{tenant_id}/info")
|
||||||
|
|
||||||
class WebAppAuth:
|
class WebAppAuth:
|
||||||
@classmethod
|
@classmethod
|
||||||
def is_user_allowed_to_access_webapp(cls, user_id: str, app_code: str) -> bool:
|
def is_user_allowed_to_access_webapp(cls, user_id: str, app_code: str):
|
||||||
params = {"userId": user_id, "appCode": app_code}
|
params = {"userId": user_id, "appCode": app_code}
|
||||||
data = EnterpriseRequest.send_request("GET", "/webapp/permission", params=params)
|
data = EnterpriseRequest.send_request("GET", "/webapp/permission", params=params)
|
||||||
|
|
||||||
@ -70,7 +69,7 @@ class EnterpriseService:
|
|||||||
return WebAppSettings(**data)
|
return WebAppSettings(**data)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def update_app_access_mode(cls, app_id: str, access_mode: str) -> bool:
|
def update_app_access_mode(cls, app_id: str, access_mode: str):
|
||||||
if not app_id:
|
if not app_id:
|
||||||
raise ValueError("app_id must be provided.")
|
raise ValueError("app_id must be provided.")
|
||||||
if access_mode not in ["public", "private", "private_all"]:
|
if access_mode not in ["public", "private", "private_all"]:
|
||||||
|
|||||||
@ -89,7 +89,11 @@ class WebAppAuthService:
|
|||||||
@classmethod
|
@classmethod
|
||||||
def create_end_user(cls, app_code, email) -> EndUser:
|
def create_end_user(cls, app_code, email) -> EndUser:
|
||||||
site = db.session.query(Site).filter(Site.code == app_code).first()
|
site = db.session.query(Site).filter(Site.code == app_code).first()
|
||||||
|
if not site:
|
||||||
|
raise NotFound("Site not found.")
|
||||||
app_model = db.session.query(App).filter(App.id == site.app_id).first()
|
app_model = db.session.query(App).filter(App.id == site.app_id).first()
|
||||||
|
if not app_model:
|
||||||
|
raise NotFound("App not found.")
|
||||||
end_user = EndUser(
|
end_user = EndUser(
|
||||||
tenant_id=app_model.tenant_id,
|
tenant_id=app_model.tenant_id,
|
||||||
app_id=app_model.id,
|
app_id=app_model.id,
|
||||||
@ -119,7 +123,7 @@ class WebAppAuthService:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _get_account_jwt_token(cls, account: Account, site: Site, end_user_id: str) -> str:
|
def _get_account_jwt_token(cls, account: Account, site: Site, end_user_id: str) -> str:
|
||||||
exp_dt = datetime.now(UTC) + timedelta(hours=dify_config.WebAppSessionTimeoutInHours * 24)
|
exp_dt = datetime.now(UTC) + timedelta(hours=dify_config.ACCESS_TOKEN_EXPIRE_MINUTES * 24)
|
||||||
exp = int(exp_dt.timestamp())
|
exp = int(exp_dt.timestamp())
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user