Fix setting the workflow on a collection

The previous implementation would delete all accesses if the bucket
was not all_access.

I think it's simpler to move the bucket workflow into a separate
Buckets::WorkflowsController, rather than deal with different sets of
params from different forms in the existing BucketsController.
This commit is contained in:
Mike Dalessio
2025-03-30 09:24:56 -04:00
parent de6f782ca3
commit b7c2369988
7 changed files with 55 additions and 3 deletions
@@ -0,0 +1,16 @@
class Buckets::WorkflowsController < ApplicationController
include BucketScoped
before_action :set_workflow
def update
@bucket.update! workflow: @workflow
redirect_to bubbles_path(bucket_ids: [ @bucket ])
end
private
def set_workflow
@workflow = Current.account.workflows.find(params.expect(bucket: [ :workflow_id ]).require(:workflow_id))
end
end
+1 -2
View File
@@ -33,8 +33,7 @@ class BucketsController < ApplicationController
end
def bucket_params
params.expect(bucket: [ :name, :all_access, :workflow_id ]).with_defaults(all_access: false)
params.require(:bucket).permit(:name, :all_access, :workflow_id)
params.expect(bucket: [ :name, :all_access ]).with_defaults(all_access: false)
end
def grantees
+1 -1
View File
@@ -79,7 +79,7 @@
<div class="panel shadow center flex flex-column gap-half margin-block-double" style="--panel-size: 55ch;">
<strong class="txt-large">Choose a workflow</strong>
<p class="margin-none">Use a workflow to track progress in this collection.</p>
<%= form_with model: @bucket, local: true, data: { controller: "form" } do |form| %>
<%= form_with model: @bucket, url: bucket_workflow_path(@bucket), local: true, method: :patch, data: { controller: "form" } do |form| %>
<%= form.select :workflow_id, Current.account.workflows.map { |w| [w.name, w.id] }, { include_blank: "Choose…" }, class: "input input--select full-width", data: { action: "change->form#submit" } %>
<% end %>
<p><%= link_to "Manage workflows", workflows_path, class: "btn btn--plain txt-link" %></p>
+1
View File
@@ -35,6 +35,7 @@ Rails.application.routes.draw do
resources :buckets do
scope module: :buckets do
resource :subscriptions
resource :workflow, only: :update
end
resources :bubbles do
@@ -0,0 +1,16 @@
require "test_helper"
class Buckets::WorkflowsControllerTest < ActionDispatch::IntegrationTest
setup do
sign_in_as :kevin
end
test "update" do
bucket = buckets(:writebook)
patch bucket_workflow_url(bucket), params: { bucket: { workflow_id: workflows(:on_call).id } }
assert_redirected_to bubbles_path(bucket_ids: [ bucket.id ])
assert_equal workflows(:on_call), bucket.reload.workflow
end
end
+16
View File
@@ -13,3 +13,19 @@ qa_on_hold:
qa_review:
name: Review
workflow: qa
on_call_inbox:
name: Inbox
workflow: on_call
on_call_in_progress:
name: In progress
workflow: on_call
on_call_on_hold:
name: Waiting on customers
workflow: on_call
on_call_review:
name: Pending deploy
workflow: on_call
+4
View File
@@ -1,3 +1,7 @@
qa:
account: 37s
name: QA
on_call:
account: 37s
name: "On call"