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
653259c8
Commit
653259c8
authored
Feb 02, 2024
by
crazywoola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add db transaction
parent
7e87a528
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
12 deletions
+18
-12
account_service.py
api/services/account_service.py
+18
-12
No files found.
api/services/account_service.py
View file @
653259c8
...
...
@@ -24,6 +24,7 @@ from services.errors.account import (AccountAlreadyInTenantError, AccountLoginEr
from
sqlalchemy
import
func
from
tasks.mail_invite_member_task
import
send_invite_member_mail_task
from
werkzeug.exceptions
import
Forbidden
from
sqlalchemy
import
exc
def
_create_tenant_for_account
(
account
)
->
Tenant
:
...
...
@@ -257,18 +258,23 @@ class TenantService:
def
switch_tenant
(
account
:
Account
,
tenant_id
:
int
=
None
)
->
None
:
"""Switch the current workspace for the account"""
tenant_account_join
=
TenantAccountJoin
.
query
.
filter_by
(
account_id
=
account
.
id
,
tenant_id
=
tenant_id
)
.
first
()
TenantAccountJoin
.
query
.
filter_by
(
account_id
=
account
.
id
)
.
update
({
'current'
:
False
})
# Check if the tenant exists and the account is a member of the tenant
if
not
tenant_account_join
:
raise
AccountNotLinkTenantError
(
"Tenant not found or account is not a member of the tenant."
)
else
:
tenant_account_join
.
current
=
True
db
.
session
.
commit
()
# Set the current tenant for the account
account
.
current_tenant_id
=
tenant_account_join
.
tenant_id
with
db
.
session
.
begin
():
try
:
tenant_account_join
=
TenantAccountJoin
.
query
.
filter_by
(
account_id
=
account
.
id
,
tenant_id
=
tenant_id
)
.
first
()
TenantAccountJoin
.
query
.
filter_by
(
account_id
=
account
.
id
)
.
update
({
'current'
:
False
})
# Check if the tenant exists and the account is a member of the tenant
if
not
tenant_account_join
:
raise
AccountNotLinkTenantError
(
"Tenant not found or account is not a member of the tenant."
)
else
:
tenant_account_join
.
current
=
True
db
.
session
.
commit
()
# Set the current tenant for the account
account
.
current_tenant_id
=
tenant_account_join
.
tenant_id
except
exc
.
SQLAlchemyError
:
db
.
session
.
rollback
()
raise
@
staticmethod
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