Skip to content

feat: Auto-switch to authorized workspace when accessing URL #12131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion api/controllers/console/app/wraps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from controllers.console.app.error import AppNotFoundError
from extensions.ext_database import db
from libs.login import current_user
from models import App, AppMode
from models import App, AppMode, Tenant, TenantAccountJoin


def get_app_model(view: Optional[Callable] = None, *, mode: Union[AppMode, list[AppMode], None] = None):
Expand All @@ -26,6 +26,31 @@ def decorated_view(*args, **kwargs):
.first()
)

if not app_model:
# If app not found in current tenant, check other workspaces
accessible_tenants = (
db.session.query(Tenant)
.join(TenantAccountJoin, TenantAccountJoin.tenant_id == Tenant.id)
.filter(TenantAccountJoin.account_id == current_user.id)
.all()
)

for tenant in accessible_tenants:
if tenant.id == current_user.current_tenant_id:
continue

app_model = (
db.session.query(App)
.filter(App.id == app_id, App.tenant_id == tenant.id, App.status == "normal")
.first()
)

if app_model:
# Found app in another tenant, switch to it
current_user.current_tenant_id = tenant.id
db.session.commit()
break

if not app_model:
raise AppNotFoundError()

Expand Down
Loading