You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2022/07/05 18:11:55 UTC

[GitHub] [superset] john-bodley commented on a diff in pull request #20499: fix: Refactor ownership checks

john-bodley commented on code in PR #20499:
URL: https://github.com/apache/superset/pull/20499#discussion_r914066443


##########
superset/security/manager.py:
##########
@@ -1469,3 +1467,63 @@ def has_guest_access(self, dashboard: "Dashboard") -> bool:
             if str(resource["id"]) == str(dashboard.embedded[0].uuid):
                 return True
         return False
+
+    def raise_for_ownership(self, resource: Model) -> None:
+        """
+        Raise an exception if the user does not own the resource.
+
+        Note admins are deemed owners of all resources.
+
+        :param resource: The dashboard, dataste, chart, etc. resource
+        :raises SupersetSecurityException: If the current user is not an owner
+        """
+
+        if self.is_admin():
+            return
+
+        # Set of wners that works across ORM models.
+        owners: List[User] = []
+
+        if hasattr(resource, "owners"):
+            owners += resource.owners
+
+        if hasattr(resource, "owner"):
+            owners.append(resource.owner)
+
+        if hasattr(resource, "created_by"):
+            owners.append(resource.created_by)

Review Comment:
   @eschutho apologies for the delay in responding as I was away on PTO. I think the point you raise is a good call and I'll revert the logic. 
   
   As a side note I _think_ a lot of the `pre_update` logic is possibly obsolete with the DAO model—which merely complicates the code base—and we likely could deprecate some of that. I'm planning on authoring another PR to address said issue.



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org