diff --git a/app/admin/pipelines.rb b/app/admin/pipelines.rb index df101f7..5b5791a 100644 --- a/app/admin/pipelines.rb +++ b/app/admin/pipelines.rb @@ -1,6 +1,11 @@ ActiveAdmin.register WarpEngine::Pipeline, as: "Pipeline" do actions :index, :show, :edit, :update + # Without this the edit form cannot save at all: ActiveAdmin hands unpermitted params to + # the model and Rails raises ForbiddenAttributesError. The two fields here are the two + # the form offers; everything else about a pipeline comes from the Woodpecker sync. + permit_params :platform, :software_id + menu parent: "🌀 WarpEngine", priority: 10, label: "🚀 Pipelines" config.sort_order = "repo_name_asc" @@ -48,24 +53,12 @@ ActiveAdmin.register WarpEngine::Pipeline, as: "Pipeline" do collection: WarpEngine::Software.order(:title).map { |s| [ s.title, s.id ] }, include_blank: "- none -", hint: "One pipeline per software. Picking one that another pipeline already " \ - "has moves the link here rather than refusing it." + "has moves the link here — that pipeline is left without a software, " \ + "and the move is written to the log." end f.actions end - controller do - # The reassignment itself is the model's job; this only makes it visible. Without a - # word about it, the other pipeline loses its software with nothing on screen to say - # that it happened. - def update - super - taken = resource.software_taken_from - return if taken.blank? - - flash[:notice] = [ flash[:notice], "Software taken from #{taken.join(', ')}." ].compact.join(" ") - end - end - sidebar "Details", only: :show do attributes_table_for resource do row :id diff --git a/app/models/warp_engine/pipeline.rb b/app/models/warp_engine/pipeline.rb index 8f5013a..5394455 100644 --- a/app/models/warp_engine/pipeline.rb +++ b/app/models/warp_engine/pipeline.rb @@ -55,6 +55,16 @@ module WarpEngine others = Pipeline.where(software_id: software_id).where.not(id: id) @software_taken_from = others.map(&:full_name) + return if @software_taken_from.empty? + + # Logged rather than flashed. The first attempt at this put a message on screen by + # overriding the admin's `update` action, which bypassed the permitted-params path + # and made every pipeline edit fail with ForbiddenAttributesError. A silent + # reassignment is a small problem; an admin page that cannot save is a large one. + Rails.logger.info( + "[WarpEngine::Pipeline] #{full_name} took software #{software_id} from " \ + "#{@software_taken_from.join(', ')}" + ) others.update_all(software_id: nil, updated_at: Time.current) end