Skip to content

Commit 910105d

Browse files
committed
Allow experience-cs admin to set project user_id
Specifically to set `Project#user_id` to `nil` to signify a "public" project which can be viewed by anonymous users. The logic in `Api::ProjectsController#project_params` is a bit hard to follow. However, essentially we need to avoid the `base_params.merge(user_id: current_user&.id)` line in the `else` branch to avoid `Project#user_id` being set to the current user's ID.
1 parent c0af46a commit 910105d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

app/controllers/api/projects_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ def load_projects
8080
end
8181

8282
def project_params
83-
if school_owner?
84-
# A school owner must specify who the project user is.
83+
if school_owner? || current_user&.experience_cs_admin?
84+
# A school owner or an Experience CS admin must specify who the project user is.
8585
base_params
8686
else
8787
# A school teacher may only create projects they own.

spec/features/project/creating_a_project_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@
217217
name: 'Test Project',
218218
locale: 'fr',
219219
project_type: Project::Types::SCRATCH,
220+
user_id: nil,
220221
components: []
221222
}
222223
}
@@ -258,5 +259,12 @@
258259

259260
expect(data[:project_type]).to eq(Project::Types::SCRATCH)
260261
end
262+
263+
it 'sets the project user_id to the specified value (i.e. nil to represent a public project)' do
264+
post('/api/projects', headers:, params:)
265+
data = JSON.parse(response.body, symbolize_names: true)
266+
267+
expect(data[:user_id]).to be_nil
268+
end
261269
end
262270
end

0 commit comments

Comments
 (0)