Skip to content

Commit 9753062

Browse files
committed
Introduce permission for updating public projects
I plan to use this to restrict updating public projects to experience-cs admin users.
1 parent 7986f0a commit 9753062

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

app/models/ability.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ def define_school_student_abilities(user:, school:)
103103
end
104104

105105
def define_experience_cs_admin_abilities(user)
106-
can :create, :public_project if user.experience_cs_admin?
106+
return unless user.experience_cs_admin?
107+
108+
can :create, :public_project
109+
can :update, :public_project
107110
end
108111

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

spec/models/ability_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
end
3232

3333
it { is_expected.not_to be_able_to(:create, :public_project) }
34+
it { is_expected.not_to be_able_to(:update, :public_project) }
3435
end
3536

3637
context 'with a standard user' do
@@ -60,6 +61,7 @@
6061
end
6162

6263
it { is_expected.not_to be_able_to(:create, :public_project) }
64+
it { is_expected.not_to be_able_to(:update, :public_project) }
6365
end
6466

6567
context 'with a teacher' do
@@ -89,6 +91,7 @@
8991
end
9092

9193
it { is_expected.not_to be_able_to(:create, :public_project) }
94+
it { is_expected.not_to be_able_to(:update, :public_project) }
9295
end
9396

9497
context 'with an owner' do
@@ -118,6 +121,7 @@
118121
end
119122

120123
it { is_expected.not_to be_able_to(:create, :public_project) }
124+
it { is_expected.not_to be_able_to(:update, :public_project) }
121125
end
122126

123127
context 'with a student' do
@@ -147,12 +151,14 @@
147151
end
148152

149153
it { is_expected.not_to be_able_to(:create, :public_project) }
154+
it { is_expected.not_to be_able_to(:update, :public_project) }
150155
end
151156

152157
context 'with an experience-cs admin' do
153158
let(:user) { build(:experience_cs_admin_user) }
154159

155160
it { is_expected.to be_able_to(:create, :public_project) }
161+
it { is_expected.to be_able_to(:update, :public_project) }
156162
end
157163

158164
# rubocop:disable RSpec/MultipleMemoizedHelpers

0 commit comments

Comments
 (0)