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? %> -
-<% end %> - <% if card.drafted? %> 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 @@