Esempio n. 1
0
    def validate(self) -> None:
        exceptions = list()
        datasource_type = self._properties["datasource_type"]
        datasource_id = self._properties["datasource_id"]
        dashboard_ids = self._properties.get("dashboards", [])
        owner_ids: Optional[List[int]] = self._properties.get("owners")

        # Validate/Populate datasource
        try:
            datasource = get_datasource_by_id(datasource_id, datasource_type)
            self._properties["datasource_name"] = datasource.name
        except ValidationError as ex:
            exceptions.append(ex)

        # Validate/Populate dashboards
        dashboards = DashboardDAO.find_by_ids(dashboard_ids)
        if len(dashboards) != len(dashboard_ids):
            exceptions.append(DashboardsNotFoundValidationError())
        self._properties["dashboards"] = dashboards

        try:
            owners = populate_owners(self._actor, owner_ids)
            self._properties["owners"] = owners
        except ValidationError as ex:
            exceptions.append(ex)
        if exceptions:
            exception = ChartInvalidError()
            exception.add_list(exceptions)
            raise exception
Esempio n. 2
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()
Esempio n. 3
0
    def validate(self) -> None:
        exceptions: List[ValidationError] = []
        dashboard_ids = self._properties.get("dashboards")
        owner_ids: Optional[List[int]] = self._properties.get("owners")

        # Validate if datasource_id is provided datasource_type is required
        datasource_id = self._properties.get("datasource_id")
        if datasource_id is not None:
            datasource_type = self._properties.get("datasource_type", "")
            if not datasource_type:
                exceptions.append(
                    DatasourceTypeUpdateRequiredValidationError())

        # Validate/populate model exists
        self._model = ChartDAO.find_by_id(self._model_id)
        if not self._model:
            raise ChartNotFoundError()

        # Check and update ownership; when only updating query context we ignore
        # ownership so the update can be performed by report workers
        if not is_query_context_update(self._properties):
            try:
                check_ownership(self._model)
                owners = self.populate_owners(self._actor, owner_ids)
                self._properties["owners"] = owners
            except SupersetSecurityException as ex:
                raise ChartForbiddenError() from ex
            except ValidationError as ex:
                exceptions.append(ex)

        # Validate/Populate datasource
        if datasource_id is not None:
            try:
                datasource = get_datasource_by_id(datasource_id,
                                                  datasource_type)
                self._properties["datasource_name"] = datasource.name
            except ValidationError as ex:
                exceptions.append(ex)

        # Validate/Populate dashboards only if it's a list
        if dashboard_ids is not None:
            dashboards = DashboardDAO.find_by_ids(dashboard_ids)
            if len(dashboards) != len(dashboard_ids):
                exceptions.append(DashboardsNotFoundValidationError())
            self._properties["dashboards"] = dashboards

        if exceptions:
            exception = ChartInvalidError()
            exception.add_list(exceptions)
            raise exception
Esempio n. 4
0
    def validate(self) -> None:
        exceptions: List[ValidationError] = list()
        dashboard_ids = self._properties.get("dashboards")
        owner_ids: Optional[List[int]] = self._properties.get("owners")

        # Validate if datasource_id is provided datasource_type is required
        datasource_id = self._properties.get("datasource_id")
        if datasource_id is not None:
            datasource_type = self._properties.get("datasource_type", "")
            if not datasource_type:
                exceptions.append(
                    DatasourceTypeUpdateRequiredValidationError())

        # Validate/populate model exists
        self._model = ChartDAO.find_by_id(self._model_id)
        if not self._model:
            raise ChartNotFoundError()
        # Check ownership
        try:
            check_ownership(self._model)
        except SupersetSecurityException:
            raise ChartForbiddenError()

        # Validate/Populate datasource
        if datasource_id is not None:
            try:
                datasource = get_datasource_by_id(datasource_id,
                                                  datasource_type)
                self._properties["datasource_name"] = datasource.name
            except ValidationError as ex:
                exceptions.append(ex)

        # Validate/Populate dashboards only if it's a list
        if dashboard_ids is not None:
            dashboards = DashboardDAO.find_by_ids(dashboard_ids)
            if len(dashboards) != len(dashboard_ids):
                exceptions.append(DashboardsNotFoundValidationError())
            self._properties["dashboards"] = dashboards

        # Validate/Populate owner
        try:
            owners = populate_owners(self._actor, owner_ids)
            self._properties["owners"] = owners
        except ValidationError as ex:
            exceptions.append(ex)
        if exceptions:
            exception = ChartInvalidError()
            exception.add_list(exceptions)
            raise exception
Esempio n. 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
Esempio n. 6
0
 def favorite_status(self, **kwargs: Any) -> Response:
     """Favorite Stars for Dashboards
     ---
     get:
       description: >-
         Check favorited dashboards for current user
       parameters:
       - in: query
         name: q
         content:
           application/json:
             schema:
               $ref: '#/components/schemas/get_fav_star_ids_schema'
       responses:
         200:
           description:
           content:
             application/json:
               schema:
                 $ref: "#/components/schemas/GetFavStarIdsSchema"
         400:
           $ref: '#/components/responses/400'
         401:
           $ref: '#/components/responses/401'
         404:
           $ref: '#/components/responses/404'
         500:
           $ref: '#/components/responses/500'
     """
     requested_ids = kwargs["rison"]
     dashboards = DashboardDAO.find_by_ids(requested_ids)
     if not dashboards:
         return self.response_404()
     favorited_dashboard_ids = DashboardDAO.favorited_ids(
         dashboards, g.user.get_id()
     )
     res = [
         {"id": request_id, "value": request_id in favorited_dashboard_ids}
         for request_id in requested_ids
     ]
     return self.response(200, result=res)
Esempio n. 7
0
 def validate(self) -> None:
     self._models = DashboardDAO.find_by_ids(self.dashboard_ids)
     if len(self._models) != len(self.dashboard_ids):
         raise DashboardNotFoundError()