Merge pull request #2306 from basecamp/draft-new

Use a dedicated resource for showing cards in draft mode
This commit is contained in:
Jorge Manrubia
2026-01-08 17:30:19 +01:00
committed by GitHub
12 changed files with 109 additions and 17 deletions
@@ -0,0 +1,13 @@
class Cards::DraftsController < ApplicationController
include CardScoped
before_action :redirect_if_published
def show
end
private
def redirect_if_published
redirect_to @card unless @card.drafted?
end
end
@@ -5,7 +5,8 @@ class Cards::PublishesController < ApplicationController
@card.publish
if add_another_param?
redirect_to @board.cards.create!, notice: "Card added"
card = @board.cards.create!(status: :drafted)
redirect_to card_draft_path(card), notice: "Card added"
else
redirect_to @card.board
end
+6 -1
View File
@@ -3,6 +3,7 @@ class CardsController < ApplicationController
before_action :set_board, only: %i[ create ]
before_action :set_card, only: %i[ show edit update destroy ]
before_action :redirect_if_drafted, only: :show
before_action :ensure_permission_to_administer_card, only: %i[ destroy ]
def index
@@ -13,7 +14,7 @@ class CardsController < ApplicationController
respond_to do |format|
format.html do
card = Current.user.draft_new_card_in(@board)
redirect_to card
redirect_to card_draft_path(card)
end
format.json do
@@ -56,6 +57,10 @@ class CardsController < ApplicationController
@card = Current.user.accessible_cards.find_by!(number: params[:id])
end
def redirect_if_drafted
redirect_to card_draft_path(@card) if @card.drafted?
end
def ensure_permission_to_administer_card
head :forbidden unless Current.user.can_administer_card?(@card)
end
-6
View File
@@ -37,11 +37,5 @@
<% if card.published? %>
<%= render "cards/container/footer/published", card: card %>
<% elsif card.drafted? %>
<% if Fizzy.saas? %>
<%= render "cards/container/footer/saas/create", card: card %>
<% else %>
<%= render "cards/container/footer/create", card: card %>
<% end %>
<% end %>
</section>
@@ -0,0 +1,34 @@
<section id="<%= dom_id(card, :card_container) %>" class="card-perma" style="--card-color: <%= card.color %>;">
<% cache card do %>
<div class="card-perma__actions card-perma__actions--left">
<%= render "cards/container/image", card: card %>
</div>
<div class="card-perma__bg">
<%= card_article_tag card, class: "card" do %>
<header class="card__header">
<%= render "cards/display/perma/board", card: card %>
<%= render "cards/display/perma/tags", card: card %>
</header>
<div class="card__body justify-space-between">
<div class="card__content">
<%= render "cards/container/content", card: card %>
<%= render "cards/display/perma/steps", card: card %>
</div>
</div>
<footer class="card__footer full-width flex align-start gap">
<%= render "cards/display/perma/meta", card: card %>
<%= render "cards/display/perma/background", card: card %>
</footer>
<% end %>
</div>
<% end %>
<% if Fizzy.saas? %>
<%= render "cards/container/footer/saas/create", card: card %>
<% else %>
<%= render "cards/container/footer/create", card: card %>
<% end %>
</section>
+16
View File
@@ -0,0 +1,16 @@
<% @page_title = @card.title %>
<% @header_class = "header--card" %>
<% content_for :header do %>
<div class="header__actions header__actions--start">
<%= link_back_to_board(@card.board) %>
</div>
<% end %>
<div data-controller="beacon lightbox" data-beacon-url-value="<%= card_reading_path(@card) %>">
<%= render "cards/drafts/container", card: @card %>
<%= render "layouts/lightbox" do %>
<%= button_to_remove_card_image(@card) if @card.image.attached? %>
<% end %>
</div>
+1 -1
View File
@@ -16,7 +16,7 @@
<div data-controller="beacon lightbox" data-beacon-url-value="<%= card_reading_path(@card) %>">
<%= render "cards/container", card: @card %>
<%= render "cards/messages", card: @card unless @card.drafted? %>
<%= render "cards/messages", card: @card %>
<%= render "layouts/lightbox" do %>
<%= button_to_remove_card_image(@card) if @card.image.attached? %>
+1
View File
@@ -71,6 +71,7 @@ Rails.application.routes.draw do
resources :cards do
scope module: :cards do
resource :draft, only: :show
resource :board
resource :closure
resource :column
@@ -10,7 +10,7 @@ class Account::Subscriptions::CardCreationTest < ActionDispatch::IntegrationTest
test "admin sees nearing card limit notice" do
accounts(:initech).update_column(:cards_count, 950)
get card_path(cards(:unfinished_thoughts), script_name: accounts(:initech).slug)
get card_draft_path(cards(:unfinished_thoughts), script_name: accounts(:initech).slug)
assert_response :success
assert_match /upgrade to unlimited/i, response.body
@@ -19,7 +19,7 @@ class Account::Subscriptions::CardCreationTest < ActionDispatch::IntegrationTest
test "admin sees nearing storage limit notice" do
Account.any_instance.stubs(:bytes_used).returns(600.megabytes)
get card_path(cards(:unfinished_thoughts), script_name: accounts(:initech).slug)
get card_draft_path(cards(:unfinished_thoughts), script_name: accounts(:initech).slug)
assert_response :success
assert_match /upgrade to get more/i, response.body
@@ -30,7 +30,7 @@ class Account::Subscriptions::CardCreationTest < ActionDispatch::IntegrationTest
test "admin sees exceeding card limit notice" do
accounts(:initech).update_column(:cards_count, 1001)
get card_path(cards(:unfinished_thoughts), script_name: accounts(:initech).slug)
get card_draft_path(cards(:unfinished_thoughts), script_name: accounts(:initech).slug)
assert_response :success
assert_match /youve used your.*free cards/i, response.body
@@ -39,7 +39,7 @@ class Account::Subscriptions::CardCreationTest < ActionDispatch::IntegrationTest
test "admin sees exceeding storage limit notice" do
Account.any_instance.stubs(:bytes_used).returns(1.1.gigabytes)
get card_path(cards(:unfinished_thoughts), script_name: accounts(:initech).slug)
get card_draft_path(cards(:unfinished_thoughts), script_name: accounts(:initech).slug)
assert_response :success
assert_match /youve run out of.*free storage/i, response.body
@@ -64,7 +64,7 @@ class Account::Subscriptions::CardCreationTest < ActionDispatch::IntegrationTest
test "comped account under limits sees no notices" do
accounts(:initech).comp
get card_path(cards(:unfinished_thoughts), script_name: accounts(:initech).slug)
get card_draft_path(cards(:unfinished_thoughts), script_name: accounts(:initech).slug)
assert_response :success
assert_no_match /upgrade/i, response.body
@@ -0,0 +1,21 @@
require "test_helper"
class Cards::DraftsControllerTest < ActionDispatch::IntegrationTest
setup do
sign_in_as :kevin
end
test "show" do
card = boards(:writebook).cards.create!(creator: users(:kevin), status: :drafted)
get card_draft_path(card)
assert_response :success
end
test "show redirects to card when published" do
card = cards(:logo)
get card_draft_path(card)
assert_redirected_to card
end
end
@@ -28,6 +28,6 @@ class Cards::PublishesControllerTest < ActionDispatch::IntegrationTest
new_card = Card.last
assert new_card.drafted?
assert_redirected_to new_card
assert_redirected_to card_draft_path(new_card)
end
end
+9 -2
View File
@@ -21,7 +21,7 @@ class CardsControllerTest < ActionDispatch::IntegrationTest
end
card = Card.last
assert_redirected_to card
assert_redirected_to card_draft_path(card)
assert card.drafted?
end
@@ -31,10 +31,17 @@ class CardsControllerTest < ActionDispatch::IntegrationTest
assert_no_difference -> { Card.count } do
post board_cards_path(boards(:writebook))
assert_redirected_to draft
assert_redirected_to card_draft_path(draft)
end
end
test "show redirects to draft when card is drafted" do
card = boards(:writebook).cards.create!(creator: users(:kevin), status: :drafted)
get card_path(card)
assert_redirected_to card_draft_path(card)
end
test "show" do
get card_path(cards(:logo))
assert_response :success