diff --git a/app/controllers/cards/drafts_controller.rb b/app/controllers/cards/drafts_controller.rb new file mode 100644 index 000000000..a4e9388de --- /dev/null +++ b/app/controllers/cards/drafts_controller.rb @@ -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 diff --git a/app/controllers/cards/publishes_controller.rb b/app/controllers/cards/publishes_controller.rb index 641f728cd..a0378eec3 100644 --- a/app/controllers/cards/publishes_controller.rb +++ b/app/controllers/cards/publishes_controller.rb @@ -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 diff --git a/app/controllers/cards_controller.rb b/app/controllers/cards_controller.rb index e79eeb22b..e007527b8 100644 --- a/app/controllers/cards_controller.rb +++ b/app/controllers/cards_controller.rb @@ -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 diff --git a/app/views/cards/_container.html.erb b/app/views/cards/_container.html.erb index c85236683..d66996f96 100644 --- a/app/views/cards/_container.html.erb +++ b/app/views/cards/_container.html.erb @@ -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 %> diff --git a/app/views/cards/drafts/_container.html.erb b/app/views/cards/drafts/_container.html.erb new file mode 100644 index 000000000..c74326544 --- /dev/null +++ b/app/views/cards/drafts/_container.html.erb @@ -0,0 +1,34 @@ +
+ <% cache card do %> +
+ <%= render "cards/container/image", card: card %> +
+ +
+ <%= card_article_tag card, class: "card" do %> +
+ <%= render "cards/display/perma/board", card: card %> + <%= render "cards/display/perma/tags", card: card %> +
+ +
+
+ <%= render "cards/container/content", card: card %> + <%= render "cards/display/perma/steps", card: card %> +
+
+ + + <% end %> +
+ <% end %> + + <% if Fizzy.saas? %> + <%= render "cards/container/footer/saas/create", card: card %> + <% else %> + <%= render "cards/container/footer/create", card: card %> + <% end %> +
diff --git a/app/views/cards/drafts/show.html.erb b/app/views/cards/drafts/show.html.erb new file mode 100644 index 000000000..d670f4c2f --- /dev/null +++ b/app/views/cards/drafts/show.html.erb @@ -0,0 +1,16 @@ +<% @page_title = @card.title %> +<% @header_class = "header--card" %> + +<% content_for :header do %> +
+ <%= link_back_to_board(@card.board) %> +
+<% end %> + +
+ <%= render "cards/drafts/container", card: @card %> + + <%= render "layouts/lightbox" do %> + <%= button_to_remove_card_image(@card) if @card.image.attached? %> + <% end %> +
diff --git a/app/views/cards/show.html.erb b/app/views/cards/show.html.erb index 596006ce8..bfaa9c676 100644 --- a/app/views/cards/show.html.erb +++ b/app/views/cards/show.html.erb @@ -16,7 +16,7 @@
<%= 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? %> diff --git a/config/routes.rb b/config/routes.rb index d84fa06e3..0fd75fd98 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/saas/test/controllers/accounts/subscriptions/card_creation_test.rb b/saas/test/controllers/accounts/subscriptions/card_creation_test.rb index dd5e72826..1ddc4bc1c 100644 --- a/saas/test/controllers/accounts/subscriptions/card_creation_test.rb +++ b/saas/test/controllers/accounts/subscriptions/card_creation_test.rb @@ -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 /you’ve 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 /you’ve 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 diff --git a/test/controllers/cards/drafts_controller_test.rb b/test/controllers/cards/drafts_controller_test.rb new file mode 100644 index 000000000..8d14f3fff --- /dev/null +++ b/test/controllers/cards/drafts_controller_test.rb @@ -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 diff --git a/test/controllers/cards/publishes_controller_test.rb b/test/controllers/cards/publishes_controller_test.rb index 4de6d20bb..537a6f73b 100644 --- a/test/controllers/cards/publishes_controller_test.rb +++ b/test/controllers/cards/publishes_controller_test.rb @@ -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 diff --git a/test/controllers/cards_controller_test.rb b/test/controllers/cards_controller_test.rb index d13affa96..11c4b62a5 100644 --- a/test/controllers/cards_controller_test.rb +++ b/test/controllers/cards_controller_test.rb @@ -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