Skip to content

Commit 0148d94

Browse files
committed
Don't allow image_list in create project endpoint
This fixes a problem that was introduced in this commit [1]. The call to `skip_load_resource only: :create` was removed which meant that the call to `load_and_authorize_resource` triggered an attempt to instantiate a `Project` model using the params identified by CanCanCan. This included the `image_list` param which did not exist as an attribute on a `Project` and thus resulted in the following exception: ActiveModel::UnknownAttributeError: unknown attribute 'image_list' for Project. I did initially look at fixing the problem while maintaining the ability to pass the `image_list` into `Project::Create#call`. However, the functionality in `Project::Create#build_project` which loops through the `image_list` was not previously tested and I can't really see that it ever worked. Furthermore, @sra405 has pointed out that we're not currently allowing users to add their own images to a project for safeguarding reasons and so I thought it made more sense to fix the problem by removing support for `image_list` from the create project endpoint for now until we actually need it. /cc @loiswells97 Removing the `image_list` param from the permitted params in `Api::ProjectsController#base_params` should mean it is never included in the params supplied to either CanCanCan's `load_and_authorize_resource` method or to `Project::Create#call`, although it will mean that a warning will appear in the logs. So ideally we'd remove it from the params being supplied by the UI. Note that the images from the projects in the `raspberrypilearning` GitHub organisation [2] are added to a project using a different mechanism and so should not be affected by this change. [1]: 39f45f7
1 parent 80e3c88 commit 0148d94

File tree

3 files changed

+1
-8
lines changed

3 files changed

+1
-8
lines changed

app/controllers/api/projects_controller.rb

-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ def base_params
8484
:project_type,
8585
:locale,
8686
{
87-
image_list: [],
8887
components: %i[id name extension content index default]
8988
}
9089
)

lib/concepts/project/operations/create.rb

+1-6
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,8 @@ def call(project_hash:)
1818

1919
def build_project(project_hash)
2020
identifier = PhraseIdentifier.generate
21-
new_project = Project.new(project_hash.except(:components, :image_list).merge(identifier:))
21+
new_project = Project.new(project_hash.except(:components).merge(identifier:))
2222
new_project.components.build(project_hash[:components])
23-
24-
(project_hash[:image_list] || []).each do |image|
25-
new_project.images.attach(image.blob)
26-
end
27-
2823
new_project
2924
end
3025
end

spec/concepts/project/create_spec.rb

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
content: 'print("hello world")',
2828
default: true
2929
}],
30-
image_list: [],
3130
user_id:
3231
}
3332
end

0 commit comments

Comments
 (0)