Skip to content

Commit 7892057

Browse files
committed
Allow ExCS admin to destroy 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 destroy project request spec to check this works as intended. There are obviously some dangers associated with destroying a starter project, but I think it's still useful for an ExCS admin to be able to do it.
1 parent 8e5d53b commit 7892057

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

app/models/ability.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def define_experience_cs_admin_abilities(user)
107107

108108
can :create, Project
109109
can :update, Project
110+
can :destroy, Project
110111
end
111112

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

spec/models/ability_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144

145145
it { is_expected.to be_able_to(:create, starter_project) }
146146
it { is_expected.to be_able_to(:update, starter_project) }
147+
it { is_expected.to be_able_to(:destroy, starter_project) }
147148
end
148149

149150
# rubocop:disable RSpec/MultipleMemoizedHelpers

spec/requests/projects/destroy_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,29 @@
3636
expect(response).to have_http_status(:forbidden)
3737
end
3838
end
39+
40+
context 'when experience-cs admin deleting a Scratch starter project' do
41+
let(:project) do
42+
create(
43+
:project, {
44+
project_type: Project::Types::SCRATCH,
45+
user_id: nil,
46+
locale: 'en'
47+
}
48+
)
49+
end
50+
let(:experience_cs_admin) { create(:experience_cs_admin_user) }
51+
52+
before do
53+
authenticated_in_hydra_as(experience_cs_admin)
54+
end
55+
56+
it 'deletes the project' do
57+
expect do
58+
delete("/api/projects/#{project.identifier}?project_type=scratch", headers:)
59+
end.to change(Project.unscoped, :count).by(-1)
60+
end
61+
end
3962
end
4063

4164
context 'when no token is given' do

0 commit comments

Comments
 (0)