def validate( # pylint: disable=arguments-differ self, session: Session = None) -> None: # Validate/populate model exists self._model = ReportScheduleDAO.find_by_id(self._model_id, session=session) if not self._model: raise ReportScheduleNotFoundError()
def validate(self) -> None: # Validate/populate model exists self._model = ReportScheduleDAO.find_by_id(self._model_id) if not self._model: raise ReportScheduleNotFoundError() # Check ownership try: security_manager.raise_for_ownership(self._model) except SupersetSecurityException as ex: raise ReportScheduleForbiddenError() from ex
def validate(self) -> None: exceptions: List[ValidationError] = list() owner_ids: Optional[List[int]] = self._properties.get("owners") report_type = self._properties.get("type", ReportScheduleType.ALERT) name = self._properties.get("name", "") self._model = ReportScheduleDAO.find_by_id(self._model_id) # Does the report exist? if not self._model: raise ReportScheduleNotFoundError() # Validate name uniqueness if not ReportScheduleDAO.validate_update_uniqueness( name, report_schedule_id=self._model_id): exceptions.append(ReportScheduleNameUniquenessValidationError()) # validate relation by report type if not report_type: report_type = self._model.type if report_type == ReportScheduleType.ALERT: database_id = self._properties.get("database") # If database_id was sent let's validate it exists if database_id: database = DatabaseDAO.find_by_id(database_id) if not database: exceptions.append(DatabaseNotFoundValidationError()) self._properties["database"] = database # Validate chart or dashboard relations self.validate_chart_dashboard(exceptions, update=True) if "validator_config_json" in self._properties: self._properties["validator_config_json"] = json.dumps( self._properties["validator_config_json"]) # Check ownership try: check_ownership(self._model) except SupersetSecurityException: raise ReportScheduleForbiddenError() # 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 = ReportScheduleInvalidError() exception.add_list(exceptions) raise exception
def validate(self) -> None: # Validate/populate model exists self._models = ReportScheduleDAO.find_by_ids(self._model_ids) if not self._models or len(self._models) != len(self._model_ids): raise ReportScheduleNotFoundError() # Check ownership for model in self._models: try: check_ownership(model) except SupersetSecurityException as ex: raise ReportScheduleForbiddenError() from ex
def validate( # pylint: disable=arguments-differ self, session: Session = None ) -> None: # Validate/populate model exists self._model = ReportScheduleDAO.find_by_id(self._model_id, session=session) if not self._model: raise ReportScheduleNotFoundError() # Avoid overlap processing if self._model.last_state == ReportLogState.WORKING: raise ReportSchedulePreviousWorkingError() # Check grace period if self._model.type == ReportScheduleType.ALERT: last_success = ReportScheduleDAO.find_last_success_log(session) if ( last_success and self._model.last_state in (ReportLogState.SUCCESS, ReportLogState.NOOP) and self._model.grace_period and datetime.utcnow() - timedelta(seconds=self._model.grace_period) < last_success.end_dttm ): raise ReportScheduleAlertGracePeriodError()
def validate(self) -> None: exceptions: List[ValidationError] = list() owner_ids: Optional[List[int]] = self._properties.get("owners") report_type = self._properties.get("type", ReportScheduleType.ALERT) name = self._properties.get("name", "") self._model = ReportScheduleDAO.find_by_id(self._model_id) # Does the report exist? if not self._model: raise ReportScheduleNotFoundError() # Change the state to not triggered when the user deactivates # A report that is currently in a working state. This prevents # an alert/report from being kept in a working state if activated back if (self._model.last_state == ReportState.WORKING and "active" in self._properties and not self._properties["active"]): self._properties["last_state"] = ReportState.NOOP # validate relation by report type if not report_type: report_type = self._model.type # Validate name type uniqueness if not ReportScheduleDAO.validate_update_uniqueness( name, report_type, report_schedule_id=self._model_id): exceptions.append(ReportScheduleNameUniquenessValidationError()) if report_type == ReportScheduleType.ALERT: database_id = self._properties.get("database") # If database_id was sent let's validate it exists if database_id: database = DatabaseDAO.find_by_id(database_id) if not database: exceptions.append(DatabaseNotFoundValidationError()) self._properties["database"] = database # Validate chart or dashboard relations self.validate_chart_dashboard(exceptions, update=True) if "validator_config_json" in self._properties: self._properties["validator_config_json"] = json.dumps( self._properties["validator_config_json"]) # Check ownership try: check_ownership(self._model) except SupersetSecurityException: raise ReportScheduleForbiddenError() # 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 = ReportScheduleInvalidError() exception.add_list(exceptions) raise exception
def validate(self) -> None: # Validate/populate model exists self._model = ReportScheduleDAO.find_by_id(self._model_id) if not self._model: raise ReportScheduleNotFoundError()
def validate(self) -> None: # Validate/populate model exists self._models = ReportScheduleDAO.find_by_ids(self._model_ids) if not self._models or len(self._models) != len(self._model_ids): raise ReportScheduleNotFoundError()