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

Bugfix/workflow plugin instance #1359

Merged
merged 4 commits into from
Jun 23, 2021
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Moving column name from plugin_id to plugin_instance_id

Revision ID: 32811f581cb8
Revises: c767b759a508
Create Date: 2021-06-23 10:45:12.839871

"""
from alembic import op


# revision identifiers, used by Alembic.
revision = "32811f581cb8"
down_revision = "c767b759a508"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint("workflow_plugin_id_fkey", "workflow", type_="foreignkey")
op.alter_column("workflow", "plugin_id", new_column_name="plugin_instance_id")
op.create_foreign_key(None, "workflow", "plugin_instance", ["plugin_instance_id"], ["id"])
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, "workflow", type_="foreignkey")
op.alter_column("workflow", "plugin_instance_id", new_column_name="plugin_id")
op.create_foreign_key(
"workflow_plugin_id_fkey",
"workflow",
"plugin",
["plugin_id"],
["id"],
referent_schema="dispatch_core",
)
# ### end Alembic commands ###
2 changes: 1 addition & 1 deletion src/dispatch/plugin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class PluginInstance(Base, ProjectMixin):

# this is some magic that allows us to use the plugin search vectors
# against our plugin instances
search_vector = association_proxy(Plugin, "search_vector")
search_vector = association_proxy("plugin", "search_vector")

@property
def instance(self):
Expand Down
3 changes: 2 additions & 1 deletion src/dispatch/plugins/dispatch_slack/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
create_rating_feedback_modal,
)

from .modals.workflow.views import RunWorkflowCallbackId
from .modals.workflow.views import RunWorkflowBlockId, RunWorkflowCallbackId
from .modals.workflow.handlers import run_workflow_submitted_form, update_workflow_modal

from .modals.incident.handlers import (
Expand Down Expand Up @@ -133,6 +133,7 @@ def block_action_functions(action: str):
UpdateParticipantCallbackId.update_view: [update_update_participant_modal],
ReportIncidentCallbackId.update_view: [update_report_incident_modal],
RunWorkflowCallbackId.update_view: [update_workflow_modal],
RunWorkflowBlockId.workflow_select: [update_workflow_modal],
}

# this allows for unique action blocks e.g. invite-user or invite-user-1, etc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def run_workflow_view(
"text": "Select Workflow",
},
"options": workflow_options,
"action_id": RunWorkflowBlockId.workflow_select,
}
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default {
q: this.search,
sortBy: ["slug"],
itemsPerPage: this.numItems,
filters: JSON.stringify({
filter: JSON.stringify({
and: [
{
model: "Plugin",
Expand All @@ -123,7 +123,7 @@ export default {
value: this.type,
},
{
model: "Plugin",
model: "PluginInstance",
field: "enabled",
op: "==",
value: "true",
Expand Down
2 changes: 1 addition & 1 deletion src/dispatch/static/dispatch/src/plugin/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const getDefaultSelectedState = () => {
enabled: null,
configuration: [],
project: null,
plugin: null,
plugin_instance: null,
loading: false,
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/dispatch/static/dispatch/src/workflow/NewEditSheet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<span class="subtitle-2">Details</span>
</v-flex>
<v-flex xs12>
<ValidationProvider name="name" immediate>
<ValidationProvider name="name" rules="required" immediate>
<v-text-field
v-model="name"
slot-scope="{ errors, valid }"
Expand All @@ -43,7 +43,7 @@
</ValidationProvider>
</v-flex>
<v-flex xs12>
<ValidationProvider name="resourceId" immediate>
<ValidationProvider name="resourceId" rules="required" immediate>
<v-text-field
v-model="resource_id"
slot-scope="{ errors, valid }"
Expand All @@ -56,7 +56,7 @@
</ValidationProvider>
</v-flex>
<v-flex xs12>
<ValidationProvider name="description" immediate>
<ValidationProvider name="description" rules="required" immediate>
<v-textarea
v-model="description"
slot-scope="{ errors, valid }"
Expand All @@ -70,8 +70,8 @@
</ValidationProvider>
</v-flex>
<v-flex xs12>
<plugin-combobox
v-model="plugin"
<plugin-instance-combobox
v-model="plugin_instance"
type="workflow"
:project="project"
label="Plugin"
Expand Down Expand Up @@ -101,7 +101,7 @@ import { mapActions } from "vuex"
import { ValidationObserver, ValidationProvider, extend } from "vee-validate"
import { required } from "vee-validate/dist/rules"

import PluginCombobox from "@/plugin/PluginCombobox"
import PluginInstanceCombobox from "@/plugin/PluginInstanceCombobox"
import WorkflowParametersInput from "@/workflow/WorkflowParametersInput"

extend("required", {
Expand All @@ -115,7 +115,7 @@ export default {
components: {
ValidationObserver,
ValidationProvider,
PluginCombobox,
PluginInstanceCombobox,
WorkflowParametersInput,
},

Expand All @@ -127,7 +127,7 @@ export default {
"selected.resource_id",
"selected.parameters",
"selected.id",
"selected.plugin",
"selected.plugin_instance",
"selected.project",
"selected.loading",
"dialogs.showCreateEdit",
Expand Down
6 changes: 3 additions & 3 deletions src/dispatch/static/dispatch/src/workflow/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
:sort-by.sync="sortBy"
:sort-desc.sync="descending"
>
<template v-slot:item.plugin="{ item }">
{{ item.plugin.title }}
<template v-slot:item.plugin_instance="{ item }">
{{ item.plugin_instance.plugin.title }}
</template>
<template v-slot:item.enabled="{ item }">
<v-simple-checkbox v-model="item.enabled" disabled />
Expand Down Expand Up @@ -86,7 +86,7 @@ export default {
{ text: "Description", value: "description", sortable: false },
{ text: "Enabled", value: "enabled", sortable: true },
{ text: "ResourceId", value: "resource_id", sortable: true },
{ text: "Plugin", value: "plugin", sortable: true },
{ text: "Plugin", value: "plugin_instance", sortable: true },
{ text: "", value: "data-table-actions", sortable: false, align: "end" },
],
}
Expand Down
4 changes: 2 additions & 2 deletions src/dispatch/workflow/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from dispatch.document.models import DocumentCreate
from dispatch.models import DispatchBase, ResourceBase, ResourceMixin, TimeStampMixin, ProjectMixin
from dispatch.participant.models import ParticipantRead
from dispatch.plugin.models import PluginInstance, PluginRead
from dispatch.plugin.models import PluginInstance, PluginInstanceRead
from dispatch.project.models import ProjectRead


Expand Down Expand Up @@ -103,7 +103,7 @@ class WorkflowInstance(Base, ResourceMixin):
class WorkflowBase(DispatchBase):
name: str
resource_id: str
plugin: Optional[PluginRead]
plugin_instance: Optional[PluginInstanceRead]
parameters: Optional[List[dict]] = []
enabled: Optional[bool]
description: Optional[str]
Expand Down
14 changes: 9 additions & 5 deletions src/dispatch/workflow/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ def get_enabled(*, db_session) -> List[Optional[Workflow]]:
def create(*, db_session, workflow_in: WorkflowCreate) -> Workflow:
"""Creates a new workflow."""
project = project_service.get_by_name(db_session=db_session, name=workflow_in.project.name)
plugin = plugin_service.get(db_session=db_session, plugin_id=workflow_in.plugin.id)
plugin_instance = plugin_service.get_instance(
db_session=db_session, plugin_instance_id=workflow_in.plugin_instance.id
)
workflow = Workflow(
**workflow_in.dict(exclude={"plugin", "project"}),
plugin_instance=plugin,
**workflow_in.dict(exclude={"plugin_instance", "project"}),
plugin_instance=plugin_instance,
project=project,
)

Expand All @@ -59,8 +61,10 @@ def update(*, db_session, workflow: Workflow, workflow_in: WorkflowUpdate) -> Wo
if field in update_data:
setattr(workflow, field, update_data[field])

plugin = plugin_service.get(db_session=db_session, plugin_id=workflow_in.plugin.id)
workflow.plugin_instance = plugin
plugin_instance = plugin_service.get_instance(
db_session=db_session, plugin_instance_id=workflow_in.plugin_instance.id
)
workflow.plugin_instance = plugin_instance

db_session.add(workflow)
db_session.commit()
Expand Down