korbit-ai[bot] commented on code in PR #32231:
URL: https://github.com/apache/superset/pull/32231#discussion_r1958840279


##########
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:
   @Vitor-Avila Thanks for the clarification regarding the user permission 
checks in the `validate` method. It does make sense to centralize the 
validation logic to ensure that it applies throughout. I do agree with you on 
this point. One suggestion I have is to maybe add an inline comment right 
before the user impersonation step in the `resync_database_permissions` 
function, stating that user permissions are being validated in the `validate` 
method. This would make it clearer for someone looking at this function in 
isolation in the future. This is just a suggestion and it would be interesting 
to hear your thoughts on it.



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