+24





![autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>](/assets/img/avatar_default.png)
![Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>](/assets/img/avatar_default.png)


-LAN-
GitHub
Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Yunlu Wen
Joel
GareArc
NFish
Davide Delbianco
minglu7
Ponder
crazywoola
gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
heyszt
Asuka Minato
Guangdong Liu
Eric Guo
NeatGuyCoding
XlKsyt
Dhruv Gorasiya
crazywoola
github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
lyzno1
hj24
GuanMu
非法操作
Copilot
Tonlo
Yusuke Yamada
Novice
kenwoodjw
Ademílson Tonato
znn
yangzheli
9a5f214623
Signed-off-by: NeatGuyCoding <[email protected]> Signed-off-by: lyzno1 <[email protected]> Signed-off-by: kenwoodjw <[email protected]> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Yunlu Wen <[email protected]> Co-authored-by: Joel <[email protected]> Co-authored-by: GareArc <[email protected]> Co-authored-by: NFish <[email protected]> Co-authored-by: Davide Delbianco <[email protected]> Co-authored-by: minglu7 <[email protected]> Co-authored-by: Ponder <[email protected]> Co-authored-by: crazywoola <[email protected]> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: heyszt <[email protected]> Co-authored-by: Asuka Minato <[email protected]> Co-authored-by: Guangdong Liu <[email protected]> Co-authored-by: Eric Guo <[email protected]> Co-authored-by: NeatGuyCoding <[email protected]> Co-authored-by: XlKsyt <[email protected]> Co-authored-by: Dhruv Gorasiya <[email protected]> Co-authored-by: crazywoola <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: lyzno1 <[email protected]> Co-authored-by: hj24 <[email protected]> Co-authored-by: GuanMu <[email protected]> Co-authored-by: 非法操作 <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: Tonlo <[email protected]> Co-authored-by: Yusuke Yamada <[email protected]> Co-authored-by: Novice <[email protected]> Co-authored-by: kenwoodjw <[email protected]> Co-authored-by: Ademílson Tonato <[email protected]> Co-authored-by: znn <[email protected]> Co-authored-by: yangzheli <[email protected]>
83 lines
2.7 KiB
Python
83 lines
2.7 KiB
Python
from collections.abc import Callable
|
|
from functools import wraps
|
|
from typing import Concatenate, ParamSpec, TypeVar
|
|
|
|
from flask_restx import Resource
|
|
from werkzeug.exceptions import NotFound
|
|
|
|
from controllers.console.explore.error import AppAccessDeniedError
|
|
from controllers.console.wraps import account_initialization_required
|
|
from extensions.ext_database import db
|
|
from libs.login import current_account_with_tenant, login_required
|
|
from models import InstalledApp
|
|
from services.enterprise.enterprise_service import EnterpriseService
|
|
from services.feature_service import FeatureService
|
|
|
|
P = ParamSpec("P")
|
|
R = TypeVar("R")
|
|
T = TypeVar("T")
|
|
|
|
|
|
def installed_app_required(view: Callable[Concatenate[InstalledApp, P], R] | None = None):
|
|
def decorator(view: Callable[Concatenate[InstalledApp, P], R]):
|
|
@wraps(view)
|
|
def decorated(installed_app_id: str, *args: P.args, **kwargs: P.kwargs):
|
|
_, current_tenant_id = current_account_with_tenant()
|
|
installed_app = (
|
|
db.session.query(InstalledApp)
|
|
.where(InstalledApp.id == str(installed_app_id), InstalledApp.tenant_id == current_tenant_id)
|
|
.first()
|
|
)
|
|
|
|
if installed_app is None:
|
|
raise NotFound("Installed app not found")
|
|
|
|
if not installed_app.app:
|
|
db.session.delete(installed_app)
|
|
db.session.commit()
|
|
|
|
raise NotFound("Installed app not found")
|
|
|
|
return view(installed_app, *args, **kwargs)
|
|
|
|
return decorated
|
|
|
|
if view:
|
|
return decorator(view)
|
|
return decorator
|
|
|
|
|
|
def user_allowed_to_access_app(view: Callable[Concatenate[InstalledApp, P], R] | None = None):
|
|
def decorator(view: Callable[Concatenate[InstalledApp, P], R]):
|
|
@wraps(view)
|
|
def decorated(installed_app: InstalledApp, *args: P.args, **kwargs: P.kwargs):
|
|
current_user, _ = current_account_with_tenant()
|
|
feature = FeatureService.get_system_features()
|
|
if feature.webapp_auth.enabled:
|
|
app_id = installed_app.app_id
|
|
res = EnterpriseService.WebAppAuth.is_user_allowed_to_access_webapp(
|
|
user_id=str(current_user.id),
|
|
app_id=app_id,
|
|
)
|
|
if not res:
|
|
raise AppAccessDeniedError()
|
|
|
|
return view(installed_app, *args, **kwargs)
|
|
|
|
return decorated
|
|
|
|
if view:
|
|
return decorator(view)
|
|
return decorator
|
|
|
|
|
|
class InstalledAppResource(Resource):
|
|
# must be reversed if there are multiple decorators
|
|
|
|
method_decorators = [
|
|
user_allowed_to_access_app,
|
|
installed_app_required,
|
|
account_initialization_required,
|
|
login_required,
|
|
]
|