Пример #1
0
def dashboard_PATCH(request):
    dashboard = request.context.resource
    allowed_keys = ["public", "resource_name", "layout_config"]
    for k, v in request.unsafe_json_body.items():
        if k in allowed_keys:
            setattr(dashboard, k, v)
        else:
            return HTTPUnprocessableEntity()

    # ensure we don't have any leftover chart definitions present from
    # removed layout columns
    chart_ids = []
    for row in dashboard.layout_config:
        for col in row["columns"]:
            chart_ids.append(col["chartId"])

    for chart in dashboard.charts:
        if chart.uuid not in chart_ids:
            actions = AlertChannelActionService.by_other_id(chart.uuid)
            for action in actions:
                DBSession.delete(action)
            dashboard.charts.remove(chart)

    existing_ids = [c.uuid for c in dashboard.charts]
    for c_uuid in chart_ids:
        if c_uuid not in existing_ids:
            chart = DashboardChart(uuid=c_uuid, config=None)
            dashboard.charts.append(chart)
    request.session.flash("Dashboard updated")
    return dashboard.get_dict(request=request)
Пример #2
0
def charts_PATCH(request):
    dashboard = request.context.resource

    json_body = copy.deepcopy(request.unsafe_json_body)
    chart_config = json_body["config"]
    # for now just throw error in case something weird is found

    applications = UserService.resources_with_perms(
        request.user, ["view"], resource_types=["application"])

    # CRITICAL - this ensures our resultset is limited to only the ones
    # user has view permissions
    all_possible_app_ids = set([app.resource_id for app in applications])

    schema = ChartConfigSchema().bind(resources=all_possible_app_ids)
    schema.deserialize(chart_config)

    # some processing/normalizing for new/missing variables
    if "timeRange" not in chart_config:
        chart_config["timeRange"] = "1M"
    if "startMoment" not in chart_config:
        chart_config["startMoment"] = "now"
    if "startMomentUnit" not in chart_config:
        chart_config["startMomentUnit"] = "days"
    if "startMomentValue" not in chart_config:
        chart_config["startMomentValue"] = 0
    # ensure we don't have any leftover chart definitions present from
    # removed layout columns
    chart_ids = []
    for row in dashboard.layout_config:
        for col in row["columns"]:
            chart_ids.append(col["chartId"])
    for chart in dashboard.charts:
        if chart.uuid not in chart_ids:
            actions = AlertChannelActionService.by_other_id(chart.uuid)
            for action in actions:
                DBSession.delete(action)
            dashboard.charts.remove(chart)

    chart_config["json_config_version"] = chart.json_config_version
    # make sure we set model field as dirty
    request.context.chart.name = json_body["name"]
    request.context.chart.config = None
    request.context.chart.config = chart_config
    session = DBSession()
    mark_changed(session)
    request.session.flash("Chart saved")
    return True
Пример #3
0
def charts_event_rules_GET(request):
    actions = AlertChannelActionService.by_other_id(request.context.chart.uuid)
    return [a.get_dict(extended_info=True) for a in actions]