-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc066d6
commit 2b71f13
Showing
13 changed files
with
200 additions
and
119 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
This document details changes that aren't fully backwards compatible. | ||
This doc is here to inform of change of behavior as well as | ||
to explain actions that may be required to take while upgrading. | ||
|
||
# 0.19.0 | ||
* We introduced `superset.security_manager.SupersetSecurityManager`, | ||
that derives `flask_appbuilder.security.sqla.manager.SecurityManager`. | ||
This derivation of FAB's SecurityManager was necessary in order to | ||
introduce new attributes to `SupersetUser` like the `image_url` surfaced | ||
in the profile page as well as in the new dashboard stats footer. | ||
|
||
Knowing that the authentication in FAB is implemented by deriving their | ||
`SecurityManager`, if you have your own auth setup in that way, you'll now | ||
have to derive `SupersetSecurityManager` instead. | ||
|
||
|
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
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,22 @@ | ||
"""empty message | ||
Revision ID: e58b53fc8605 | ||
Revises: ('cd8aba67c8b6', 'a65458420354') | ||
Create Date: 2017-06-17 10:17:40.227962 | ||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'e58b53fc8605' | ||
down_revision = ('cd8aba67c8b6', 'a65458420354') | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
def upgrade(): | ||
pass | ||
|
||
|
||
def downgrade(): | ||
pass |
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,73 @@ | ||
from collections import defaultdict | ||
|
||
from flask_appbuilder.models.sqla.interface import SQLAInterface | ||
from flask_appbuilder.security import views as fab_views | ||
from flask_appbuilder.security.sqla import models as ab_models | ||
from flask_appbuilder.security.sqla.manager import SecurityManager | ||
|
||
from sqlalchemy import Column, String | ||
|
||
|
||
class SupersetUser(ab_models.User): | ||
"""Deriving FAB's USER to enrich it""" | ||
image_url = Column(String(1000)) | ||
slack_username = Column(String(500)) | ||
|
||
@property | ||
def full_name(self): | ||
return self.first_name + ' ' + self.last_name | ||
|
||
@property | ||
def data(self): | ||
"""Returns a json-serializable representation of the self""" | ||
return { | ||
'id': self.id, | ||
'first_name': self.first_name, | ||
'last_name': self.last_name, | ||
'slack_username': self.slack_username, | ||
'email': self.email, | ||
'image_url': self.image_url, | ||
'username': self.username, | ||
'is_active': self.is_active(), | ||
'created_on': self.created_on.isoformat(), | ||
} | ||
|
||
@property | ||
def data_extended(self): | ||
"""Superset of data property with roles and perms""" | ||
d = self.data | ||
roles = {} | ||
permissions = defaultdict(set) | ||
for role in self.roles: | ||
perms = set() | ||
for perm in role.permissions: | ||
perms.add( | ||
(perm.permission.name, perm.view_menu.name) | ||
) | ||
if perm.permission.name in ( | ||
'datasource_access', 'database_access'): | ||
permissions[perm.permission.name].add(perm.view_menu.name) | ||
roles[role.name] = [ | ||
[perm.permission.name, perm.view_menu.name] | ||
for perm in role.permissions | ||
] | ||
d.update({ | ||
'roles': roles, | ||
'permissions': permissions, | ||
}) | ||
return d | ||
|
||
|
||
class SupersetUserModelView(fab_views.UserDBModelView): | ||
route_base = '/userext' | ||
datamodel = SQLAInterface(SupersetUser) | ||
edit_columns = fab_views.UserDBModelView.edit_columns + [ | ||
'image_url', 'slack_username'] | ||
add_columns = fab_views.UserDBModelView.add_columns + [ | ||
'image_url', 'slack_username'] | ||
fab_views.UserDBModelView = SupersetUserModelView | ||
|
||
|
||
class SupersetSecurityManager(SecurityManager): | ||
user_model = SupersetUser | ||
userdbmodelview = SupersetUserModelView |
Oops, something went wrong.