-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updated welcome landing page * fixed test and linting * linting * addressing comments * fix test * fix test * remove unneeded var * add magic comments
- Loading branch information
1 parent
56f6515
commit 11ea83e
Showing
7 changed files
with
158 additions
and
84 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
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,67 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
from __future__ import unicode_literals | ||
|
||
from collections import defaultdict | ||
|
||
from flask import g | ||
from flask_appbuilder.security.sqla import models as ab_models | ||
|
||
from superset import db | ||
|
||
|
||
def bootstrap_user_data(username=None, include_perms=False): | ||
if username: | ||
username = username | ||
else: | ||
username = g.user.username | ||
|
||
user = ( | ||
db.session.query(ab_models.User) | ||
.filter_by(username=username) | ||
.one() | ||
) | ||
|
||
payload = { | ||
'username': user.username, | ||
'firstName': user.first_name, | ||
'lastName': user.last_name, | ||
'userId': user.id, | ||
'isActive': user.is_active(), | ||
'createdOn': user.created_on.isoformat(), | ||
'email': user.email, | ||
} | ||
|
||
if include_perms: | ||
roles, permissions = get_permissions(user) | ||
payload['roles'] = roles | ||
payload['permissions'] = permissions | ||
|
||
return payload | ||
|
||
|
||
def get_permissions(user): | ||
if not user.roles: | ||
raise AttributeError('User object does not have roles') | ||
|
||
roles = {} | ||
permissions = defaultdict(set) | ||
for role in user.roles: | ||
perms = set() | ||
for perm in role.permissions: | ||
if perm.permission and perm.view_menu: | ||
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 | ||
if perm.permission and perm.view_menu | ||
] | ||
|
||
return roles, permissions |