From 33280487ec17f9c0e7e600cc98b40dcce2fbb84c Mon Sep 17 00:00:00 2001 From: Will Sheldon <114631109+wssheldon@users.noreply.github.com> Date: Tue, 7 Mar 2023 12:10:11 -0800 Subject: [PATCH 1/3] check for entity types --- src/dispatch/signal/service.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/dispatch/signal/service.py b/src/dispatch/signal/service.py index 7088796b1469..99a09f7b8b5d 100644 --- a/src/dispatch/signal/service.py +++ b/src/dispatch/signal/service.py @@ -195,11 +195,12 @@ def create(*, db_session: Session, signal_in: SignalCreate) -> Signal: signal.tags = tags entity_types = [] - for e in signal_in.entity_types: - entity_type = entity_type_service.get_by_name_or_raise( - db_session=db_session, project_id=project.id, entity_type_in=e - ) - entity_types.append(entity_type) + if signal_in.entity_types: + for e in signal_in.entity_types: + entity_type = entity_type_service.get_by_name_or_raise( + db_session=db_session, project_id=project.id, entity_type_in=e + ) + entity_types.append(entity_type) signal.entity_types = entity_types From 2c5c7222978744972c3942c4e5bc30373fbab15a Mon Sep 17 00:00:00 2001 From: Will Sheldon <114631109+wssheldon@users.noreply.github.com> Date: Tue, 7 Mar 2023 15:47:04 -0800 Subject: [PATCH 2/3] move optional lists to create --- src/dispatch/signal/models.py | 7 +++---- src/dispatch/signal/service.py | 11 +++++------ src/dispatch/static/dispatch/src/signal/store.js | 7 ++++--- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/dispatch/signal/models.py b/src/dispatch/signal/models.py index f1ae0b411967..dfeceab4b8b3 100644 --- a/src/dispatch/signal/models.py +++ b/src/dispatch/signal/models.py @@ -218,14 +218,13 @@ class SignalBase(DispatchBase): external_url: Optional[str] source: Optional[SourceBase] created_at: Optional[datetime] = None - filters: Optional[List[SignalFilterRead]] = [] - entity_types: Optional[List[EntityTypeRead]] = [] - tags: Optional[List[TagRead]] = [] project: ProjectRead class SignalCreate(SignalBase): - entity_types: Optional[EntityTypeCreate] = [] + filters: Optional[List[SignalFilterRead]] = [] + entity_types: Optional[List[EntityTypeRead]] = [] + tags: Optional[List[TagRead]] = [] class SignalUpdate(SignalBase): diff --git a/src/dispatch/signal/service.py b/src/dispatch/signal/service.py index 99a09f7b8b5d..7088796b1469 100644 --- a/src/dispatch/signal/service.py +++ b/src/dispatch/signal/service.py @@ -195,12 +195,11 @@ def create(*, db_session: Session, signal_in: SignalCreate) -> Signal: signal.tags = tags entity_types = [] - if signal_in.entity_types: - for e in signal_in.entity_types: - entity_type = entity_type_service.get_by_name_or_raise( - db_session=db_session, project_id=project.id, entity_type_in=e - ) - entity_types.append(entity_type) + for e in signal_in.entity_types: + entity_type = entity_type_service.get_by_name_or_raise( + db_session=db_session, project_id=project.id, entity_type_in=e + ) + entity_types.append(entity_type) signal.entity_types = entity_types diff --git a/src/dispatch/static/dispatch/src/signal/store.js b/src/dispatch/static/dispatch/src/signal/store.js index 9f0c88420bbb..77e7a2695487 100644 --- a/src/dispatch/static/dispatch/src/signal/store.js +++ b/src/dispatch/static/dispatch/src/signal/store.js @@ -16,10 +16,10 @@ const getDefaultSelectedState = () => { case_type: null, case_priority: null, enabled: false, - filters: null, - entity_types: null, + filters: [], + entity_types: [], + tags: [], signal_definition: null, - tags: null, source: null, project: null, created_at: null, @@ -141,6 +141,7 @@ const actions = { commit("RESET_SELECTED") }, save({ commit, dispatch }) { + console.log("Saving state: %O", state) commit("SET_SELECTED_LOADING", true) if (!state.selected.id) { return SignalApi.create(state.selected) From 1d9fdd73c47888018e4fc721e9ba8421f54f9a89 Mon Sep 17 00:00:00 2001 From: Will Sheldon <114631109+wssheldon@users.noreply.github.com> Date: Tue, 7 Mar 2023 15:47:34 -0800 Subject: [PATCH 3/3] Update src/dispatch/static/dispatch/src/signal/store.js --- src/dispatch/static/dispatch/src/signal/store.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/dispatch/static/dispatch/src/signal/store.js b/src/dispatch/static/dispatch/src/signal/store.js index 77e7a2695487..ca0d24ff0fa2 100644 --- a/src/dispatch/static/dispatch/src/signal/store.js +++ b/src/dispatch/static/dispatch/src/signal/store.js @@ -141,7 +141,6 @@ const actions = { commit("RESET_SELECTED") }, save({ commit, dispatch }) { - console.log("Saving state: %O", state) commit("SET_SELECTED_LOADING", true) if (!state.selected.id) { return SignalApi.create(state.selected)