-
Auto-Close Cards
-
- <%= select_tag :closure, options_for_select(Card::Closeable::AUTO_CLOSE_OPTIONS, Card::Closeable::AUTO_CLOSE_AFTER), { class: "input input--select full-width margin-block-end", data: { action: "change->form#submit" } } %>
+ <%= render "collections/edit/auto_close", collection: @collection %>
-
-
Workflows
-
Use a Workflow to track progress in this Collection.
-
- <% Workflow.all.each do |workflow| %>
-
- <%= button_to collection_workflow_path(@collection), method: :patch do %>
- <%= hidden_field_tag "collection[workflow_id]", workflow.id %>
-
<%= workflow.name %>
-
- <% workflow.stages.each do |stage| %>
- -
-
- <%= stage.name %>
-
- <% end %>
-
- <% end %>
-
- <% end %>
-
-
<%= link_to "Manage workflows", workflows_path, class: "btn btn--plain txt-link" %>
+ <%= render "collections/edit/workflows", collection: @collection %>
diff --git a/app/views/collections/edit/_auto_close.html.erb b/app/views/collections/edit/_auto_close.html.erb
new file mode 100644
index 000000000..84be06644
--- /dev/null
+++ b/app/views/collections/edit/_auto_close.html.erb
@@ -0,0 +1,6 @@
+
Auto-Close Cards
+
+
+<%= form_with model: collection, data: { controller: "form" } do |form| %>
+ <%= form.select :auto_close_period, collection_auto_close_options, {}, { class: "input input--select full-width margin-block-end", data: { action: "change->form#submit" } } %>
+<% end %>
diff --git a/app/views/collections/edit/_name.html.erb b/app/views/collections/edit/_name.html.erb
new file mode 100644
index 000000000..e08e885ce
--- /dev/null
+++ b/app/views/collections/edit/_name.html.erb
@@ -0,0 +1,7 @@
+
+
+
diff --git a/app/views/collections/edit/_users.html.erb b/app/views/collections/edit/_users.html.erb
new file mode 100644
index 000000000..bc3530419
--- /dev/null
+++ b/app/views/collections/edit/_users.html.erb
@@ -0,0 +1,42 @@
+
diff --git a/app/views/collections/edit/_workflows.html.erb b/app/views/collections/edit/_workflows.html.erb
new file mode 100644
index 000000000..1d44f014e
--- /dev/null
+++ b/app/views/collections/edit/_workflows.html.erb
@@ -0,0 +1,21 @@
+
Workflows
+
Use a Workflow to track progress in this Collection.
+
+ <% Workflow.all.each do |workflow| %>
+
+ <%= button_to collection_workflow_path(collection), method: :patch do %>
+ <%= hidden_field_tag "collection[workflow_id]", workflow.id %>
+
<%= workflow.name %>
+
+ <% workflow.stages.each do |stage| %>
+ -
+
+ <%= stage.name %>
+
+ <% end %>
+
+ <% end %>
+
+ <% end %>
+
+
<%= link_to "Manage workflows", workflows_path, class: "btn btn--plain txt-link" %>
diff --git a/db/migrate/20250425092727_add_auto_close_period_to_collections.rb b/db/migrate/20250425092727_add_auto_close_period_to_collections.rb
new file mode 100644
index 000000000..5a96c9a60
--- /dev/null
+++ b/db/migrate/20250425092727_add_auto_close_period_to_collections.rb
@@ -0,0 +1,11 @@
+class AddAutoClosePeriodToCollections < ActiveRecord::Migration[8.1]
+ def change
+ add_column :collections, :auto_close_period, :bigint
+
+ add_index :collections, :auto_close_period
+
+ execute <<~SQL
+ UPDATE collections SET auto_close_period = #{30.days.to_i} WHERE auto_close_period IS NULL;
+ SQL
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 39f007f59..fcdb52c28 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema[8.1].define(version: 2025_04_25_070025) do
+ActiveRecord::Schema[8.1].define(version: 2025_04_25_092727) do
create_table "accesses", force: :cascade do |t|
t.integer "collection_id", null: false
t.datetime "created_at", null: false
@@ -141,11 +141,13 @@ ActiveRecord::Schema[8.1].define(version: 2025_04_25_070025) do
create_table "collections", force: :cascade do |t|
t.boolean "all_access", default: false, null: false
+ t.bigint "auto_close_period"
t.datetime "created_at", null: false
t.integer "creator_id", null: false
t.string "name", null: false
t.datetime "updated_at", null: false
t.integer "workflow_id"
+ t.index ["auto_close_period"], name: "index_collections_on_auto_close_period"
t.index ["creator_id"], name: "index_collections_on_creator_id"
t.index ["workflow_id"], name: "index_collections_on_workflow_id"
end
@@ -292,7 +294,6 @@ ActiveRecord::Schema[8.1].define(version: 2025_04_25_070025) do
t.datetime "created_at", null: false
t.string "title"
t.datetime "updated_at", null: false
- t.index ["title"], name: "index_tags_on_account_id_and_title", unique: true
end
create_table "users", force: :cascade do |t|
diff --git a/db/schema_cache.yml b/db/schema_cache.yml
index 00b890f15..3df7f5fe6 100644
--- a/db/schema_cache.yml
+++ b/db/schema_cache.yml
@@ -504,6 +504,16 @@ columns:
default_function:
collation:
comment:
+ - !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column
+ auto_increment:
+ name: auto_close_period
+ cast_type: *11
+ sql_type_metadata: *12
+ 'null': true
+ default:
+ default_function:
+ collation:
+ comment:
- *5
- *23
- *6
@@ -1401,6 +1411,22 @@ indexes:
comment:
valid: true
collections:
+ - !ruby/object:ActiveRecord::ConnectionAdapters::IndexDefinition
+ table: collections
+ name: index_collections_on_auto_close_period
+ unique: false
+ columns:
+ - auto_close_period
+ lengths: {}
+ orders: {}
+ opclasses: {}
+ where:
+ type:
+ using:
+ include:
+ nulls_not_distinct:
+ comment:
+ valid: true
- !ruby/object:ActiveRecord::ConnectionAdapters::IndexDefinition
table: collections
name: index_collections_on_creator_id
@@ -1941,23 +1967,7 @@ indexes:
nulls_not_distinct:
comment:
valid: true
- tags:
- - !ruby/object:ActiveRecord::ConnectionAdapters::IndexDefinition
- table: tags
- name: index_tags_on_account_id_and_title
- unique: true
- columns:
- - title
- lengths: {}
- orders: {}
- opclasses: {}
- where:
- type:
- using:
- include:
- nulls_not_distinct:
- comment:
- valid: true
+ tags: []
users:
- !ruby/object:ActiveRecord::ConnectionAdapters::IndexDefinition
table: users
@@ -2042,4 +2052,4 @@ indexes:
comment:
valid: true
workflows: []
-version: 20250425070025
+version: 20250425092727
diff --git a/test/controllers/collections_controller_test.rb b/test/controllers/collections_controller_test.rb
index 20111c4bf..f816332b8 100644
--- a/test/controllers/collections_controller_test.rb
+++ b/test/controllers/collections_controller_test.rb
@@ -35,7 +35,7 @@ class CollectionsControllerTest < ActionDispatch::IntegrationTest
user_ids: users(:david, :jz).pluck(:id)
}
- assert_redirected_to cards_path(collection_ids: [ collections(:writebook) ])
+ assert_redirected_to edit_collection_path(collections(:writebook))
assert_equal "Writebook bugs", collections(:writebook).reload.name
assert_equal users(:david, :jz).sort, collections(:writebook).users.sort
assert_not collections(:writebook).all_access?
@@ -49,7 +49,7 @@ class CollectionsControllerTest < ActionDispatch::IntegrationTest
patch collection_path(collection), params: { collection: { name: "Bugs", all_access: true } }
- assert_redirected_to cards_path(collection_ids: [ collection ])
+ assert_redirected_to edit_collection_path(collection)
assert collection.reload.all_access?
assert_equal User.all, collection.users
end
diff --git a/test/fixtures/collections.yml b/test/fixtures/collections.yml
index 9e1e8d484..1487aaa5e 100644
--- a/test/fixtures/collections.yml
+++ b/test/fixtures/collections.yml
@@ -2,4 +2,5 @@ writebook:
name: Writebook
creator: david
all_access: true
+ auto_close_period: 30
workflow: qa
diff --git a/test/models/card/closeable_test.rb b/test/models/card/closeable_test.rb
index 738eaca53..008058866 100644
--- a/test/models/card/closeable_test.rb
+++ b/test/models/card/closeable_test.rb
@@ -15,11 +15,19 @@ class Card::CloseableTest < ActiveSupport::TestCase
assert_equal users(:kevin), cards(:logo).closed_by
end
- test "auto_close_all_due" do
+ test "autoclose_at infers the period from the collection" do
+ freeze_time
+
+ collections(:writebook).update! auto_close_period: 123.days
+ cards(:logo).update! last_active_at: 2.day.ago
+ assert_equal (123-2).days.from_now, cards(:logo).auto_close_at
+ end
+
+ test "auto close all due" do
cards(:logo, :shipping).each(&:reconsider)
- cards(:logo).update!(last_active_at: 1.day.ago - Card::Closeable::AUTO_CLOSE_AFTER)
- cards(:shipping).update!(last_active_at: 1.day.from_now - Card::Closeable::AUTO_CLOSE_AFTER)
+ cards(:logo).update!(last_active_at: 1.day.ago - collections(:writebook).auto_close_period)
+ cards(:shipping).update!(last_active_at: 1.day.from_now - collections(:writebook).auto_close_period)
assert_difference -> { Card.closed.count }, +1 do
Card.auto_close_all_due
@@ -28,4 +36,16 @@ class Card::CloseableTest < ActiveSupport::TestCase
assert cards(:logo).reload.closed?
assert_not cards(:shipping).reload.closed?
end
+
+ test "don't auto close those cards where the collection has no auto close period" do
+ cards(:logo, :shipping).each(&:reconsider)
+
+ collections(:writebook).update auto_close_period: nil
+
+ assert_no_difference -> { Card.closed.count } do
+ Card.auto_close_all_due
+ end
+
+ assert_not cards(:logo).reload.closed?
+ end
end