Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/incident-filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
kevgliss authored Jul 19, 2021
2 parents f79e111 + 8aea672 commit 18c9ab8
Show file tree
Hide file tree
Showing 41 changed files with 287 additions and 634 deletions.
2 changes: 1 addition & 1 deletion requirements-base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ murmurhash==1.0.5
# preshed
# spacy
# thinc
numpy==1.21.0
numpy==1.21.1
# via
# -r requirements-base.in
# blis
Expand Down
5 changes: 3 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ appdirs==1.4.4
# via black
attrs==20.3.0
# via pytest
black==21.6b0
black==21.7b0
# via -r requirements-dev.in
click==8.0.1
# via black
Expand Down Expand Up @@ -56,8 +56,9 @@ text-unidecode==1.3
# via faker
toml==0.10.2
# via
# black
# pytest
# vulture
tomli==1.0.4
# via black
vulture==2.3
# via -r requirements-dev.in
12 changes: 3 additions & 9 deletions src/dispatch/auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@
response_model=UserPagination,
)
def get_users(*, organization: str, common: dict = Depends(common_parameters)):
"""
Get all users.
"""
"""Get all users."""
common["filter_spec"] = {
"and": [{"model": "Organization", "op": "==", "field": "name", "value": organization}]
}
Expand All @@ -66,9 +64,7 @@ def get_users(*, organization: str, common: dict = Depends(common_parameters)):

@user_router.get("/{user_id}", response_model=UserRead)
def get_user(*, db_session: Session = Depends(get_db), user_id: int):
"""
Get a user.
"""
"""Get a user."""
user = get(db_session=db_session, user_id=user_id)
if not user:
raise HTTPException(status_code=404, detail="The user with this id does not exist.")
Expand Down Expand Up @@ -96,9 +92,7 @@ def update_user(
organization: str,
user_in: UserUpdate,
):
"""
Update a user.
"""
"""Update a user."""
user = get(db_session=db_session, user_id=user_id)
if not user:
raise HTTPException(status_code=404, detail="The user with this id does not exist.")
Expand Down
2 changes: 1 addition & 1 deletion src/dispatch/conference/service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional, List
from typing import Optional

from .models import Conference, ConferenceCreate

Expand Down
20 changes: 5 additions & 15 deletions src/dispatch/definition/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@

@router.get("", response_model=DefinitionPagination)
def get_definitions(*, common: dict = Depends(common_parameters)):
"""
Get all definitions.
"""
"""Get all definitions."""
return search_filter_sort_paginate(model="Definition", **common)


@router.get("/{definition_id}", response_model=DefinitionRead)
def get_definition(*, db_session: Session = Depends(get_db), definition_id: int):
"""
Update a definition.
"""
"""Update a definition."""
definition = get(db_session=db_session, definition_id=definition_id)
if not definition:
raise HTTPException(status_code=404, detail="The definition with this id does not exist.")
Expand All @@ -36,9 +32,7 @@ def get_definition(*, db_session: Session = Depends(get_db), definition_id: int)

@router.post("", response_model=DefinitionRead)
def create_definition(*, db_session: Session = Depends(get_db), definition_in: DefinitionCreate):
"""
Create a new definition.
"""
"""Create a new definition."""
definition = get_by_text(db_session=db_session, text=definition_in.text)
if definition:
raise HTTPException(
Expand All @@ -53,9 +47,7 @@ def create_definition(*, db_session: Session = Depends(get_db), definition_in: D
def update_definition(
*, db_session: Session = Depends(get_db), definition_id: int, definition_in: DefinitionUpdate
):
"""
Update a definition.
"""
"""Update a definition."""
definition = get(db_session=db_session, definition_id=definition_id)
if not definition:
raise HTTPException(status_code=404, detail="The definition with this id does not exist.")
Expand All @@ -65,9 +57,7 @@ def update_definition(

@router.delete("/{definition_id}")
def delete_definition(*, db_session: Session = Depends(get_db), definition_id: int):
"""
Delete a definition.
"""
"""Delete a definition."""
definition = get(db_session=db_session, definition_id=definition_id)
if not definition:
raise HTTPException(status_code=404, detail="The definition with this id does not exist.")
Expand Down
20 changes: 5 additions & 15 deletions src/dispatch/document/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@

@router.get("", response_model=DocumentPagination)
def get_documents(*, common: dict = Depends(common_parameters)):
"""
Get all documents.
"""
"""Get all documents."""
return search_filter_sort_paginate(model="Document", **common)


@router.get("/{document_id}", response_model=DocumentRead)
def get_document(*, db_session: Session = Depends(get_db), document_id: int):
"""
Update a document.
"""
"""Update a document."""
document = get(db_session=db_session, document_id=document_id)
if not document:
raise HTTPException(status_code=404, detail="The document with this id does not exist.")
Expand All @@ -31,9 +27,7 @@ def get_document(*, db_session: Session = Depends(get_db), document_id: int):

@router.post("", response_model=DocumentCreate)
def create_document(*, db_session: Session = Depends(get_db), document_in: DocumentCreate):
"""
Create a new document.
"""
"""Create a new document."""
document = create(db_session=db_session, document_in=document_in)
return document

Expand All @@ -42,9 +36,7 @@ def create_document(*, db_session: Session = Depends(get_db), document_in: Docum
def update_document(
*, db_session: Session = Depends(get_db), document_id: int, document_in: DocumentUpdate
):
"""
Update a document.
"""
"""Update a document."""
document = get(db_session=db_session, document_id=document_id)
if not document:
raise HTTPException(status_code=404, detail="The document with this id does not exist.")
Expand All @@ -54,9 +46,7 @@ def update_document(

@router.delete("/{document_id}")
def delete_document(*, db_session: Session = Depends(get_db), document_id: int):
"""
Delete a document.
"""
"""Delete a document."""
document = get(db_session=db_session, document_id=document_id)
if not document:
raise HTTPException(status_code=404, detail="The document with this id does not exist.")
Expand Down
36 changes: 9 additions & 27 deletions src/dispatch/event/service.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
from typing import List, Optional
from uuid import uuid4
import datetime
import logging

from uuid import uuid4

from typing import List, Optional

from fastapi.encoders import jsonable_encoder

from sqlalchemy.dialects.postgresql import UUID

from dispatch.incident import service as incident_service
from dispatch.individual import service as individual_service

Expand All @@ -19,40 +15,30 @@


def get(*, db_session, event_id: int) -> Optional[Event]:
"""
Get an event by id.
"""
"""Get an event by id."""
return db_session.query(Event).filter(Event.id == event_id).one_or_none()


def get_by_incident_id(*, db_session, incident_id: int) -> List[Optional[Event]]:
"""
Get events by incident id.
"""
"""Get events by incident id."""
return db_session.query(Event).filter(Event.incident_id == incident_id)


def get_all(*, db_session) -> List[Optional[Event]]:
"""
Get all events.
"""
"""Get all events."""
return db_session.query(Event)


def create(*, db_session, event_in: EventCreate) -> Event:
"""
Create a new event.
"""
"""Create a new event."""
event = Event(**event_in.dict())
db_session.add(event)
db_session.commit()
return event


def update(*, db_session, event: Event, event_in: EventUpdate) -> Event:
"""
Updates an event.
"""
"""Updates an event."""
event_data = jsonable_encoder(event)
update_data = event_in.dict(skip_defaults=True)

Expand All @@ -66,9 +52,7 @@ def update(*, db_session, event: Event, event_in: EventUpdate) -> Event:


def delete(*, db_session, event_id: int):
"""
Deletes an event
"""
"""Deletes an event."""
event = db_session.query(Event).filter(Event.id == event_id).first()
db_session.delete(event)
db_session.commit()
Expand All @@ -84,9 +68,7 @@ def log(
ended_at: datetime = None,
details: dict = None,
) -> Event:
"""
Logs an event
"""
"""Logs an event."""
uuid = uuid4()

if not started_at:
Expand Down
4 changes: 1 addition & 3 deletions src/dispatch/feedback/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
def send_incident_feedback_daily_report(
commander_email: str, feedback: List[Feedback], project_id: int, db_session: SessionLocal
):
"""
Sends an incident feedback daily report to all incident commanders who received feedback.
"""
"""Sends an incident feedback daily report to all incident commanders who received feedback."""
plugin = plugin_service.get_active_instance(
db_session=db_session, project_id=project_id, plugin_type="email"
)
Expand Down
20 changes: 5 additions & 15 deletions src/dispatch/feedback/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,13 @@

@router.get("", response_model=FeedbackPagination)
def get_feedback_entries(*, commons: dict = Depends(common_parameters)):
"""
Get all feedback entries, or only those matching a given search term.
"""
"""Get all feedback entries, or only those matching a given search term."""
return search_filter_sort_paginate(model="Feedback", **commons)


@router.get("/{feedback_id}", response_model=FeedbackRead)
def get_feedback(*, db_session: Session = Depends(get_db), feedback_id: int):
"""
Get a feedback entry by its id.
"""
"""Get a feedback entry by its id."""
feedback = get(db_session=db_session, feedback_id=feedback_id)
if not feedback:
raise HTTPException(status_code=404, detail="A feedback entry with this id does not exist.")
Expand All @@ -38,9 +34,7 @@ def get_feedback(*, db_session: Session = Depends(get_db), feedback_id: int):

@router.post("", response_model=FeedbackRead)
def create_feedback(*, db_session: Session = Depends(get_db), feedback_in: FeedbackCreate):
"""
Create a new feedback entry.
"""
"""Create a new feedback entry."""
feedback = create(db_session=db_session, feedback_in=feedback_in)
return feedback

Expand All @@ -49,9 +43,7 @@ def create_feedback(*, db_session: Session = Depends(get_db), feedback_in: Feedb
def update_feedback(
*, db_session: Session = Depends(get_db), feedback_id: int, feedback_in: FeedbackUpdate
):
"""
Updates a feeback entry by its id.
"""
"""Updates a feeback entry by its id."""
feedback = get(db_session=db_session, feedback_id=feedback_id)
if not feedback:
raise HTTPException(status_code=404, detail="A feedback entry with this id does not exist.")
Expand All @@ -61,9 +53,7 @@ def update_feedback(

@router.delete("/{feedback_id}")
def delete_feedback(*, db_session: Session = Depends(get_db), feedback_id: int):
"""
Delete a feedback entry, returning only an HTTP 200 OK if successful.
"""
"""Delete a feedback entry, returning only an HTTP 200 OK if successful."""
feedback = get(db_session=db_session, feedback_id=feedback_id)
if not feedback:
raise HTTPException(status_code=404, detail="A feedback entry with this id does not exist.")
Expand Down
4 changes: 1 addition & 3 deletions src/dispatch/incident/scheduled.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ def auto_tagger(db_session: SessionLocal, project: Project):
@scheduler.add(every(1).day.at("18:00"), name="incident-daily-report")
@scheduled_project_task
def daily_report(db_session: SessionLocal, project: Project):
"""
Creates and sends incident daily reports based on notifications.
"""
"""Creates and sends incident daily reports based on notifications."""
# we fetch all active, stable and closed incidents
active_incidents = get_all_by_status(
db_session=db_session, project_id=project.id, status=IncidentStatus.active
Expand Down
Loading

0 comments on commit 18c9ab8

Please sign in to comment.