Skip to content

Commit

Permalink
Disable user access request (apache#4405)
Browse files Browse the repository at this point in the history
* add feature flag to config

* wrap check around a feature flag

* add flag to the model view

* remove access request from seurity tests
  • Loading branch information
timifasubaa authored and mistercrunch committed Feb 14, 2018
1 parent 70e963b commit 9c26830
Show file tree
Hide file tree
Showing 5 changed files with 258 additions and 250 deletions.
3 changes: 3 additions & 0 deletions superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ class CeleryConfig(object):
# example: FLASK_APP_MUTATOR = lambda x: x.before_request = f
FLASK_APP_MUTATOR = None

# Set this to false if you don't want users to be able to request/grant
# datasource access requests from/to other users.
ENABLE_ACCESS_REQUEST = False

# smtp server configuration
EMAIL_NOTIFICATIONS = False # all the emails are sent using dryrun
Expand Down
63 changes: 32 additions & 31 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,30 +362,30 @@ class DatabaseTablesAsync(DatabaseView):
appbuilder.add_view_no_menu(DatabaseTablesAsync)


class AccessRequestsModelView(SupersetModelView, DeleteMixin):
datamodel = SQLAInterface(DAR)
list_columns = [
'username', 'user_roles', 'datasource_link',
'roles_with_datasource', 'created_on']
order_columns = ['created_on']
base_order = ('changed_on', 'desc')
label_columns = {
'username': _('User'),
'user_roles': _('User Roles'),
'database': _('Database URL'),
'datasource_link': _('Datasource'),
'roles_with_datasource': _('Roles to grant'),
'created_on': _('Created On'),
}

if config.get('ENABLE_ACCESS_REQUEST'):
class AccessRequestsModelView(SupersetModelView, DeleteMixin):
datamodel = SQLAInterface(DAR)
list_columns = [
'username', 'user_roles', 'datasource_link',
'roles_with_datasource', 'created_on']
order_columns = ['created_on']
base_order = ('changed_on', 'desc')
label_columns = {
'username': _('User'),
'user_roles': _('User Roles'),
'database': _('Database URL'),
'datasource_link': _('Datasource'),
'roles_with_datasource': _('Roles to grant'),
'created_on': _('Created On'),
}

appbuilder.add_view(
AccessRequestsModelView,
'Access requests',
label=__('Access requests'),
category='Security',
category_label=__('Security'),
icon='fa-table')
appbuilder.add_view(
AccessRequestsModelView,
'Access requests',
label=__('Access requests'),
category='Security',
category_label=__('Security'),
icon='fa-table')


class SliceModelView(SupersetModelView, DeleteMixin): # noqa
Expand Down Expand Up @@ -1964,14 +1964,15 @@ def dashboard(self, dashboard_id):
if datasource:
datasources.add(datasource)

for datasource in datasources:
if datasource and not self.datasource_access(datasource):
flash(
__(get_datasource_access_error_msg(datasource.name)),
'danger')
return redirect(
'superset/request_access/?'
'dashboard_id={dash.id}&'.format(**locals()))
if config.get('ENABLE_ACCESS_REQUEST'):
for datasource in datasources:
if datasource and not self.datasource_access(datasource):
flash(
__(get_datasource_access_error_msg(datasource.name)),
'danger')
return redirect(
'superset/request_access/?'
'dashboard_id={dash.id}&'.format(**locals()))

# Hack to log the dashboard_id properly, even when getting a slug
@log_this
Expand Down
Loading

0 comments on commit 9c26830

Please sign in to comment.