villebro commented on a change in pull request #14015: URL: https://github.com/apache/superset/pull/14015#discussion_r709315163
########## File path: superset/dashboards/filter_sets/commands/base.py ########## @@ -0,0 +1,95 @@ +# 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. +import logging +from typing import cast, Optional + +from flask_appbuilder.models.sqla import Model +from flask_appbuilder.security.sqla.models import User + +from superset.commands.base import BaseCommand +from superset.common.not_authrized_object import NotAuthorizedException +from superset.common.request_contexed_based import is_user_admin +from superset.dashboards.commands.exceptions import DashboardNotFoundError +from superset.dashboards.dao import DashboardDAO +from superset.dashboards.filter_sets.commands.exceptions import ( + FilterSetForbiddenError, + FilterSetNotFoundError, +) +from superset.dashboards.filter_sets.consts import USER_OWNER_TYPE +from superset.models.dashboard import Dashboard +from superset.models.filter_set import FilterSet + +logger = logging.getLogger(__name__) + + +class BaseFilterSetCommand(BaseCommand): + # pylint: disable=C0103 + _dashboard: Dashboard + _filter_set_id: Optional[int] + _filter_set: Optional[FilterSet] + + def __init__(self, user: User, dashboard_id: int): + self._actor = user + self._is_actor_admin = is_user_admin() + self._dashboard_id = dashboard_id + + def run(self) -> Model: + pass + + def validate(self) -> None: + self._validate_filterset_dashboard_exists() + + def _validate_filterset_dashboard_exists(self) -> None: + self._dashboard = DashboardDAO.get_by_id_or_slug(str(self._dashboard_id)) + if not self._dashboard: + raise DashboardNotFoundError() Review comment: I would recommend not introducing abstractions before they are needed. If `validate` grows out of proportion it totally makes sense to break out the separate validators (we have linting rules for this), but until then I suggest just keeping it all in `validate()` with a comment explaining what each step is about if it's really difficult to understand (probably not needed here). -- 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]
