Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new reports models api #11606

Merged
merged 26 commits into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions superset/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def init_views(self) -> None:
#
# pylint: disable=too-many-locals
# pylint: disable=too-many-statements
# pylint: disable=too-many-branches
from superset.annotation_layers.api import AnnotationLayerRestApi
from superset.annotation_layers.annotations.api import AnnotationRestApi
from superset.cachekeys.api import CacheRestApi
Expand All @@ -148,6 +149,8 @@ def init_views(self) -> None:
from superset.datasets.api import DatasetRestApi
from superset.queries.api import QueryRestApi
from superset.queries.saved_queries.api import SavedQueryRestApi
from superset.reports.api import ReportScheduleRestApi
from superset.reports.logs.api import ReportExecutionLogRestApi
from superset.views.access_requests import AccessRequestsModelView
from superset.views.alerts import (
AlertLogModelView,
Expand Down Expand Up @@ -206,6 +209,9 @@ def init_views(self) -> None:
appbuilder.add_api(DatasetRestApi)
appbuilder.add_api(QueryRestApi)
appbuilder.add_api(SavedQueryRestApi)
if feature_flag_manager.is_feature_enabled("ALERTS_REPORTS"):
appbuilder.add_api(ReportScheduleRestApi)
appbuilder.add_api(ReportExecutionLogRestApi)
#
# Setup regular views
#
Expand Down
2 changes: 2 additions & 0 deletions superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ def _try_json_readsha( # pylint: disable=unused-argument
# a custom security config could potentially give access to setting filters on
# tables that users do not have access to.
"ROW_LEVEL_SECURITY": False,
# Enables Alerts and reports new implementation
"ALERT_REPORTS": False,
}

# Set the default view to card/grid view if thumbnail support is enabled.
Expand Down
4 changes: 2 additions & 2 deletions superset/dao/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from typing import Any, Dict, List, Optional
from typing import Any, Dict, List, Optional, Type

from flask_appbuilder.models.filters import BaseFilter
from flask_appbuilder.models.sqla import Model
Expand All @@ -35,7 +35,7 @@ class BaseDAO:
Base DAO, implement base CRUD sqlalchemy operations
"""

model_cls: Optional[Model] = None
model_cls: Optional[Type[Model]] = None
"""
Child classes need to state the Model class so they don't need to implement basic
create, update and delete methods
Expand Down
15 changes: 9 additions & 6 deletions superset/models/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# pylint: disable=line-too-long,unused-argument,ungrouped-imports
"""A collection of ORM sqlalchemy models for Superset"""
import enum

Expand All @@ -30,7 +29,7 @@
Table,
Text,
)
from sqlalchemy.orm import relationship
from sqlalchemy.orm import backref, relationship
from sqlalchemy.schema import UniqueConstraint

from superset.extensions import security_manager
Expand All @@ -50,8 +49,8 @@ class ReportScheduleType(str, enum.Enum):
class ReportScheduleValidatorType(str, enum.Enum):
""" Validator types for alerts """

not_null = "not null"
operator = "operator"
NOT_NULL = "not null"
OPERATOR = "operator"


class ReportRecipientType(str, enum.Enum):
Expand Down Expand Up @@ -143,7 +142,9 @@ class ReportRecipients(
Integer, ForeignKey("report_schedule.id"), nullable=False
)
report_schedule = relationship(
ReportSchedule, backref="recipients", foreign_keys=[report_schedule_id]
ReportSchedule,
backref=backref("recipients", cascade="all,delete,delete-orphan"),
foreign_keys=[report_schedule_id],
)


Expand Down Expand Up @@ -173,5 +174,7 @@ class ReportExecutionLog(Model): # pylint: disable=too-few-public-methods
Integer, ForeignKey("report_schedule.id"), nullable=False
)
report_schedule = relationship(
ReportSchedule, backref="logs", foreign_keys=[report_schedule_id]
ReportSchedule,
backref=backref("logs", cascade="all,delete"),
foreign_keys=[report_schedule_id],
)
2 changes: 1 addition & 1 deletion superset/models/slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Slice(
primaryjoin="and_(Slice.datasource_id == SqlaTable.id, "
"Slice.datasource_type == 'table')",
remote_side="SqlaTable.id",
lazy="joined",
lazy="subquery",
)

token = ""
Expand Down
16 changes: 16 additions & 0 deletions superset/reports/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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.
Loading