Skip to content

Commit bc63dda

Browse files
committed
Allow ExCS admin to set starter project user_id
Specifically to set `Project#user_id` to `nil` to signify a starter (or "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 69c45dd commit bc63dda

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
@@ -218,6 +218,7 @@
218218
name: 'Test Project',
219219
locale: 'fr',
220220
project_type: Project::Types::SCRATCH,
221+
user_id: nil,
221222
components: []
222223
}
223224
}
@@ -259,5 +260,12 @@
259260

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

0 commit comments

Comments
 (0)