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

Revert "Removes option to delete a signal definition" #5483

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions src/dispatch/signal/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,14 @@ def update(*, db_session: Session, signal: Signal, signal_in: SignalUpdate) -> S
return signal


def delete(*, db_session: Session, signal_id: int):
"""Deletes a signal definition."""
signal = db_session.query(Signal).filter(Signal.id == signal_id).one()
db_session.delete(signal)
db_session.commit()
return signal_id


def is_valid_uuid(val):
try:
uuid.UUID(str(val), version=4)
Expand Down
17 changes: 17 additions & 0 deletions src/dispatch/signal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
create,
create_signal_engagement,
create_signal_filter,
delete,
delete_signal_filter,
get,
get_by_primary_or_external_id,
Expand Down Expand Up @@ -329,3 +330,19 @@ def update_signal(
) from None

return signal


@router.delete(
"/{signal_id}",
response_model=None,
dependencies=[Depends(PermissionsDependency([SensitiveProjectActionPermission]))],
)
def delete_signal(db_session: DbSession, signal_id: Union[str, PrimaryKey]):
"""Deletes a signal."""
signal = get_by_primary_or_external_id(db_session=db_session, signal_id=signal_id)
if not signal:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=[{"msg": "A signal with this id does not exist."}],
)
delete(db_session=db_session, signal_id=signal.id)
35 changes: 35 additions & 0 deletions src/dispatch/static/dispatch/src/signal/DeleteDialog.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<template>
<v-dialog v-model="showRemove" persistent max-width="800px">
<v-card>
<v-card-title>
<span class="text-h5">Delete Signal Definition?</span>
</v-card-title>
<v-card-text>
<v-container> Are you sure you would like to delete this Signal Definition? </v-container>
</v-card-text>
<v-card-actions>
<v-spacer />
<v-btn color="blue en-1" variant="text" @click="closeRemove()"> Cancel </v-btn>
<v-btn color="red en-1" variant="text" @click="remove()"> Delete </v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</template>

<script>
import { mapActions } from "vuex"
import { mapFields } from "vuex-map-fields"
export default {
name: "SignalDefinitionDeleteDialog",
data() {
return {}
},
computed: {
...mapFields("signal", ["dialogs.showRemove"]),
},

methods: {
...mapActions("signal", ["remove", "closeRemove"]),
},
}
</script>
8 changes: 6 additions & 2 deletions src/dispatch/static/dispatch/src/signal/Table.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<v-container fluid>
<new-edit-dialog />
<delete-dialog />
<v-row no-gutters>
<v-col>
<v-alert closable icon="mdi-school" prominent text type="info">
Expand Down Expand Up @@ -87,6 +88,9 @@
<v-list-item @click="createEditShow(item)">
<v-list-item-title>View / Edit</v-list-item-title>
</v-list-item>
<v-list-item @click="removeShow(item)">
<v-list-item-title>Delete</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
</template>
Expand All @@ -100,12 +104,12 @@
<script>
import { mapFields } from "vuex-map-fields"
import { mapActions } from "vuex"

import NewEditDialog from "@/signal/NewEditDialog.vue"
import DeleteDialog from "@/signal/DeleteDialog.vue"

export default {
name: "SignalTable",
components: { NewEditDialog },
components: { NewEditDialog, DeleteDialog },
props: {
name: {
type: String,
Expand Down
55 changes: 29 additions & 26 deletions tests/signal/test_signal_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_update(session, project, signal):


def test_update__add_filter(session, signal, signal_filter):
from dispatch.signal.models import SignalFilterRead, SignalUpdate
from dispatch.signal.models import SignalUpdate, SignalFilterRead
from dispatch.signal.service import update

signal_filter.project = signal.project
Expand Down Expand Up @@ -91,15 +91,21 @@ def test_update__delete_filter(session, signal, signal_filter):
assert len(signal.filters) == 0


def test_filter_actions_default_deduplicate(session, signal, project):
from datetime import datetime, timedelta
def test_delete(session, signal):
from dispatch.signal.service import delete, get

from dispatch.case.models import Case
from dispatch.entity.models import Entity
delete(db_session=session, signal_id=signal.id)
assert not get(db_session=session, signal_id=signal.id)


def test_filter_actions_default_deduplicate(session, signal, project):
from dispatch.signal.models import SignalInstance, SignalFilterAction
from dispatch.signal.service import filter_signal
from dispatch.entity_type.models import EntityType
from dispatch.entity.models import Entity
from dispatch.enums import Visibility
from dispatch.signal.models import SignalFilterAction, SignalInstance
from dispatch.signal.service import filter_signal
from dispatch.case.models import Case
from datetime import datetime, timedelta

entity_type = EntityType(
name="default_dedupe",
Expand Down Expand Up @@ -157,14 +163,14 @@ def test_filter_actions_default_deduplicate(session, signal, project):


def test_filter_actions_deduplicate_different_entities(session, signal, project):
from dispatch.entity.models import Entity
from dispatch.entity_type.models import EntityType
from dispatch.signal.models import (
SignalFilter,
SignalFilterAction,
SignalInstance,
SignalFilterAction,
)
from dispatch.signal.service import filter_signal
from dispatch.entity_type.models import EntityType
from dispatch.entity.models import Entity

entity_type_0 = EntityType(
name="dedupe2-0",
Expand Down Expand Up @@ -210,14 +216,14 @@ def test_filter_actions_deduplicate_different_entities(session, signal, project)


def test_filter_actions_deduplicate_different_entities_types(session, signal, project):
from dispatch.entity.models import Entity
from dispatch.entity_type.models import EntityType
from dispatch.signal.models import (
SignalFilter,
SignalFilterAction,
SignalInstance,
SignalFilterAction,
)
from dispatch.signal.service import filter_signal
from dispatch.entity_type.models import EntityType
from dispatch.entity.models import Entity

entity_type_0 = EntityType(
name="dedupe0-0",
Expand Down Expand Up @@ -268,14 +274,14 @@ def test_filter_actions_deduplicate_different_entities_types(session, signal, pr


def test_filter_actions_deduplicate(session, signal, project):
from dispatch.entity.models import Entity
from dispatch.entity_type.models import EntityType
from dispatch.signal.models import (
SignalFilter,
SignalFilterAction,
SignalInstance,
SignalFilterAction,
)
from dispatch.signal.service import filter_signal
from dispatch.entity_type.models import EntityType
from dispatch.entity.models import Entity

entity_type = EntityType(
name="dedupe1",
Expand Down Expand Up @@ -319,15 +325,14 @@ def test_filter_actions_deduplicate(session, signal, project):

def test_filter_action_with_dedupe_and_snooze(session, signal, project):
from datetime import datetime, timedelta, timezone

from dispatch.entity.models import Entity
from dispatch.entity_type.models import EntityType
from dispatch.signal.models import (
SignalFilter,
SignalFilterAction,
SignalInstance,
SignalFilterAction,
)
from dispatch.signal.service import filter_signal
from dispatch.entity_type.models import EntityType
from dispatch.entity.models import Entity

entity_type = EntityType(
name="dedupe1+snooze",
Expand Down Expand Up @@ -381,14 +386,13 @@ def test_filter_action_with_dedupe_and_snooze(session, signal, project):

def test_filter_actions_snooze(session, entity, signal, project):
from datetime import datetime, timedelta, timezone

from dispatch.entity_type.models import EntityType
from dispatch.signal.models import (
SignalFilter,
SignalFilterAction,
SignalInstance,
SignalFilterAction,
)
from dispatch.signal.service import filter_signal
from dispatch.entity_type.models import EntityType

entity_type = EntityType(
name="test",
Expand Down Expand Up @@ -426,14 +430,13 @@ def test_filter_actions_snooze(session, entity, signal, project):

def test_filter_actions_snooze_expired(session, entity, signal, project):
from datetime import datetime, timedelta, timezone

from dispatch.entity_type.models import EntityType
from dispatch.signal.models import (
SignalFilter,
SignalFilterAction,
SignalInstance,
SignalFilterAction,
)
from dispatch.signal.service import filter_signal
from dispatch.entity_type.models import EntityType

entity_type = EntityType(
name="test",
Expand Down
Loading