Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow dataset owners to see their datasets #20135

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions superset/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,10 +620,19 @@ def apply(self, query: Query, value: Any) -> Query:
return query
datasource_perms = security_manager.user_view_menu_names("datasource_access")
schema_perms = security_manager.user_view_menu_names("schema_access")
owner_ids_query = (
db.session.query(models.SqlaTable.id)
.join(models.SqlaTable.owners)
.filter(
security_manager.user_model.id
== security_manager.user_model.get_user_id()
)
)
return query.filter(
or_(
self.model.perm.in_(datasource_perms),
self.model.schema_perm.in_(schema_perms),
models.SqlaTable.id.in_(owner_ids_query),
)
)

Expand Down
21 changes: 21 additions & 0 deletions tests/integration_tests/datasets/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,27 @@ def test_get_dataset_list_gamma(self):
response = json.loads(rv.data.decode("utf-8"))
assert response["result"] == []

def test_get_dataset_list_gamma_owned(self):
"""
Dataset API: Test get dataset list owned by gamma
"""
main_db = get_main_database()
owned_dataset = self.insert_dataset(
"ab_user", [self.get_user("gamma").id], main_db
)

self.login(username="gamma")
uri = "api/v1/dataset/"
rv = self.get_assert_metric(uri, "get_list")
assert rv.status_code == 200
response = json.loads(rv.data.decode("utf-8"))

assert response["count"] == 1
assert response["result"][0]["table_name"] == "ab_user"

db.session.delete(owned_dataset)
db.session.commit()

def test_get_dataset_related_database_gamma(self):
"""
Dataset API: Test get dataset related databases gamma
Expand Down