Vitor-Avila commented on code in PR #32231: URL: https://github.com/apache/superset/pull/32231#discussion_r1958840072
########## 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 `resync_database_permissions` will call `SyncPermissionsCommand.run()`, which ends up calling `validate()` and the `validate` method now ensures the user has write access. I prefer to keep any validation as part of the `validate` method, so that in the future if the `SyncPermissionsCommand` is called from other places, the actual validation logic is centralized. I'll be marking this as resolved now. -- 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