Skip to content

Commit bc3eac4

Browse files
committed
WIP
1 parent 127d5ed commit bc3eac4

5 files changed

Lines changed: 32 additions & 1 deletion

File tree

app/controllers/admin/editions_controller.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class Admin::EditionsController < Admin::BaseController
44

55
before_action :remove_blank_parameters
66
before_action :clean_edition_parameters, only: %i[create update]
7+
before_action :destroy_blank_social_media_accounts, only: %i[create update]
78
before_action :clear_scheduled_publication_if_not_activated, only: %i[create update]
89
before_action :clear_response_form_file_cache, only: %i[create update]
910
before_action :find_edition, only: %i[show edit update revise diff confirm_destroy destroy update_bypass_id update_image_display_option]
@@ -291,6 +292,7 @@ def permitted_edition_attributes
291292
default_news_image_attributes: %i[file file_cache id],
292293
nation_inapplicabilities_attributes: %i[id nation_id alternative_url excluded],
293294
fatality_notice_casualties_attributes: %i[id personal_details _destroy],
295+
social_media_accounts_attributes: %i[social_media_service_id url title _destroy id],
294296
document_attributes: [
295297
:id,
296298
:slug,
@@ -469,6 +471,16 @@ def clean_edition_parameters
469471
end
470472
end
471473

474+
def destroy_blank_social_media_accounts
475+
if edition_params[:social_media_accounts_attributes]
476+
edition_params[:social_media_accounts_attributes].each_pair do |_key, account|
477+
if account[:social_media_service_id].blank? && account[:url].blank? && account[:title].blank?
478+
account[:_destroy] = "1"
479+
end
480+
end
481+
end
482+
end
483+
472484
def clear_scheduled_publication_if_not_activated
473485
if params[:scheduled_publication_active] && params[:scheduled_publication_active].to_i.zero?
474486
edition_params.keys.each do |key|

app/controllers/admin/standard_editions_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
class Admin::StandardEditionsController < Admin::EditionsController
33
rescue_from ConfigurableDocumentType::NotFoundError, with: :render_not_found
44

5+
def social_media_accounts
6+
find_edition
7+
@edition.social_media_accounts.build if @edition.social_media_accounts.empty?
8+
end
9+
510
def choose_type
611
@permitted_configurable_document_types = ConfigurableDocumentType.where_group(params[:group])
712
.select { |type| can?(current_user, type) }

app/models/standard_edition.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class StandardEdition < Edition
88
include Edition::WorldLocations
99
include Edition::Organisations
1010
include Edition::WorldwideOrganisations
11+
include Edition::SocialMediaAccounts
1112
include HasBlockContent
1213
include StandardEdition::DefaultLeadImage
1314

@@ -63,6 +64,11 @@ def allows_file_attachments?
6364
type_instance.settings["file_attachments_enabled"]
6465
end
6566

67+
def can_be_associated_with_social_media_accounts?
68+
edit_screens = type_instance.settings.dig("edit_screens")
69+
edit_screens&.key?("social_media_accounts")
70+
end
71+
6672
def can_be_marked_political?
6773
type_instance.settings["history_mode_enabled"]
6874
end

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ def redirect(path, options = { prefix: Whitehall.router_prefix })
303303
get :change_type
304304
get :change_type_preview
305305
patch :apply_change_type
306+
get :social_media_accounts
306307
end
307308

308309
resources :translations, controller: "standard_edition_translations", except: %i[index show create] do

public/configurable-document-type.schema.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@
218218
"properties": {
219219
"edit_screens": {
220220
"type": "object",
221-
"description": "A list of rendered screens (tabs) for the content type. Controls which content blocks appear on which editing screens (document, images).",
221+
"description": "A list of rendered screens (tabs) for the content type. Controls which content blocks appear on which editing screens (document, images, social_media_accounts).",
222222
"properties": {
223223
"document": {
224224
"type": "array",
@@ -233,6 +233,13 @@
233233
"items": {
234234
"type": "string"
235235
}
236+
},
237+
"social_media_accounts": {
238+
"type": "array",
239+
"description": "A list of content blocks to display on the social media accounts editing screen. Usually empty as social media accounts are managed through a separate interface.",
240+
"items": {
241+
"type": "string"
242+
}
236243
}
237244
},
238245
"additionalProperties": false

0 commit comments

Comments
 (0)