Skip to content

Commit

Permalink
Fix None view_menues in permissions. (#1409)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkyryliuk committed Oct 21, 2016
1 parent 62e0e19 commit 4f886d6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
24 changes: 15 additions & 9 deletions caravel/views.py
Expand Up @@ -1088,25 +1088,31 @@ def override_role_permissions(self):
for dbs in databases:
for schema in dbs['schema']:
for ds_name in schema['datasources']:
db_ds_names.add(utils.get_datasource_full_name(
dbs['name'], ds_name, schema=schema['name']))
fullname = utils.get_datasource_full_name(
dbs['name'], ds_name, schema=schema['name'])
db_ds_names.add(fullname)

existing_datasources = SourceRegistry.get_all_datasources(db.session)
datasources = [
d for d in existing_datasources if d.full_name in db_ds_names]

role = sm.find_role(role_name)
# remove all permissions
role.permissions = []
# grant permissions to the list of datasources
for ds_name in datasources:
role.permissions.append(
sm.find_permission_view_menu(
view_menu_name=ds_name.perm,
granted_perms = []
for datasource in datasources:
view_menu_perm = sm.find_permission_view_menu(
view_menu_name=datasource.perm,
permission_name='datasource_access')
)
# prevent creating empty permissions
if view_menu_perm and view_menu_perm.view_menu:
role.permissions.append(view_menu_perm)
granted_perms.append(view_menu_perm.view_menu.name)
db.session.commit()
return Response(status=201)
return Response(json.dumps({
'granted': granted_perms,
'requested': list(db_ds_names)
}), status=201)

@log_this
@has_access
Expand Down
1 change: 1 addition & 0 deletions tests/access_tests.py
Expand Up @@ -44,6 +44,7 @@
]
}


class RequestAccessTests(CaravelTestCase):

requires_examples = False
Expand Down

0 comments on commit 4f886d6

Please sign in to comment.