korbit-ai[bot] commented on code in PR #33684: URL: https://github.com/apache/superset/pull/33684#discussion_r2125848569
########## superset/migrations/versions/2025-06-03_11-16_a604d8ec3411_add_roles_to_charts.py: ########## @@ -0,0 +1,47 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""add_roles_to_charts + +Revision ID: a604d8ec3411 +Revises: f1edd4a4d4f2 +Create Date: 2025-06-03 11:16:34.432416 + +""" + +# revision identifiers, used by Alembic. +revision = 'a604d8ec3411' +down_revision = 'f1edd4a4d4f2' + +import sqlalchemy as sa +from alembic import op +from superset.migrations.shared.utils import create_table + + +def upgrade(): + create_table( + "slice_roles", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("role_id", sa.Integer(), nullable=False), + sa.Column("slice_id", sa.Integer(), nullable=True), Review Comment: ### Nullable Foreign Key in Role Assignment Table <sub></sub> <details> <summary>Tell me more</summary> ###### What is the issue? The slice_id column is nullable in a relationship table where it should be required. ###### Why this matters Allowing null values for slice_id could lead to orphaned role assignments and compromise the referential integrity of the role-based access control system. ###### Suggested change ∙ *Feature Preview* Make the slice_id column non-nullable: ```python sa.Column("slice_id", sa.Integer(), nullable=False) ``` ###### Provide feedback to improve future suggestions [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/9a1cea09-f534-4e63-a082-69321f005596/upvote) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/9a1cea09-f534-4e63-a082-69321f005596?what_not_true=true) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/9a1cea09-f534-4e63-a082-69321f005596?what_out_of_scope=true) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/9a1cea09-f534-4e63-a082-69321f005596?what_not_in_standard=true) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/9a1cea09-f534-4e63-a082-69321f005596) </details> <sub> 💬 Looking for more details? Reply to this comment to chat with Korbit. </sub> <!--- korbi internal id:5d394f18-64df-445e-82eb-6bd4a80cc0bd --> [](5d394f18-64df-445e-82eb-6bd4a80cc0bd) ########## superset/charts/filters.py: ########## @@ -101,15 +102,50 @@ def apply(self, query: Query, value: Any) -> Query: class ChartFilter(BaseFilter): # pylint: disable=too-few-public-methods def apply(self, query: Query, value: Any) -> Query: - if security_manager.can_access_all_datasources(): + if security_manager.is_admin(): return query + # is_rbac_disabled_filter = [] + # is_rbac_disabled_filter.append(~(Slice.roles.any())) + + datasource_perm_query = ( + db.session.query(Slice.id) + .join(SqlaTable, Slice.datasource_id == SqlaTable.id) + .join(Database, SqlaTable.database_id == Database.id) + .filter( + and_( + ~(Slice.roles.any()), + get_dataset_access_filters( + Slice, + security_manager.can_access_all_datasources(), + ), Review Comment: ### Invalid Parameters in Dataset Access Filter <sub></sub> <details> <summary>Tell me more</summary> ###### What is the issue? The get_dataset_access_filters function is called with incorrect parameters. It expects a model class and a query as arguments, but is being passed a boolean as the second argument. ###### Why this matters This will likely cause a runtime error when the filter is applied, breaking the chart access control functionality for non-role-based access. ###### Suggested change ∙ *Feature Preview* Remove the incorrect second parameter and let the function handle the permission check internally: ```python get_dataset_access_filters(Slice) ``` ###### Provide feedback to improve future suggestions [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/7f9950d8-27c9-4a77-b627-e936ac9d0b12/upvote) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/7f9950d8-27c9-4a77-b627-e936ac9d0b12?what_not_true=true) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/7f9950d8-27c9-4a77-b627-e936ac9d0b12?what_out_of_scope=true) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/7f9950d8-27c9-4a77-b627-e936ac9d0b12?what_not_in_standard=true) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/7f9950d8-27c9-4a77-b627-e936ac9d0b12) </details> <sub> 💬 Looking for more details? Reply to this comment to chat with Korbit. </sub> <!--- korbi internal id:26757378-ae30-4858-81b1-d825e8f2713d --> [](26757378-ae30-4858-81b1-d825e8f2713d) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
