Skip to content

Commit 790493e

Browse files
author
Tim Standen
committed
[F] Add external identifier attribute to relevant APIs
1 parent 93e0bb6 commit 790493e

File tree

7 files changed

+92
-57
lines changed

7 files changed

+92
-57
lines changed

api/app/controllers/api/v1/journals_controller.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ def scope_visibility
5656

5757
Journal.all
5858
end
59+
60+
private
61+
62+
def journal_params
63+
params.require(:data)
64+
attributes = [:title, :subtitle, :hashtag, :description, :facebook_id, :twitter_id,
65+
:instagram_id, :remove_avatar, attachment(:avatar),
66+
attachment(:hero), attachment(:logo), :remove_hero, :draft,
67+
:remove_logo, metadata(Journal), :avatar_color, :pending_slug,
68+
{ tag_list: [] }, :image_credits, :social_description,
69+
attachment(:custom_icon), :hero_layout, :remove_custom_icon,
70+
:social_title, attachment(:social_image), :remove_social_image,
71+
:hero_background_color, :show_on_homepage, :home_page_priority, :external_identifier]
72+
73+
relationships = [:collaborators, :creators, :contributors, :subjects]
74+
param_config = structure_params(attributes: attributes, relationships: relationships)
75+
params.permit(param_config)
76+
end
5977
end
6078
end
6179
end

api/app/controllers/api/v1/project_collections/relationships/collection_projects_controller.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ def location
5656
def includes
5757
%w()
5858
end
59+
60+
def collection_project_params
61+
params.require(:data)
62+
attributes = [:position]
63+
relationships = []
64+
param_config = structure_params(attributes: attributes, relationships: relationships)
65+
params.permit(param_config)
66+
end
5967
end
6068
end
6169
end

api/app/controllers/api/v1/project_collections_controller.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,21 @@ def scope_for_project_collections
6666
[:subjects, :collection_projects]
6767
)
6868
end
69+
70+
private
71+
72+
def project_collection_params
73+
params.require(:data)
74+
attributes = [:title, :sort_order, :visible, :homepage, :smart, :position, :icon,
75+
{ tag_list: [] }, :number_of_projects, :featured_only, :description, :short_description,
76+
:pending_slug, :homepage_start_date, :homepage_end_date,
77+
:homepage_count, :social_description, attachment(:custom_icon),
78+
attachment(:hero), :hero_layout, :remove_hero, :remove_custom_icon,
79+
:social_title, attachment(:social_image), :remove_social_image, :external_identifier]
80+
relationships = [:projects, :subjects]
81+
param_config = structure_params(attributes: attributes, relationships: relationships)
82+
params.permit(param_config)
83+
end
6984
end
7085
end
7186
end

api/app/controllers/api/v1/projects_controller.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,27 @@ def scope_visibility
6868

6969
Project.existing.all
7070
end
71+
72+
private
73+
74+
def project_params
75+
params.require(:data)
76+
attributes = [:title, :subtitle, :featured, :hashtag, :description, :purchase_url,
77+
:purchase_price_currency, :facebook_id, :purchase_call_to_action, :twitter_id,
78+
:hide_activity, :instagram_id, :remove_avatar, attachment(:avatar),
79+
attachment(:hero), :download_url, attachment(:cover), :remove_hero, :draft,
80+
:remove_cover, :download_call_to_action, :publication_date, metadata(Project),
81+
:avatar_color, { tag_list: [] }, :dark_mode, :image_credits,
82+
:standalone_mode, :standalone_mode_press_bar_text, :restricted_access,
83+
:standalone_mode_press_bar_url, :finished, :restricted_access_heading,
84+
:restricted_access_body, :open_access, :disable_engagement,
85+
:journal_issue_pending_sort_title, :journal_issue_number, :pending_slug,
86+
:social_title, attachment(:social_image), :remove_social_image,
87+
:social_description, :external_identifier]
88+
relationships = [:collaborators, :creators, :contributors, :subjects, :journal_volume]
89+
param_config = structure_params(attributes: attributes, relationships: relationships)
90+
params.permit(param_config)
91+
end
7192
end
7293
end
7394
end

api/app/controllers/concerns/validation.rb

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -69,41 +69,6 @@ def reading_group_params
6969
params.permit(param_config)
7070
end
7171

72-
def project_params
73-
params.require(:data)
74-
attributes = [:title, :subtitle, :featured, :hashtag, :description, :purchase_url,
75-
:purchase_price_currency, :facebook_id, :purchase_call_to_action, :twitter_id,
76-
:hide_activity, :instagram_id, :remove_avatar, attachment(:avatar),
77-
attachment(:hero), :download_url, attachment(:cover), :remove_hero, :draft,
78-
:remove_cover, :download_call_to_action, :publication_date, metadata(Project),
79-
:avatar_color, { tag_list: [] }, :dark_mode, :image_credits,
80-
:standalone_mode, :standalone_mode_press_bar_text, :restricted_access,
81-
:standalone_mode_press_bar_url, :finished, :restricted_access_heading,
82-
:restricted_access_body, :open_access, :disable_engagement,
83-
:journal_issue_pending_sort_title, :journal_issue_number, :pending_slug,
84-
:social_title, attachment(:social_image), :remove_social_image,
85-
:social_description]
86-
relationships = [:collaborators, :creators, :contributors, :subjects, :journal_volume]
87-
param_config = structure_params(attributes: attributes, relationships: relationships)
88-
params.permit(param_config)
89-
end
90-
91-
def journal_params
92-
params.require(:data)
93-
attributes = [:title, :subtitle, :hashtag, :description, :facebook_id, :twitter_id,
94-
:instagram_id, :remove_avatar, attachment(:avatar),
95-
attachment(:hero), attachment(:logo), :remove_hero, :draft,
96-
:remove_logo, metadata(Journal), :avatar_color, :pending_slug,
97-
{ tag_list: [] }, :image_credits, :social_description,
98-
attachment(:custom_icon), :hero_layout, :remove_custom_icon,
99-
:social_title, attachment(:social_image), :remove_social_image,
100-
:hero_background_color, :show_on_homepage, :home_page_priority]
101-
102-
relationships = [:collaborators, :creators, :contributors, :subjects]
103-
param_config = structure_params(attributes: attributes, relationships: relationships)
104-
params.permit(param_config)
105-
end
106-
10772
def journal_volume_params
10873
params.require(:data)
10974
attributes = [:number, :pending_slug]
@@ -166,27 +131,6 @@ def resource_collection_params
166131
params.permit(param_config)
167132
end
168133

169-
def project_collection_params
170-
params.require(:data)
171-
attributes = [:title, :sort_order, :visible, :homepage, :smart, :position, :icon,
172-
{ tag_list: [] }, :number_of_projects, :featured_only, :description, :short_description,
173-
:pending_slug, :homepage_start_date, :homepage_end_date,
174-
:homepage_count, :social_description, attachment(:custom_icon),
175-
attachment(:hero), :hero_layout, :remove_hero, :remove_custom_icon,
176-
:social_title, attachment(:social_image), :remove_social_image]
177-
relationships = [:projects, :subjects]
178-
param_config = structure_params(attributes: attributes, relationships: relationships)
179-
params.permit(param_config)
180-
end
181-
182-
def collection_project_params
183-
params.require(:data)
184-
attributes = [:position]
185-
relationships = []
186-
param_config = structure_params(attributes: attributes, relationships: relationships)
187-
params.permit(param_config)
188-
end
189-
190134
def action_callout_params
191135
params.require(:data)
192136
attributes = [:title, :kind, :location, :button, :position, :remove_attachment, :url,
@@ -521,7 +465,7 @@ def analytics_params
521465

522466
def user_group_params
523467
params.require(:data)
524-
attributes = [:name]
468+
attributes = %i[name external_identifier]
525469
relationships = %i[members entitleables]
526470
param_config = structure_params(attributes: attributes, relationships: relationships)
527471
params.permit(param_config)

api/spec/requests/project_collections_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,21 @@
7676
post path, headers: admin_headers, params: valid_params
7777
expect(response).to have_http_status(:created)
7878
end
79+
80+
context "when the user submits an external identifier" do
81+
let(:headers) { admin_headers }
82+
83+
it "creates an external identifier" do
84+
params = build_json_payload(
85+
attributes: { title: "foo", external_identifier: "SKU123" },
86+
relationships: relationships
87+
)
88+
89+
expect do
90+
post path, headers: headers, params: params
91+
end.to change(ExternalIdentifier, :count).by 1
92+
end
93+
end
7994
end
8095

8196
describe "updates a collection" do

api/spec/requests/projects_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,20 @@
9898
expect(response).to have_http_status(:forbidden)
9999
end
100100
end
101+
102+
context "when the user submits an external identifier" do
103+
let(:headers) { admin_headers }
104+
105+
it "creates an external identifier" do
106+
params = build_json_payload(
107+
attributes: { title: "foo", external_identifier: "SKU123" }
108+
)
109+
110+
expect do
111+
post path, headers: headers, params: params
112+
end.to change(ExternalIdentifier, :count).by 1
113+
end
114+
end
101115
end
102116

103117
describe "updates a project" do

0 commit comments

Comments
 (0)