-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8445 from alphagov/add-ability-for-user-to-select…
…-lead-image Add ability for user to select lead image for case studies and news articles
- Loading branch information
Showing
16 changed files
with
326 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
class Admin::EditionLeadImagesController < Admin::BaseController | ||
before_action :find_edition, :find_image, :enforce_permissions! | ||
layout "design_system" | ||
|
||
def update | ||
edition_lead_image = @edition.edition_lead_image || @edition.build_edition_lead_image | ||
edition_lead_image.assign_attributes(edition_lead_image_params) | ||
|
||
if updater.can_perform? && edition_lead_image.save! | ||
updater.perform! | ||
redirect_to admin_edition_images_path(@edition), notice: "Lead image updated to #{@image.image_data.carrierwave_image}" | ||
else | ||
redirect_to admin_edition_images_path(@edition), alert: updater.failure_reason | ||
end | ||
end | ||
|
||
private | ||
|
||
def find_edition | ||
edition = Edition.find(params[:edition_id]) | ||
@edition = LocalisedModel.new(edition, edition.primary_locale) | ||
end | ||
|
||
def find_image | ||
@image = @edition.images.find(params[:id]) | ||
end | ||
|
||
def enforce_permissions! | ||
enforce_permission!(:update, @edition) | ||
end | ||
|
||
def edition_lead_image_params | ||
{ | ||
image_id: @image.id, | ||
edition_attributes: { | ||
id: @edition.id, | ||
image_display_option: "custom_image", | ||
}, | ||
} | ||
end | ||
|
||
def updater | ||
@updater ||= Whitehall.edition_services.draft_updater(@edition) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
class EditionLeadImage < ApplicationRecord | ||
belongs_to :edition | ||
belongs_to :image | ||
|
||
accepts_nested_attributes_for :edition | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.