|
2 | 2 | from typing import Any |
3 | 3 |
|
4 | 4 | from flask import current_app, g, has_request_context, request |
5 | | -from flask_login import user_logged_in # type: ignore |
6 | 5 | from flask_login.config import EXEMPT_METHODS # type: ignore |
7 | | -from werkzeug.exceptions import Unauthorized |
8 | 6 | from werkzeug.local import LocalProxy |
9 | 7 |
|
10 | 8 | from configs import dify_config |
11 | | -from extensions.ext_database import db |
12 | | -from models.account import Account, Tenant, TenantAccountJoin |
| 9 | +from models.account import Account |
13 | 10 | from models.model import EndUser |
14 | 11 |
|
15 | 12 | #: A proxy for the current user. If no user is logged in, this will be an |
@@ -53,36 +50,6 @@ def post(): |
53 | 50 |
|
54 | 51 | @wraps(func) |
55 | 52 | def decorated_view(*args, **kwargs): |
56 | | - auth_header = request.headers.get("Authorization") |
57 | | - if dify_config.ADMIN_API_KEY_ENABLE: |
58 | | - if auth_header: |
59 | | - if " " not in auth_header: |
60 | | - raise Unauthorized("Invalid Authorization header format. Expected 'Bearer <api-key>' format.") |
61 | | - auth_scheme, auth_token = auth_header.split(None, 1) |
62 | | - auth_scheme = auth_scheme.lower() |
63 | | - if auth_scheme != "bearer": |
64 | | - raise Unauthorized("Invalid Authorization header format. Expected 'Bearer <api-key>' format.") |
65 | | - |
66 | | - admin_api_key = dify_config.ADMIN_API_KEY |
67 | | - if admin_api_key: |
68 | | - if admin_api_key == auth_token: |
69 | | - workspace_id = request.headers.get("X-WORKSPACE-ID") |
70 | | - if workspace_id: |
71 | | - tenant_account_join = ( |
72 | | - db.session.query(Tenant, TenantAccountJoin) |
73 | | - .filter(Tenant.id == workspace_id) |
74 | | - .filter(TenantAccountJoin.tenant_id == Tenant.id) |
75 | | - .filter(TenantAccountJoin.role == "owner") |
76 | | - .one_or_none() |
77 | | - ) |
78 | | - if tenant_account_join: |
79 | | - tenant, ta = tenant_account_join |
80 | | - account = db.session.query(Account).filter_by(id=ta.account_id).first() |
81 | | - # Login admin |
82 | | - if account: |
83 | | - account.current_tenant = tenant |
84 | | - current_app.login_manager._update_request_context_with_user(account) # type: ignore |
85 | | - user_logged_in.send(current_app._get_current_object(), user=_get_user()) # type: ignore |
86 | 53 | if request.method in EXEMPT_METHODS or dify_config.LOGIN_DISABLED: |
87 | 54 | pass |
88 | 55 | elif not current_user.is_authenticated: |
|
0 commit comments