-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue: #1089 To achieve multi-tenancy: 1. set "ENABLE_MULTI_TENANCY = True" in superset_config file. 2. add column tenant_id String(256) in the tables or views in which you want multi-tenancy. 3. if you are adding the multi-tenancy in existing project then make sure that ab_user table have the column tenant_id else alter the table. 4. if you want to enable multi-tenancy with CUSTOM_SECURITY_MANAGER, then your custom security manager class should be a subclass of MultiTenantSecurityManager class. Added the documentation for multi-tenancy. Fixed few typing errors. Also remove tenant_id from user view. Fixes few test cases and role update api to support the custom user model.
- Loading branch information
Mayank Thakur
committed
Oct 27, 2017
1 parent
cbd0107
commit 5a063f3
Showing
11 changed files
with
107 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,3 +37,4 @@ superset/assets/version_info.json | |
|
||
# IntelliJ | ||
*.iml | ||
venv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from flask_appbuilder.security.sqla.manager import SecurityManager | ||
from flask_appbuilder.security.sqla.models import User | ||
from sqlalchemy import Column, Integer, ForeignKey, String, Sequence, Table | ||
from sqlalchemy.orm import relationship, backref | ||
from flask_appbuilder import Model | ||
from flask_appbuilder.security.views import UserDBModelView | ||
from flask_babel import lazy_gettext | ||
|
||
class MultiTenantUser(User): | ||
tenant_id = Column(String(256)) | ||
|
||
class MultiTenantUserDBModelView(UserDBModelView): | ||
show_fieldsets = [ | ||
(lazy_gettext('User info'), | ||
{'fields': ['username', 'active', 'roles', 'login_count', 'tenant_id']}), | ||
(lazy_gettext('Personal Info'), | ||
{'fields': ['first_name', 'last_name', 'email'], 'expanded': True}), | ||
(lazy_gettext('Audit Info'), | ||
{'fields': ['last_login', 'fail_login_count', 'created_on', | ||
'created_by', 'changed_on', 'changed_by'], 'expanded': False}), | ||
] | ||
|
||
user_show_fieldsets = [ | ||
(lazy_gettext('User info'), | ||
{'fields': ['username', 'active', 'roles', 'login_count']}), | ||
(lazy_gettext('Personal Info'), | ||
{'fields': ['first_name', 'last_name', 'email'], 'expanded': True}), | ||
] | ||
|
||
add_columns = ['first_name', 'last_name', 'username', 'active', 'email', 'roles', 'tenant_id', 'password', 'conf_password'] | ||
list_columns = ['first_name', 'last_name', 'username', 'email', 'active', 'roles'] | ||
edit_columns = ['first_name', 'last_name', 'username', 'active', 'email', 'roles', 'tenant_id'] | ||
|
||
# This will add multi tenant support in user model | ||
class MultiTenantSecurityManager(SecurityManager): | ||
user_model = MultiTenantUser | ||
userdbmodelview = MultiTenantUserDBModelView |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters