diff --git a/app/controllers/cards/recovers_controller.rb b/app/controllers/cards/recovers_controller.rb deleted file mode 100644 index b4614bc2a..000000000 --- a/app/controllers/cards/recovers_controller.rb +++ /dev/null @@ -1,7 +0,0 @@ -class Cards::RecoversController < ApplicationController - include CardScoped - - def create - redirect_to @card.recover_abandoned_creation - end -end diff --git a/app/controllers/cards_controller.rb b/app/controllers/cards_controller.rb index db1a0d7e0..7fcd7123e 100644 --- a/app/controllers/cards_controller.rb +++ b/app/controllers/cards_controller.rb @@ -9,7 +9,7 @@ class CardsController < ApplicationController end def create - card = @collection.cards.create! + card = @collection.cards.find_or_create_by!(creator: Current.user, status: "drafted") redirect_to card end @@ -30,7 +30,7 @@ class CardsController < ApplicationController def destroy @card.destroy! - redirect_to @card.collection, notice: ("Card deleted" unless @card.creating?) + redirect_to @card.collection, notice: "Card deleted" end private diff --git a/app/jobs/remove_abandoned_creations_job.rb b/app/jobs/remove_abandoned_creations_job.rb deleted file mode 100644 index 6ca63169d..000000000 --- a/app/jobs/remove_abandoned_creations_job.rb +++ /dev/null @@ -1,7 +0,0 @@ -class RemoveAbandonedCreationsJob < ApplicationJob - def perform - ApplicationRecord.with_each_tenant do |tenant| - Card.remove_abandoned_creations - end - end -end diff --git a/app/models/card/statuses.rb b/app/models/card/statuses.rb index 73d3f122a..f26896b21 100644 --- a/app/models/card/statuses.rb +++ b/app/models/card/statuses.rb @@ -2,38 +2,17 @@ module Card::Statuses extend ActiveSupport::Concern included do - enum :status, %w[ creating drafted published ].index_by(&:itself) + enum :status, %w[ drafted published ].index_by(&:itself) after_create -> { track_event :published }, if: :published? scope :published_or_drafted_by, ->(user) { where(status: :published).or(where(status: :drafted, creator: user)) } end - class_methods do - def remove_abandoned_creations - Card.creating.where(updated_at: ..1.day.ago).destroy_all - end - end - - def can_recover_abandoned_creation? - abandoned_creations.where(updated_at: 1.day.ago..).any? - end - - def recover_abandoned_creation - abandoned_creations.last.tap do |card| - Card.creating.where(creator: creator).excluding(card).destroy_all - end - end - def publish transaction do published! track_event :published end end - - private - def abandoned_creations - Card.creating.where(creator: creator).where("created_at != updated_at").excluding(self) - end end diff --git a/app/views/cards/_container.html.erb b/app/views/cards/_container.html.erb index 5d35d4add..3914f93ff 100644 --- a/app/views/cards/_container.html.erb +++ b/app/views/cards/_container.html.erb @@ -38,7 +38,7 @@ <% if card.published? %> <%= render "cards/container/footer/published", card: card %> - <% elsif card.creating? %> + <% elsif card.drafted? %> <%= render "cards/container/footer/draft", card: card %> <% end %> diff --git a/app/views/cards/container/_status.html.erb b/app/views/cards/container/_status.html.erb index cc093ab06..0eae3a19d 100644 --- a/app/views/cards/container/_status.html.erb +++ b/app/views/cards/container/_status.html.erb @@ -1,12 +1,3 @@ -<% if card.creating? && card.can_recover_abandoned_creation? %> -
- You have an unsaved card. Would you like to continue where you left off? - <%= button_to card_recover_path(card), class: "btn txt-small", data: { turbo_action: "replace" } do %> - Restore - <% end %> -
-<% end %> - <% if card.drafted? %>
This is a draft, it’s only visible to you. diff --git a/app/views/cards/container/footer/_draft.html.erb b/app/views/cards/container/footer/_draft.html.erb index e22d4619b..1c39e6ad0 100644 --- a/app/views/cards/container/footer/_draft.html.erb +++ b/app/views/cards/container/footer/_draft.html.erb @@ -3,6 +3,4 @@ <%= button_to "Create and add another", card_publish_path(card), method: :post, class: "btn btn--reversed", name: "creation_type", value: "add_another", title: "Create and add another (ctrl+shift+enter)", form: { data: { turbo: false } }, data: { controller: "hotkey", action: "keydown.ctrl+shift+enter@document->hotkey#click" } %> - - <%= button_to "Save as a draft", card_path(card), name: "card[status]", value: "drafted", method: :put, class: "btn btn--reversed" %>
diff --git a/app/views/cards/display/common/_meta.html.erb b/app/views/cards/display/common/_meta.html.erb index 77d306198..dd2d8efbd 100644 --- a/app/views/cards/display/common/_meta.html.erb +++ b/app/views/cards/display/common/_meta.html.erb @@ -15,13 +15,9 @@ - <% if card.creating? %> -   - <% else %> - <%= icon_tag "refresh--meta" %> - Updated - <%= local_datetime_tag(card.last_active_at, style: :daysago) %> - <% end %> + <%= icon_tag "refresh--meta" %> + Updated + <%= local_datetime_tag(card.last_active_at, style: :daysago) %> diff --git a/app/views/cards/display/perma/_tags.html.erb b/app/views/cards/display/perma/_tags.html.erb index 6cd87d932..91c112540 100644 --- a/app/views/cards/display/perma/_tags.html.erb +++ b/app/views/cards/display/perma/_tags.html.erb @@ -10,7 +10,7 @@ - <% if card.tags.any? || card.creating? %> + <% if card.tags.any? %>
<% card.tags.each_with_index do |tag, index| %> <%= link_to cards_path(collection_ids: [ card.collection ], tag_ids: [ tag.id ]), diff --git a/app/views/cards/show.html.erb b/app/views/cards/show.html.erb index 5c5549fa4..a300bafff 100644 --- a/app/views/cards/show.html.erb +++ b/app/views/cards/show.html.erb @@ -15,7 +15,7 @@
<%= render "cards/container", card: @card %> - <%= render "cards/messages", card: @card unless @card.creating? %> + <%= render "cards/messages", card: @card unless @card.drafted? %> <%= render "layouts/lightbox" do %> <%= button_to_remove_card_image(@card) if @card.image.attached? %> diff --git a/config/recurring.yml b/config/recurring.yml index 89b43c567..15067065b 100644 --- a/config/recurring.yml +++ b/config/recurring.yml @@ -8,9 +8,6 @@ production: &production auto_postpone_all_due: class: Card::AutoPostponeAllDueJob schedule: every hour at minute 50 - remove_abandoned_creations: - class: RemoveAbandonedCreationsJob - schedule: every hour at minute 59 delete_unused_tags: class: DeleteUnusedTagsJob schedule: every day at 04:02 diff --git a/config/routes.rb b/config/routes.rb index 043c48a03..c8e89fb66 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -71,7 +71,6 @@ Rails.application.routes.draw do resource :triage resource :publish resource :reading - resource :recover resource :watch resource :collection resource :column diff --git a/db/migrate/20251102095019_change_cards_status_default_to_drafted.rb b/db/migrate/20251102095019_change_cards_status_default_to_drafted.rb new file mode 100644 index 000000000..b6b960298 --- /dev/null +++ b/db/migrate/20251102095019_change_cards_status_default_to_drafted.rb @@ -0,0 +1,5 @@ +class ChangeCardsStatusDefaultToDrafted < ActiveRecord::Migration[8.2] + def change + change_column_default :cards, :status, from: "creating", to: "drafted" + end +end diff --git a/db/schema.rb b/db/schema.rb index 3a6bf3b4c..049e45a1a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -144,7 +144,7 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_02_115338) do t.integer "creator_id", null: false t.date "due_on" t.datetime "last_active_at", null: false - t.text "status", default: "creating", null: false + t.text "status", default: "drafted", null: false t.string "title" t.datetime "updated_at", null: false t.index ["collection_id"], name: "index_cards_on_collection_id" diff --git a/db/schema_cache.yml b/db/schema_cache.yml index 755b7cf07..e4c5ab87c 100644 --- a/db/schema_cache.yml +++ b/db/schema_cache.yml @@ -496,7 +496,7 @@ columns: cast_type: *15 sql_type_metadata: *16 'null': false - default: creating + default: drafted default_function: collation: comment: diff --git a/test/controllers/cards/publishes_controller_test.rb b/test/controllers/cards/publishes_controller_test.rb index bddb6e088..c2129d161 100644 --- a/test/controllers/cards/publishes_controller_test.rb +++ b/test/controllers/cards/publishes_controller_test.rb @@ -21,11 +21,12 @@ class Cards::PublishesControllerTest < ActionDispatch::IntegrationTest card.drafted! assert_changes -> { card.reload.published? }, from: false, to: true do - assert_difference -> { Card.creating.count }, +1 do + assert_difference -> { Card.count }, +1 do post card_publish_path(card, creation_type: "add_another") end end - assert_redirected_to Card.creating.last + assert Card.last.drafted? + assert_redirected_to Card.last end end diff --git a/test/controllers/cards_controller_test.rb b/test/controllers/cards_controller_test.rb index 4ee37cc2c..507aac5ed 100644 --- a/test/controllers/cards_controller_test.rb +++ b/test/controllers/cards_controller_test.rb @@ -15,11 +15,23 @@ class CardsControllerTest < ActionDispatch::IntegrationTest assert_response :success end - test "create" do + test "create a new draft" do assert_difference -> { Card.count }, 1 do post collection_cards_path(collections(:writebook)) end - assert_redirected_to card_path(Card.last) + + assert Card.last.drafted? + assert_redirected_to Card.last + end + + test "create resumes existing draft if it exists" do + draft = collections(:writebook).cards.create!(creator: users(:kevin), status: :drafted) + + assert_no_difference -> { Card.count } do + post collection_cards_path(collections(:writebook)) + end + + assert_redirected_to draft end test "show" do diff --git a/test/controllers/recovers_controller_test.rb b/test/controllers/recovers_controller_test.rb deleted file mode 100644 index 91fbf4cf2..000000000 --- a/test/controllers/recovers_controller_test.rb +++ /dev/null @@ -1,18 +0,0 @@ -require "test_helper" - -class Cards::RecoversControllerTest < ActionDispatch::IntegrationTest - setup do - sign_in_as :jz - end - - test "create" do - abandoned_card = collections(:writebook).cards.create! creator: users(:kevin) - abandoned_card.update!(title: "An edited title") - unsaved_card = collections(:writebook).cards.create! creator: users(:kevin) - - post card_recover_path(unsaved_card) - - assert_redirected_to abandoned_card - assert_equal [ abandoned_card ], Card.creating - end -end diff --git a/test/models/card/statuses_test.rb b/test/models/card/statuses_test.rb index 5a3e2cb8b..2ad983790 100644 --- a/test/models/card/statuses_test.rb +++ b/test/models/card/statuses_test.rb @@ -1,12 +1,10 @@ require "test_helper" class Card::StatusesTest < ActiveSupport::TestCase - test "cards start out in a `creating` state" do + test "cards start out in a `drafted` state" do card = collections(:writebook).cards.create! creator: users(:kevin), title: "Newly created card" - assert card.creating? - assert_not_includes Card.published_or_drafted_by(users(:kevin)), card - assert_not_includes Card.published_or_drafted_by(users(:jz)), card + assert card.drafted? end test "cards are only visible to the creator when drafted" do @@ -51,38 +49,4 @@ class Card::StatusesTest < ActiveSupport::TestCase assert_equal card, Event.last.eventable assert_equal "card_published", Event.last.action end - - test "can_recover_abandoned_creation?" do - card = collections(:writebook).cards.create! creator: users(:kevin) - unsaved_card = collections(:writebook).cards.new creator: users(:kevin) - - assert_not unsaved_card.can_recover_abandoned_creation? - - card.update!(title: "Something worth keeping") - assert unsaved_card.can_recover_abandoned_creation? - end - - test "recover_abandoned_creation" do - card_edited = collections(:writebook).cards.create! creator: users(:kevin) - card_edited.update!(title: "Something worth keeping") - - card_not_edited = collections(:writebook).cards.create! creator: users(:kevin) - - assert card_not_edited.can_recover_abandoned_creation? - - assert_equal card_edited, card_not_edited.recover_abandoned_creation - - assert_raises(ActiveRecord::RecordNotFound) { card_not_edited.reload } - end - - test "remove_abandoned_creations" do - card_old = collections(:writebook).cards.create! creator: users(:kevin), updated_at: 2.days.ago - card_recent = collections(:writebook).cards.create! creator: users(:kevin) - - assert_equal 2, Card.creating.count - - Card.remove_abandoned_creations - - assert_equal [ card_recent ], Card.creating - end end