Skip to content

Commit 38feb5d

Browse files
committed
Allow ExCS admin to update starter projects
This gives users with the "experience-cs-admin" role permission to update starter (or "public") projects (i.e. projects with no `user_id` set). I've added an example to the "Updating a project" feature spec to check this works as intended. Note that in the feature spec, unlike in the other examples, I'm relying on the lookup via `ProjectLoader#load` which I think is the intended use (at least from Experience CS) and this is why I've had to set the project locale to one of the default fallback locales, i.e. 'en', in the spec setup. I haven't attempted to fix the other examples, but I've started looking at that in #553 and plan to address the problem separately.
1 parent bc63dda commit 38feb5d

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

app/models/ability.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def define_experience_cs_admin_abilities(user)
106106
return unless user&.experience_cs_admin?
107107

108108
can :create, Project
109+
can :update, Project
109110
end
110111

111112
def school_teacher_can_manage_lesson?(user:, school:, lesson:)

spec/features/project/updating_a_project_spec.rb

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
end
1111

1212
let(:headers) { { Authorization: UserProfileMock::TOKEN } }
13-
let!(:project) { create(:project, name: 'Test Project', user_id: owner.id) }
13+
let(:project_type) { Project::Types::PYTHON }
14+
let!(:project) { create(:project, name: 'Test Project', user_id: owner.id, locale: 'en', project_type:) }
1415
let(:owner) { create(:owner, school:) }
1516
let(:school) { create(:school) }
1617

@@ -53,4 +54,26 @@
5354
put("/api/projects/#{project.id}", params:)
5455
expect(response).to have_http_status(:unauthorized)
5556
end
57+
58+
context 'when the user is an Experience CS admin and project type is scratch' do
59+
let(:experience_cs_admin) { create(:experience_cs_admin_user) }
60+
let(:project_type) { Project::Types::SCRATCH }
61+
let(:params) { { project: { name: 'Test Project' } } }
62+
63+
before do
64+
authenticated_in_hydra_as(experience_cs_admin)
65+
end
66+
67+
it 'responds 200 OK' do
68+
put("/api/projects/#{project.identifier}?project_type=scratch", headers:, params:)
69+
expect(response).to have_http_status(:success)
70+
end
71+
72+
it 'sets the project name to the specified value' do
73+
put("/api/projects/#{project.identifier}?project_type=scratch", headers:, params:)
74+
data = JSON.parse(response.body, symbolize_names: true)
75+
76+
expect(data[:name]).to eq('Test Project')
77+
end
78+
end
5679
end

spec/models/ability_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
let(:user) { build(:experience_cs_admin_user) }
144144

145145
it { is_expected.to be_able_to(:create, starter_project) }
146+
it { is_expected.to be_able_to(:update, starter_project) }
146147
end
147148

148149
# rubocop:disable RSpec/MultipleMemoizedHelpers

0 commit comments

Comments
 (0)