sha174n commented on code in PR #40333:
URL: https://github.com/apache/superset/pull/40333#discussion_r3293543707


##########
superset/commands/tag/create.py:
##########
@@ -60,9 +60,27 @@ def validate(self) -> None:
             exceptions.append(
                 TagCreateFailedError(f"invalid object type 
{self._object_type}")
             )
+
+        # Validate user has access to the target object
+        if object_type:
+            self._validate_object_access(object_type, self._object_id, 
exceptions)
+
         if exceptions:
             raise TagInvalidError(exceptions=exceptions)
 
+    def _validate_object_access(
+        self, object_type: ObjectType, object_id: int, exceptions: list[Any]
+    ) -> None:
+        """Validate that the current user has access to the target object."""
+        try:
+            target_object = to_object_model(object_type, object_id)
+            if target_object and hasattr(target_object, "raise_for_access"):
+                target_object.raise_for_access()

Review Comment:
   Addressed in prior commits — `hasattr` gate replaced with explicit 
per-object `security_manager.raise_for_access(dashboard=..., chart=..., 
query=..., dataset=...)` calls; unsupported types append an error.



##########
superset/commands/tag/delete.py:
##########
@@ -85,6 +90,21 @@ def validate(self) -> None:
         if exceptions:
             raise TagInvalidError(exceptions=exceptions)
 
+    def _validate_object_access(
+        self, object_type: ObjectType, object_id: int, exceptions: list[Any]
+    ) -> None:
+        """Validate that the current user has access to the target object."""
+        try:
+            target_object = to_object_model(object_type, object_id)
+            if target_object and hasattr(target_object, "raise_for_access"):
+                target_object.raise_for_access()

Review Comment:
   Addressed in prior commits — `hasattr` gate replaced with explicit 
per-object `security_manager.raise_for_access(dashboard=..., chart=..., 
query=..., dataset=...)` calls; unsupported types append an error.



##########
superset/commands/tag/create.py:
##########
@@ -60,9 +60,27 @@ def validate(self) -> None:
             exceptions.append(
                 TagCreateFailedError(f"invalid object type 
{self._object_type}")
             )
+
+        # Validate user has access to the target object
+        if object_type:
+            self._validate_object_access(object_type, self._object_id, 
exceptions)
+
         if exceptions:
             raise TagInvalidError(exceptions=exceptions)
 
+    def _validate_object_access(
+        self, object_type: ObjectType, object_id: int, exceptions: list[Any]
+    ) -> None:
+        """Validate that the current user has access to the target object."""
+        try:
+            target_object = to_object_model(object_type, object_id)
+            if target_object and hasattr(target_object, "raise_for_access"):

Review Comment:
   Addressed in prior commits — `to_object_model` now handles 
`ObjectType.dataset` (lazy-imported `DatasetDAO` to avoid circular import), and 
`_validate_object_access` calls `raise_for_access(datasource=...)` for datasets.



-- 
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]

Reply via email to