예제 #1
0
def get_incident_costs(
        db_session: Session = Depends(get_db),
        page: int = 1,
        items_per_page: int = Query(5, alias="itemsPerPage"),
        query_str: str = Query(None, alias="q"),
        sort_by: List[str] = Query([], alias="sortBy[]"),
        descending: List[bool] = Query([], alias="descending[]"),
        fields: List[str] = Query([], alias="fields[]"),
        ops: List[str] = Query([], alias="ops[]"),
        values: List[str] = Query([], alias="values[]"),
):
    """
    Get all incident costs, or only those matching a given search term.
    """
    return search_filter_sort_paginate(
        db_session=db_session,
        model="IncidentCost",
        query_str=query_str,
        page=page,
        items_per_page=items_per_page,
        sort_by=sort_by,
        descending=descending,
        fields=fields,
        values=values,
        ops=ops,
    )
예제 #2
0
def get_organizations(
    db_session: Session = Depends(get_db),
    page: int = 1,
    items_per_page: int = Query(5, alias="itemsPerPage"),
    query_str: str = Query(None, alias="q"),
    sort_by: List[str] = Query([], alias="sortBy[]"),
    descending: List[bool] = Query([], alias="descending[]"),
    fields: List[str] = Query([], alias="fields[]"),
    ops: List[str] = Query([], alias="ops[]"),
    values: List[str] = Query([], alias="values[]"),
):
    """
    Get all organizations.
    """
    return search_filter_sort_paginate(
        db_session=db_session,
        model="Organization",
        query_str=query_str,
        page=page,
        items_per_page=items_per_page,
        sort_by=sort_by,
        descending=descending,
        fields=fields,
        values=values,
        ops=ops,
    )
예제 #3
0
파일: views.py 프로젝트: terry-sm/dispatch
def get_plugins_by_type(
        plugin_type: str,
        db_session: Session = Depends(get_db),
        page: int = 1,
        items_per_page: int = Query(5, alias="itemsPerPage"),
        query_str: str = Query(None, alias="q"),
        sort_by: List[str] = Query([], alias="sortBy[]"),
        descending: List[bool] = Query([], alias="descending[]"),
        fields: List[str] = Query([], alias="fields[]"),
        ops: List[str] = Query([], alias="ops[]"),
        values: List[str] = Query([], alias="values[]"),
):
    """
    Get all plugins by type.
    """
    return search_filter_sort_paginate(
        db_session=db_session,
        model="Plugin",
        query_str=query_str,
        page=page,
        items_per_page=items_per_page,
        sort_by=sort_by,
        descending=descending,
        fields=["type"],
        values=[plugin_type],
        ops=["=="],
    )
예제 #4
0
def get_users(*,
              organization: OrganizationSlug,
              common: dict = Depends(common_parameters)):
    """Get all users."""
    common["filter_spec"] = {
        "and": [{
            "model": "Organization",
            "op": "==",
            "field": "name",
            "value": organization
        }]
    }
    items = search_filter_sort_paginate(model="DispatchUser", **common)

    # filtered users
    return {
        "total":
        items["total"],
        "items": [{
            "id": u.id,
            "email": u.email,
            "projects": u.projects,
            "role": u.get_organization_role(organization),
        } for u in items["items"]],
    }
예제 #5
0
def get_incident_types(
        db_session: Session = Depends(get_db),
        page: int = 1,
        items_per_page: int = Query(5, alias="itemsPerPage"),
        query_str: str = Query(None, alias="q"),
        sort_by: List[str] = Query([], alias="sortBy[]"),
        descending: List[bool] = Query([], alias="descending[]"),
        fields: List[str] = Query([], alias="fields[]"),
        ops: List[str] = Query([], alias="ops[]"),
        values: List[str] = Query([], alias="values[]"),
        current_user: DispatchUser = Depends(get_current_user),
):
    """
    Returns all incident types.
    """
    return search_filter_sort_paginate(
        db_session=db_session,
        model="IncidentType",
        query_str=query_str,
        page=page,
        items_per_page=items_per_page,
        sort_by=sort_by,
        descending=descending,
        fields=fields,
        values=values,
        ops=ops,
        user_role=current_user.role,
    )
예제 #6
0
def get_plugins_by_type(plugin_type: str,
                        common: dict = Depends(common_parameters)):
    """
    Get all plugins by type.
    """
    common["filter_spec"] = [{
        "field": "type",
        "op": "==",
        "value": plugin_type
    }]
    return search_filter_sort_paginate(model="Plugin", **common)
예제 #7
0
def get_incidents(
        db_session: Session = Depends(get_db),
        page: int = 1,
        items_per_page: int = Query(5, alias="itemsPerPage"),
        query_str: str = Query(None, alias="q"),
        filter_spec: str = Query(None, alias="filter"),
        sort_by: List[str] = Query([], alias="sortBy[]"),
        descending: List[bool] = Query([], alias="descending[]"),
        fields: List[str] = Query([], alias="fields[]"),
        ops: List[str] = Query([], alias="ops[]"),
        values: List[str] = Query([], alias="values[]"),
        current_user: DispatchUser = Depends(get_current_user),
        include: List[str] = Query([], alias="include[]"),
):
    """
    Retrieve a list of all incidents.
    """
    if filter_spec:
        filter_spec = json.loads(filter_spec)

    pagination = search_filter_sort_paginate(
        db_session=db_session,
        model="Incident",
        query_str=query_str,
        filter_spec=filter_spec,
        page=page,
        items_per_page=items_per_page,
        sort_by=sort_by,
        descending=descending,
        fields=fields,
        values=values,
        ops=ops,
        join_attrs=[
            ("tag", "tags"),
        ],
        user_role=current_user.role,
        user_email=current_user.email,
    )

    if include:
        # only allow two levels for now
        include_sets = create_pydantic_include(include)

        include_fields = {
            "items": {
                "__all__": include_sets
            },
            "itemsPerPage":...,
            "page":...,
            "total":...,
        }
        return IncidentPagination(**pagination).dict(include=include_fields)
    return IncidentPagination(**pagination).dict()
예제 #8
0
파일: views.py 프로젝트: terry-sm/dispatch
def get_tasks(
    db_session: Session = Depends(get_db),
    page: int = 1,
    items_per_page: int = Query(5, alias="itemsPerPage"),
    query_str: str = Query(None, alias="q"),
    sort_by: List[str] = Query([], alias="sortBy[]"),
    descending: List[bool] = Query([], alias="descending[]"),
    fields: List[str] = Query([], alias="fields[]"),
    ops: List[str] = Query([], alias="ops[]"),
    values: List[str] = Query([], alias="values[]"),
    include: List[str] = Query([], alias="include[]"),
):
    """
    Retrieve all tasks.
    """
    pagination = search_filter_sort_paginate(
        db_session=db_session,
        model="Task",
        query_str=query_str,
        page=page,
        items_per_page=items_per_page,
        sort_by=sort_by,
        descending=descending,
        fields=fields,
        values=values,
        ops=ops,
        join_attrs=[
            ("incident", "incident"),
            ("incident_type", "incident"),
            ("incident_priority", "incident"),
            ("tags", "tag"),
            ("creator", "creator"),
            ("owner", "owner"),
        ],
    )

    if include:
        # only allow two levels for now
        include_sets = create_pydantic_include(include)

        include_fields = {
            "items": {"__all__": include_sets},
            "itemsPerPage": ...,
            "page": ...,
            "total": ...,
        }

        return TaskPagination(**pagination).dict(include=include_fields)
    return TaskPagination(**pagination).dict()
예제 #9
0
def get_incidents(
    *,
    common: dict = Depends(common_parameters),
    include: List[str] = Query([], alias="include[]"),
):
    """Retrieve a list of all incidents."""
    pagination = search_filter_sort_paginate(model="Incident", **common)

    if include:
        # only allow two levels for now
        include_sets = create_pydantic_include(include)

        include_fields = {
            "items": {"__all__": include_sets},
            "itemsPerPage": ...,
            "page": ...,
            "total": ...,
        }
        return json.loads(IncidentPagination(**pagination).json(include=include_fields))
    return json.loads(IncidentPagination(**pagination).json())
예제 #10
0
def get_tasks(
    *, include: List[str] = Query([], alias="include[]"), commons: dict = Depends(common_parameters)
):
    """
    Retrieve all tasks.
    """
    pagination = search_filter_sort_paginate(model="Task", **commons)

    if include:
        # only allow two levels for now
        include_sets = create_pydantic_include(include)

        include_fields = {
            "items": {"__all__": include_sets},
            "itemsPerPage": ...,
            "page": ...,
            "total": ...,
        }

        return TaskPagination(**pagination).dict(include=include_fields)
    return TaskPagination(**pagination).dict()
예제 #11
0
파일: views.py 프로젝트: Netflix/dispatch
def get_feedback_entries(*, commons: dict = Depends(common_parameters)):
    """Get all feedback entries, or only those matching a given search term."""
    return search_filter_sort_paginate(model="Feedback", **commons)
예제 #12
0
파일: views.py 프로젝트: Netflix/dispatch
def get_services(*, common: dict = Depends(common_parameters)):
    """Retrieve all services."""
    return search_filter_sort_paginate(model="Service", **common)
예제 #13
0
def get_incident_cost_types(*, common: dict = Depends(common_parameters)):
    """
    Get all incident cost types, or only those matching a given search term.
    """
    return search_filter_sort_paginate(model="IncidentCostType", **common)
예제 #14
0
def get_terms(*, common: dict = Depends(common_parameters)):
    """
    Retrieve all terms.
    """
    return search_filter_sort_paginate(model="Term", **common)
예제 #15
0
파일: views.py 프로젝트: Netflix/dispatch
def get_incident_types(*, common: dict = Depends(common_parameters)):
    """Returns all incident types."""
    return search_filter_sort_paginate(model="IncidentType", **common)
예제 #16
0
def get_notifications(*, common: dict = Depends(common_parameters)):
    """
    Get all notifications, or only those matching a given search term.
    """
    return search_filter_sort_paginate(model="Notification", **common)
예제 #17
0
def get_incident_priorities(*, common: dict = Depends(common_parameters)):
    """
    Returns all incident priorities.
    """
    return search_filter_sort_paginate(model="IncidentPriority", **common)
예제 #18
0
def get_tags(*, common: dict = Depends(common_parameters)):
    """Get all tags, or only those matching a given search term."""
    return search_filter_sort_paginate(model="Tag", **common)
예제 #19
0
def get_users(*, common: dict = Depends(common_parameters)):
    """
    Get all users.
    """
    return search_filter_sort_paginate(model="DispatchUser", **common)
예제 #20
0
def get_documents(*, common: dict = Depends(common_parameters)):
    """
    Get all documents.
    """
    return search_filter_sort_paginate(model="Document", **common)
예제 #21
0
def get_definitions(*, common: dict = Depends(common_parameters)):
    """
    Get all definitions.
    """
    return search_filter_sort_paginate(model="Definition", **common)
예제 #22
0
def get_plugins(*, common: dict = Depends(common_parameters)):
    """
    Get all plugins.
    """
    return search_filter_sort_paginate(model="Plugin", **common)
예제 #23
0
def get_individuals(*, common: dict = Depends(common_parameters)):
    """
    Retrieve individual contacts.
    """
    return search_filter_sort_paginate(model="IndividualContact", **common)
예제 #24
0
def get_source_data_formats(*, common: dict = Depends(common_parameters)):
    """Get all source_data_format data formats, or only those matching a given search term."""
    return search_filter_sort_paginate(model="SourceDataFormat", **common)
예제 #25
0
def get_workflows(*, common: dict = Depends(common_parameters)):
    """
    Get all workflows.
    """
    return search_filter_sort_paginate(model="Workflow", **common)
예제 #26
0
def get_filters(*, common: dict = Depends(common_parameters)):
    """
    Retrieve filters.
    """
    return search_filter_sort_paginate(model="SearchFilter", **common)
예제 #27
0
파일: views.py 프로젝트: Netflix/dispatch
def get_source_types(*, common: dict = Depends(common_parameters)):
    """Get all source types, or only those matching a given search term."""
    return search_filter_sort_paginate(model="SourceType", **common)
예제 #28
0
파일: views.py 프로젝트: Netflix/dispatch
def get_teams(*, common: dict = Depends(common_parameters)):
    """Get all team contacts."""
    return search_filter_sort_paginate(model="TeamContact", **common)
예제 #29
0
def get_tags(
    db_session: SessionLocal,
    user_id: int,
    user_email: str,
    channel_id: str,
    incident_id: str,
    query_str: str,
    request: Request,
):
    """Fetches tags based on the current query."""
    # use the project from the incident if available
    filter_spec = {}
    if incident_id:
        incident = incident_service.get(db_session=db_session,
                                        incident_id=incident_id)
        # scope to current incident project
        filter_spec = {
            "and": [{
                "model": "Project",
                "op": "==",
                "field": "id",
                "value": incident.project.id
            }]
        }

    submitted_form = request.get("view")
    parsed_form_data = parse_submitted_form(submitted_form)
    project = parsed_form_data.get(IncidentBlockId.project)

    if project:
        filter_spec = {
            "and": [{
                "model": "Project",
                "op": "==",
                "field": "name",
                "value": project["value"]
            }]
        }

    # attempt to filter by tag type
    if "/" in query_str:
        tag_type, tag_name = query_str.split("/")
        type_filter = {
            "model": "TagType",
            "op": "==",
            "field": "name",
            "value": tag_type
        }

        if filter_spec.get("and"):
            filter_spec["and"].append(type_filter)
        else:
            filter_spec = {"and": [type_filter]}

        if not tag_name:
            query_str = None

        tags = search_filter_sort_paginate(db_session=db_session,
                                           model="Tag",
                                           query_str=query_str,
                                           filter_spec=filter_spec)
    else:
        tags = search_filter_sort_paginate(db_session=db_session,
                                           model="Tag",
                                           query_str=query_str,
                                           filter_spec=filter_spec)

    options = []
    for t in tags["items"]:
        options.append({
            "text": {
                "type": "plain_text",
                "text": f"{t.tag_type.name}/{t.name}"
            },
            "value": str(
                t.id
            ),  # NOTE slack doesn't not accept int's as values (fails silently)
        })

    return {"options": options}
예제 #30
0
def get_organizations(common: dict = Depends(common_parameters)):
    """
    Get all organizations.
    """
    return search_filter_sort_paginate(model="Organization", **common)