예제 #1
0
    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
예제 #2
0
 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()
예제 #3
0
 def validate(self) -> None:
     # Validate/populate model exists
     self._models = DashboardDAO.find_by_ids(self._model_ids)
     if not self._models or len(self._models) != len(self._model_ids):
         raise DashboardNotFoundError()
     # Check ownership
     for model in self._models:
         try:
             check_ownership(model)
         except SupersetSecurityException:
             raise DashboardForbiddenError()
예제 #4
0
 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
예제 #5
0
 def validate(self) -> None:
     # Validate/populate model exists
     self._models = DashboardDAO.find_by_ids(self._model_ids)
     if not self._models or len(self._models) != len(self._model_ids):
         raise DashboardNotFoundError()
     # Check there are no associated ReportSchedules
     reports = ReportScheduleDAO.find_by_dashboard_ids(self._model_ids)
     if reports:
         report_names = [report.name for report in reports]
         raise DashboardBulkDeleteFailedReportsExistError(
             _("There are associated alerts or reports: %s" % ",".join(report_names))
         )
     # Check ownership
     for model in self._models:
         try:
             security_manager.raise_for_ownership(model)
         except SupersetSecurityException as ex:
             raise DashboardForbiddenError() from ex