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
fc7e4ac7
Unverified
Commit
fc7e4ac7
authored
Aug 11, 2023
by
Matri
Committed by
GitHub
Aug 11, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: automatically create tenant for user (#793)
parent
39933aeb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
3 deletions
+17
-3
app.py
api/app.py
+16
-2
login.py
api/controllers/console/auth/login.py
+1
-1
No files found.
api/app.py
View file @
fc7e4ac7
...
@@ -31,6 +31,7 @@ from config import Config, CloudEditionConfig
...
@@ -31,6 +31,7 @@ from config import Config, CloudEditionConfig
from
commands
import
register_commands
from
commands
import
register_commands
from
models.account
import
TenantAccountJoin
,
AccountStatus
from
models.account
import
TenantAccountJoin
,
AccountStatus
from
models.model
import
Account
,
EndUser
,
App
from
models.model
import
Account
,
EndUser
,
App
from
services.account_service
import
TenantService
import
warnings
import
warnings
warnings
.
simplefilter
(
"ignore"
,
ResourceWarning
)
warnings
.
simplefilter
(
"ignore"
,
ResourceWarning
)
...
@@ -89,6 +90,15 @@ def initialize_extensions(app):
...
@@ -89,6 +90,15 @@ def initialize_extensions(app):
ext_sentry
.
init_app
(
app
)
ext_sentry
.
init_app
(
app
)
def
_create_tenant_for_account
(
account
):
tenant
=
TenantService
.
create_tenant
(
f
"{account.name}'s Workspace"
)
TenantService
.
create_tenant_member
(
tenant
,
account
,
role
=
'owner'
)
account
.
current_tenant
=
tenant
return
tenant
# Flask-Login configuration
# Flask-Login configuration
@
login_manager
.
user_loader
@
login_manager
.
user_loader
def
load_user
(
user_id
):
def
load_user
(
user_id
):
...
@@ -119,7 +129,9 @@ def load_user(user_id):
...
@@ -119,7 +129,9 @@ def load_user(user_id):
if
tenant_account_join
:
if
tenant_account_join
:
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
else
:
_create_tenant_for_account
(
account
)
session
[
'workspace_id'
]
=
account
.
current_tenant_id
else
:
else
:
account
.
current_tenant_id
=
workspace_id
account
.
current_tenant_id
=
workspace_id
else
:
else
:
...
@@ -127,7 +139,9 @@ def load_user(user_id):
...
@@ -127,7 +139,9 @@ def load_user(user_id):
TenantAccountJoin
.
account_id
==
account
.
id
)
.
first
()
TenantAccountJoin
.
account_id
==
account
.
id
)
.
first
()
if
tenant_account_join
:
if
tenant_account_join
:
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
else
:
_create_tenant_for_account
(
account
)
session
[
'workspace_id'
]
=
account
.
current_tenant_id
account
.
last_active_at
=
datetime
.
utcnow
()
account
.
last_active_at
=
datetime
.
utcnow
()
db
.
session
.
commit
()
db
.
session
.
commit
()
...
...
api/controllers/console/auth/login.py
View file @
fc7e4ac7
...
@@ -35,7 +35,7 @@ class LoginApi(Resource):
...
@@ -35,7 +35,7 @@ class LoginApi(Resource):
try
:
try
:
TenantService
.
switch_tenant
(
account
)
TenantService
.
switch_tenant
(
account
)
except
Exception
:
except
Exception
:
raise
AccountNotLinkTenantError
(
"Account not link tenant"
)
pass
flask_login
.
login_user
(
account
,
remember
=
args
[
'remember_me'
])
flask_login
.
login_user
(
account
,
remember
=
args
[
'remember_me'
])
AccountService
.
update_last_login
(
account
,
request
)
AccountService
.
update_last_login
(
account
,
request
)
...
...
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