def validate(self) -> None: exceptions: List[ValidationError] = [] owner_ids: Optional[List[int]] = self._properties.get("owners") slug: Optional[str] = self._properties.get("slug") # Validate/populate model exists self._model = DashboardDAO.find_by_id(self._model_id) if not self._model: raise DashboardNotFoundError() # Check ownership try: check_ownership(self._model) except SupersetSecurityException: raise DashboardForbiddenError() # Validate slug uniqueness if not DashboardDAO.validate_update_slug_uniqueness( self._model_id, slug): exceptions.append(DashboardSlugExistsValidationError()) # Validate/Populate owner if owner_ids is None: owner_ids = [owner.id for owner in self._model.owners] try: owners = populate_owners(self._actor, owner_ids) self._properties["owners"] = owners except ValidationError as ex: exceptions.append(ex) if exceptions: exception = DashboardInvalidError() exception.add_list(exceptions) raise exception
def validate_chart_dashboard( self, exceptions: List[ValidationError], update: bool = False ) -> None: """Validate chart or dashboard relation""" chart_id = self._properties.get("chart") dashboard_id = self._properties.get("dashboard") creation_method = self._properties.get("creation_method") if creation_method == ReportCreationMethod.CHARTS and not chart_id: # User has not saved chart yet in Explore view exceptions.append(ChartNotSavedValidationError()) return if creation_method == ReportCreationMethod.DASHBOARDS and not dashboard_id: exceptions.append(DashboardNotSavedValidationError()) return if chart_id and dashboard_id: exceptions.append(ReportScheduleOnlyChartOrDashboardError()) if chart_id: chart = ChartDAO.find_by_id(chart_id) if not chart: exceptions.append(ChartNotFoundValidationError()) self._properties["chart"] = chart elif dashboard_id: dashboard = DashboardDAO.find_by_id(dashboard_id) if not dashboard: exceptions.append(DashboardNotFoundValidationError()) self._properties["dashboard"] = dashboard elif not update: exceptions.append(ReportScheduleEitherChartOrDashboardError())
def validate(self) -> None: # Validate/populate model exists self._model = DashboardDAO.find_by_id(self._model_id) if not self._model: raise DashboardNotFoundError() # Check ownership try: check_ownership(self._model) except SupersetSecurityException: raise DashboardForbiddenError()
def validate(self) -> None: # Validate/populate model exists self._model = DashboardDAO.find_by_id(self._model_id) if not self._model: raise DashboardNotFoundError() # Check there are no associated ReportSchedules reports = ReportScheduleDAO.find_by_dashboard_id(self._model_id) if reports: report_names = [report.name for report in reports] raise DashboardDeleteFailedReportsExistError( _("There are associated alerts or reports: %s" % ",".join(report_names))) # Check ownership try: check_ownership(self._model) except SupersetSecurityException as ex: raise DashboardForbiddenError() from ex
def validate_chart_dashboard(self, exceptions: List[ValidationError], update: bool = False) -> None: """ Validate chart or dashboard relation """ chart_id = self._properties.get("chart") dashboard_id = self._properties.get("dashboard") if chart_id and dashboard_id: exceptions.append(ReportScheduleChartOrDashboardValidationError()) if chart_id: chart = ChartDAO.find_by_id(chart_id) if not chart: exceptions.append(ChartNotFoundValidationError()) self._properties["chart"] = chart elif dashboard_id: dashboard = DashboardDAO.find_by_id(dashboard_id) if not dashboard: exceptions.append(DashboardNotFoundValidationError()) self._properties["dashboard"] = dashboard elif not update: exceptions.append(ReportScheduleChartOrDashboardValidationError())
def get_list(self, dashboard_id: int, **kwargs: Any) -> Response: """ Gets a dashboard's Filter sets --- get: description: >- Get a dashboard's list of filter sets parameters: - in: path schema: type: integer name: dashboard_id description: The id of the dashboard responses: 200: description: FilterSets content: application/json: schema: type: array items: type: object properties: name: description: Name of the Filter set type: string json_metadata: description: metadata of the filter set type: string description: description: A description field of the filter set type: string owner_id: description: A description field of the filter set type: integer owner_type: description: the Type of the owner ( Dashboard/User) type: integer parameters: description: JSON schema defining the needed parameters 302: description: Redirects to the current digest 400: $ref: '#/components/responses/400' 401: $ref: '#/components/responses/401' 404: $ref: '#/components/responses/404' """ if not DashboardDAO.find_by_id(cast(int, dashboard_id)): return self.response(404, message="dashboard '%s' not found" % dashboard_id) rison_data = kwargs.setdefault("rison", {}) rison_data.setdefault("filters", []) rison_data["filters"].append({ "col": "dashboard_id", "opr": "eq", "value": str(dashboard_id) }) return self.get_list_headless(**kwargs)