Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
e3408156
Commit
e3408156
authored
Feb 01, 2024
by
crazywoola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: remove some session['workspace_id']
parent
d8672796
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
45 deletions
+15
-45
login.py
api/controllers/console/auth/login.py
+0
-1
account_service.py
api/services/account_service.py
+15
-44
No files found.
api/controllers/console/auth/login.py
View file @
e3408156
...
@@ -47,7 +47,6 @@ class LogoutApi(Resource):
...
@@ -47,7 +47,6 @@ class LogoutApi(Resource):
@
setup_required
@
setup_required
def
get
(
self
):
def
get
(
self
):
flask
.
session
.
pop
(
'workspace_id'
,
None
)
flask_login
.
logout_user
()
flask_login
.
logout_user
()
return
{
'result'
:
'success'
}
return
{
'result'
:
'success'
}
...
...
api/services/account_service.py
View file @
e3408156
...
@@ -39,54 +39,26 @@ class AccountService:
...
@@ -39,54 +39,26 @@ class AccountService:
@
staticmethod
@
staticmethod
def
load_user
(
user_id
:
str
)
->
Account
:
def
load_user
(
user_id
:
str
)
->
Account
:
# todo: used by flask_login
account
=
Account
.
query
.
filter_by
(
id
=
user_id
)
.
first
()
if
'.'
in
user_id
:
if
not
account
:
tenant_id
,
account_id
=
user_id
.
split
(
'.'
)
return
None
else
:
account_id
=
user_id
account
=
db
.
session
.
query
(
Account
)
.
filter
(
Account
.
id
==
account_id
)
.
first
()
if
account
:
if
account
.
status
==
AccountStatus
.
BANNED
.
value
or
account
.
status
==
AccountStatus
.
CLOSED
.
value
:
raise
Forbidden
(
'Account is banned or closed.'
)
workspace_id
=
session
.
get
(
'workspace_id'
)
if
workspace_id
:
tenant_account_join
=
db
.
session
.
query
(
TenantAccountJoin
)
.
filter
(
TenantAccountJoin
.
account_id
==
account
.
id
,
TenantAccountJoin
.
tenant_id
==
workspace_id
)
.
first
()
if
not
tenant_account_join
:
tenant_account_join
=
db
.
session
.
query
(
TenantAccountJoin
)
.
filter
(
TenantAccountJoin
.
account_id
==
account
.
id
)
.
first
()
if
tenant_account_join
:
account
.
current_tenant_id
=
tenant_account_join
.
tenant_id
else
:
_create_tenant_for_account
(
account
)
session
[
'workspace_id'
]
=
account
.
current_tenant_id
else
:
account
.
current_tenant_id
=
workspace_id
else
:
tenant_account_join
=
db
.
session
.
query
(
TenantAccountJoin
)
.
filter
(
TenantAccountJoin
.
account_id
==
account
.
id
)
.
first
()
if
tenant_account_join
:
account
.
current_tenant_id
=
tenant_account_join
.
tenant_id
else
:
_create_tenant_for_account
(
account
)
session
[
'workspace_id'
]
=
account
.
current_tenant_id
current_time
=
datetime
.
utcnow
()
if
account
.
status
in
[
AccountStatus
.
BANNED
.
value
,
AccountStatus
.
CLOSED
.
value
]:
raise
Forbidden
(
'Account is banned or closed.'
)
# update last_active_at when last_active_at is more than 10 minutes ago
tenant_account_join
=
TenantAccountJoin
.
query
.
filter_by
(
account_id
=
account
.
id
)
.
first
()
if
current_time
-
account
.
last_active_at
>
timedelta
(
minutes
=
10
):
if
not
tenant_account_join
:
account
.
last_active_at
=
current_time
_create_tenant_for_account
(
account
)
db
.
session
.
commit
()
else
:
account
.
current_tenant_id
=
tenant_account_join
.
tenant_id
# Update last_active_at if more than 10 minutes have passed
if
datetime
.
utcnow
()
-
account
.
last_active_at
>
timedelta
(
minutes
=
10
):
account
.
last_active_at
=
datetime
.
utcnow
()
db
.
session
.
commit
()
return
account
return
account
@
staticmethod
@
staticmethod
def
get_account_jwt_token
(
account
):
def
get_account_jwt_token
(
account
):
payload
=
{
payload
=
{
...
@@ -288,7 +260,6 @@ class TenantService:
...
@@ -288,7 +260,6 @@ class TenantService:
# Set the current tenant for the account
# Set the current tenant for the account
account
.
current_tenant_id
=
tenant_account_join
.
tenant_id
account
.
current_tenant_id
=
tenant_account_join
.
tenant_id
session
[
'workspace_id'
]
=
account
.
current_tenant
.
id
@
staticmethod
@
staticmethod
def
get_tenant_members
(
tenant
:
Tenant
)
->
List
[
Account
]:
def
get_tenant_members
(
tenant
:
Tenant
)
->
List
[
Account
]:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment