Skip to content

Commit

Permalink
Address comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdan Kyryliuk committed Nov 29, 2016
1 parent e572047 commit 7979331
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
19 changes: 16 additions & 3 deletions superset/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,10 @@ def link(self):

@property
def schema_perm(self):
return "[{obj.database}].[{obj.schema}]".format(obj=self)
"""Returns schema permission if present, database one otherwise."""
if self.schema:
return "[{obj.database}].[{obj.schema}]".format(obj=self)
return self.database.perm

def get_perm(self):
return (
Expand Down Expand Up @@ -1630,10 +1633,20 @@ def num_cols(self):
def name(self):
return self.datasource_name

@property
def schema(self):
name_pieces = self.datasource_name.split('.')
if len(name_pieces) > 1:
return name_pieces[0]
else:
return None

@property
def schema_perm(self):
"""Is not used. Created for consistency with SqlaTable."""
return "[{obj.database}]".format(obj=self)
"""Returns schema permission if present, cluster one otherwise."""
if self.schema:
return "[{obj.database}].[{obj.schema}]".format(obj=self)
return self.cluster.perm

def get_perm(self):
return (
Expand Down
4 changes: 3 additions & 1 deletion superset/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ def sync_role_definitions():
for datasource in datasources:
perm = datasource.get_perm()
sm.add_permission_view_menu('datasource_access', perm)
sm.add_permission_view_menu('schema_access', datasource.schema_perm)
if datasource.schema:
sm.add_permission_view_menu(
'schema_access', datasource.schema_perm)
if perm != datasource.perm:
datasource.perm = perm

Expand Down

0 comments on commit 7979331

Please sign in to comment.