kgabryje commented on code in PR #37900:
URL: https://github.com/apache/superset/pull/37900#discussion_r2794537611
##########
superset/tasks/filters.py:
##########
@@ -26,87 +26,41 @@
class TaskFilter(BaseFilter): # pylint: disable=too-few-public-methods
"""
- Filter for Task that shows tasks based on scope and user permissions.
+ Filter for Task that shows tasks based on user subscriptions.
- Filtering rules:
- - Admins: See all tasks (private, shared, system)
- - Non-admins:
- - Private tasks: Only their own tasks
- - Shared tasks: Tasks they're subscribed to
- - System tasks: None (admin-only)
+ Non-admins only see tasks they're subscribed to. Task creators are
+ automatically subscribed when creating a task, so this covers both
+ owned and shared tasks. Unsubscribing removes visibility.
+
+ Admins see all tasks without filtering.
"""
def apply(self, query: Query, value: Any) -> Query:
"""Apply the filter to the query."""
- from flask import g, has_request_context
- from sqlalchemy import or_
+ from sqlalchemy import and_, select
- from superset import db, security_manager
+ from superset import security_manager
from superset.models.task_subscribers import TaskSubscriber
from superset.models.tasks import Task
- # If no request context or no user, return unfiltered query
- # (this handles background tasks and system operations)
- if not has_request_context() or not hasattr(g, "user"):
+ # If user is admin or no user_id, return unfiltered query.
+ # This typically applies to background tasks and system operations
+ user_id = get_user_id()
+ if not user_id or security_manager.is_admin():
return query
- # If user is admin, return unfiltered query
if security_manager.is_admin():
Review Comment:
I think the check above makes this one redundant/unreachable?
--
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]