Vitor-Avila commented on code in PR #32231:
URL: https://github.com/apache/superset/pull/32231#discussion_r1958837672


##########
superset/tasks/permissions.py:
##########
@@ -0,0 +1,56 @@
+# 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.
+from __future__ import annotations
+
+import logging
+
+from flask import current_app, g
+
+from superset import security_manager
+from superset.commands.database.resync_permissions import 
ResyncPermissionsCommand
+from superset.daos.database import DatabaseDAO
+from superset.extensions import celery_app
+
+logger = logging.getLogger(__name__)
+
+
+@celery_app.task(name="resync_database_permissions", soft_time_limit=600)
+def resync_database_permissions(
+    database_id: int, username: str, original_database_name: str
+) -> None:
+    logger.info("Resyncing permissions for DB connection ID %s", database_id)
+    with current_app.test_request_context():
+        try:
+            user = security_manager.get_user_by_username(username)
+            assert user
+            g.user = user

Review Comment:
   @korbit-ai
   This is the current flow for the async mode:
   
   ```
   API call triggers the Command -> the Command triggers the Celery task -> The 
Celery task calls the Command
   ```
   
   The `username` parameter is currently passed to the Celery task directly 
from the command. In the command, the `username` is retrieved from the `g` 
object directly (it's not arbitrarily passed by the user). Also, at the API 
layer there's a permission validation to ensure the user has the write perm on 
Database objects.
   
   With that in mind, technically this shouldn't be a concern. In any case, 
I've just added logic to validate the current user has write access on DB 
objects directly in the `validate` method for the command (since the Celery 
call would go through it).
   
   Could you please review and mark this thread + this topic in your top 
summary as resolved?



-- 
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-unsubscr...@superset.apache.org

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


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

Reply via email to