bito-code-review[bot] commented on code in PR #41897:
URL: https://github.com/apache/superset/pull/41897#discussion_r3547734116
##########
superset/subjects/filters.py:
##########
@@ -176,6 +176,28 @@ def apply(self, query: Query, value: Optional[Any]) ->
Query:
return _apply_subject_list_filters(query)
+class SubjectAllTextFilter(BaseFilter): # pylint:
disable=too-few-public-methods
+ """ILIKE search across a subject's textual columns.
+
+ Used by the Subject REST API ``search_filters`` for free-text search.
+ """
+
+ name = _("All Text")
+ arg_name = "subject_all_text"
+
+ def apply(self, query: Query, value: Any) -> Query:
+ if not value:
+ return query
+ ilike_value = f"%{value}%"
+ return query.filter(
+ or_(
+ Subject.label.ilike(ilike_value),
+ Subject.secondary_label.ilike(ilike_value),
+ Subject.extra_search.ilike(ilike_value),
+ )
+ )
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Bypasses required list filters</b></div>
<div id="fix">
The `SubjectAllTextFilter.apply()` bypasses `_apply_subject_list_filters()`
which is called by every other filter in this file (lines 127, 150, 153, 168,
176). This function applies `_apply_excluded_users()` and
`_apply_extra_related_query_filters()` — critical security and permission
filters. Users excluded from lists or filtered by `EXTRA_RELATED_QUERY_FILTERS`
will appear in SubjectAllTextFilter search results but would be absent from
other filter results, creating inconsistent access control. This is a
behavioral divergence from the established pattern.
</div>
</div>
<small><i>Code Review Run #def035</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
##########
superset/subjects/api.py:
##########
@@ -0,0 +1,123 @@
+# 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.
+import logging
+
+from flask_appbuilder.models.sqla.interface import SQLAInterface
+
+from superset.constants import RouteMethod
+from superset.subjects.filters import SubjectAllTextFilter
+from superset.subjects.models import Subject
+from superset.subjects.schemas import openapi_spec_methods_override
+from superset.views.base_api import BaseSupersetModelRestApi
+
+logger = logging.getLogger(__name__)
+
+
+class SubjectRestApi(BaseSupersetModelRestApi):
+ """Read-only API for fetching and filtering Subjects.
+
+ Subjects are an internal representation derived from Users, Roles, and
+ Groups, so this API only exposes read operations (list, get, info, related,
+ distinct). Access is gated by the ``Subject`` permission, which is granted
to
+ Admins by default.
+ """
+
+ datamodel = SQLAInterface(Subject)
+
+ include_route_methods = {
+ RouteMethod.GET,
+ RouteMethod.GET_LIST,
+ RouteMethod.INFO,
+ }
+ class_permission_name = "Subject"
+ method_permission_name = {
+ "get": "read",
+ "get_list": "read",
+ "info": "read",
+ }
+
+ resource_name = "subject"
+ allow_browser_login = True
+ openapi_spec_tag = "Subjects"
+ openapi_spec_methods = openapi_spec_methods_override
+
+ list_columns = [
+ "id",
+ "uuid",
+ "label",
+ "secondary_label",
+ "type",
+ "active",
+ "extra_search",
+ "img",
+ "user_id",
+ "role_id",
+ "group_id",
+ "created_on",
+ "changed_on",
+ "changed_by.first_name",
+ "changed_by.last_name",
+ ]
+ show_columns = [
+ "id",
+ "uuid",
+ "label",
+ "secondary_label",
+ "type",
+ "active",
+ "extra_search",
+ "img",
+ "user_id",
+ "role_id",
+ "group_id",
+ # Full principal detail — only the relationship matching ``type`` is
set
+ "user.id",
+ "user.username",
+ "user.first_name",
+ "user.last_name",
+ "user.email",
+ "user.active",
+ "role.id",
+ "role.name",
+ "group.id",
+ "group.name",
+ "group.label",
+ "group.description",
+ "created_on",
+ "changed_on",
+ "changed_by.first_name",
+ "changed_by.last_name",
+ ]
+ order_columns = [
+ "label",
+ "type",
+ "active",
+ "created_on",
+ "changed_on",
+ ]
+
+ search_columns = [
+ "label",
+ "secondary_label",
+ "extra_search",
+ "type",
+ "active",
+ "user_id",
+ "role_id",
+ "group_id",
+ ]
+ search_filters = {"label": [SubjectAllTextFilter]}
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Missing base_related_field_filters on related
endpoints</b></div>
<div id="fix">
The `/related/<column>` endpoint has no `base_related_field_filters` set, so
`FilterRelatedSubjects` (which wraps `_apply_subject_list_filters`) is never
applied. This means the related-field dropdowns will not respect
`SUBJECTS_RELATED_TYPES` config or the admin-exclusion settings that the rest
of the subjects module enforces. Import `FilterRelatedSubjects` from `.filters`
and wire it to the three relationship columns.
</div>
</div>
<small><i>Code Review Run #def035</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
##########
superset/subjects/api.py:
##########
@@ -0,0 +1,123 @@
+# 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.
+import logging
+
+from flask_appbuilder.models.sqla.interface import SQLAInterface
+
+from superset.constants import RouteMethod
+from superset.subjects.filters import SubjectAllTextFilter
+from superset.subjects.models import Subject
+from superset.subjects.schemas import openapi_spec_methods_override
+from superset.views.base_api import BaseSupersetModelRestApi
+
+logger = logging.getLogger(__name__)
+
+
+class SubjectRestApi(BaseSupersetModelRestApi):
+ """Read-only API for fetching and filtering Subjects.
+
+ Subjects are an internal representation derived from Users, Roles, and
+ Groups, so this API only exposes read operations (list, get, info, related,
+ distinct). Access is gated by the ``Subject`` permission, which is granted
to
+ Admins by default.
+ """
+
+ datamodel = SQLAInterface(Subject)
+
+ include_route_methods = {
+ RouteMethod.GET,
+ RouteMethod.GET_LIST,
+ RouteMethod.INFO,
+ }
+ class_permission_name = "Subject"
+ method_permission_name = {
+ "get": "read",
+ "get_list": "read",
+ "info": "read",
+ }
+
+ resource_name = "subject"
+ allow_browser_login = True
+ openapi_spec_tag = "Subjects"
+ openapi_spec_methods = openapi_spec_methods_override
+
+ list_columns = [
+ "id",
+ "uuid",
+ "label",
+ "secondary_label",
+ "type",
+ "active",
+ "extra_search",
+ "img",
+ "user_id",
+ "role_id",
+ "group_id",
+ "created_on",
+ "changed_on",
+ "changed_by.first_name",
+ "changed_by.last_name",
+ ]
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Missing allowed_rel_fields for relationship
columns</b></div>
<div id="fix">
Add `allowed_rel_fields = {"user", "role", "group"}` to the `SubjectRestApi`
class so that `/related/<column>` calls for user, role, and group do not return
404. Ensure to add this line after `order_columns`.
</div>
</div>
<small><i>Code Review Run #def035</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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]