From 5bc28841454bbab10dd1ff5934ecd96f838a8852 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 20 Jan 2026 01:02:16 +0000 Subject: [PATCH 1/2] Initial plan From d140d9ab0a803856ddb654c9f13e1048f21316c0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 20 Jan 2026 01:15:49 +0000 Subject: [PATCH 2/2] Add asset promotion for WorkshopIdea and StoryIdea with tests Co-authored-by: maebeale <7607813+maebeale@users.noreply.github.com> --- app/controllers/stories_controller.rb | 7 +- app/services/story_from_idea_service.rb | 44 +++++++++ app/services/workshop_from_idea_service.rb | 12 ++- app/views/workshop_ideas/edit.html.erb | 17 +++- spec/fixtures/test_image.jpg | Bin 0 -> 41 bytes spec/services/story_from_idea_service_spec.rb | 83 +++++++++++++++++ .../workshop_from_idea_service_spec.rb | 84 ++++++++++++++++++ 7 files changed, 242 insertions(+), 5 deletions(-) create mode 100644 app/services/story_from_idea_service.rb create mode 100644 spec/fixtures/test_image.jpg create mode 100644 spec/services/story_from_idea_service_spec.rb create mode 100644 spec/services/workshop_from_idea_service_spec.rb diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 0e6b8007e..1daed96ba 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -28,7 +28,12 @@ def show end def new - @story = Story.new.decorate + if params[:story_idea_id].present? + @story_idea = StoryIdea.find(params[:story_idea_id]) + @story = StoryFromIdeaService.new(@story_idea, user: current_user).call + else + @story = Story.new + end @story = @story.decorate set_form_variables end diff --git a/app/services/story_from_idea_service.rb b/app/services/story_from_idea_service.rb new file mode 100644 index 000000000..8b1dea621 --- /dev/null +++ b/app/services/story_from_idea_service.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +class StoryFromIdeaService + def initialize(story_idea, user:) + @story_idea = story_idea + @user = user + end + + def call + Story.new(attributes_from_idea).tap do |story| + duplicate_assets(story) + end + end + + private + + attr_reader :story_idea, :user + + def attributes_from_idea + story_idea.attributes.slice( + "title", "body", "youtube_url", + "windows_type_id", "project_id", "workshop_id", "external_workshop_title" + ).merge( + created_by_id: user.id, + updated_by_id: user.id, + story_idea_id: story_idea.id, + published: false + ) + end + + def duplicate_assets(story) + # Duplicate primary asset with correct type + if story_idea.primary_asset&.file&.attached? + story.build_primary_asset(file: story_idea.primary_asset.file.blob) + end + + # Duplicate gallery assets with correct type + story_idea.gallery_assets.each do |gallery_asset| + next unless gallery_asset.file&.attached? + + story.gallery_assets.build(file: gallery_asset.file.blob) + end + end +end diff --git a/app/services/workshop_from_idea_service.rb b/app/services/workshop_from_idea_service.rb index 04d68b1c4..5e89337fa 100644 --- a/app/services/workshop_from_idea_service.rb +++ b/app/services/workshop_from_idea_service.rb @@ -63,8 +63,16 @@ def duplicate_series_children(workshop) end def duplicate_assets(workshop) - workshop_idea.assets.each do |image| - workshop.assets.build(file: image.file.blob) + # Duplicate primary asset with correct type + if workshop_idea.primary_asset&.file&.attached? + workshop.build_primary_asset(file: workshop_idea.primary_asset.file.blob) + end + + # Duplicate gallery assets with correct type + workshop_idea.gallery_assets.each do |gallery_asset| + next unless gallery_asset.file&.attached? + + workshop.gallery_assets.build(file: gallery_asset.file.blob) end end end diff --git a/app/views/workshop_ideas/edit.html.erb b/app/views/workshop_ideas/edit.html.erb index c4e5d622d..525762989 100644 --- a/app/views/workshop_ideas/edit.html.erb +++ b/app/views/workshop_ideas/edit.html.erb @@ -3,8 +3,21 @@

Edit <%= @workshop_idea.class.model_name.human %>

- <%= link_to 'View', workshop_idea_path(@workshop_idea), - class: "btn btn-secondary-outline" %> +
+ <% if @workshop_idea.workshops.any? %> + <% @workshop_idea.workshops.each do |workshop| %> + <%= link_to "View Workshop", workshop_path(workshop), + class: "btn btn-secondary-outline" %> + <% end %> + <% else %> + <% if current_user.super_user && @workshop_idea.persisted? %> + <%= link_to "Promote to Workshop", new_workshop_path(workshop_idea_id: @workshop_idea.id), + class: "admin-only bg-blue-100 btn btn-secondary-outline ms-2" %> + <% end %> + <% end %> + <%= link_to "View", workshop_idea_path(@workshop_idea), + class: "btn btn-secondary-outline" %> +
diff --git a/spec/fixtures/test_image.jpg b/spec/fixtures/test_image.jpg new file mode 100644 index 0000000000000000000000000000000000000000..ea680ea0d5217e73063bc14947d2558f2a0de95f GIT binary patch literal 41 tcmex=