Skip to content

Commit

Permalink
fix(roles): Add SqlLabPermalinkRestApi as default sqlab roles. (apach…
Browse files Browse the repository at this point in the history
  • Loading branch information
LevisNgigi authored Feb 21, 2025
1 parent b06a9ed commit 2c37ddb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions superset/security/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ class SupersetSecurityManager( # pylint: disable=too-many-public-methods
("menu_access", "SQL Editor"),
("menu_access", "Saved Queries"),
("menu_access", "Query Search"),
("can_read", "SqlLabPermalinkRestApi"),
("can_write", "SqlLabPermalinkRestApi"),
}

SQLLAB_EXTRA_PERMISSION_VIEWS = {
Expand Down
2 changes: 2 additions & 0 deletions tests/integration_tests/security_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,8 @@ def test_sql_lab_permissions(self):
("menu_access", "Saved Queries"),
("menu_access", "SQL Editor"),
("menu_access", "SQL Lab"),
("can_read", "SqlLabPermalinkRestApi"),
("can_write", "SqlLabPermalinkRestApi"),
}

self.assert_cannot_alpha(sql_lab_set)
Expand Down
22 changes: 22 additions & 0 deletions tests/integration_tests/sql_lab/permalink/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,28 @@ def permalink_salt(app_context) -> Iterator[str]:
db.session.commit()


def test_sqllab_user_can_access_shared_query(
tab_state_data: dict[str, Any], permalink_salt: str, test_client, login_as
):
login_as(GAMMA_SQLLAB_USERNAME)

resp = test_client.post("api/v1/sqllab/permalink", json=tab_state_data)
assert resp.status_code == 201, "Failed to create permalink"

data = resp.json
key = data["key"]

resp = test_client.get(f"api/v1/sqllab/permalink/{key}")
assert resp.status_code == 200, "SQL Lab user access expected"

result = json.loads(resp.data.decode("utf-8"))
assert result == tab_state_data, "Query data mismatch"

id_ = decode_permalink_id(key, permalink_salt)
db.session.query(KeyValueEntry).filter_by(id=id_).delete()
db.session.commit()


def test_post(
tab_state_data: dict[str, Any], permalink_salt: str, test_client, login_as
):
Expand Down

0 comments on commit 2c37ddb

Please sign in to comment.