Skip to content

Commit 3d2560f

Browse files
authored
Merge pull request #254 from openstax/edit-vocab
no longer consider vocab term exercises special
2 parents 6e6c80b + b8aacce commit 3d2560f

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

app/access_policies/exercise_access_policy.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@ def self.action_allowed?(action, requestor, exercise)
77
true
88
when :create
99
!requestor.is_anonymous? &&
10-
requestor.is_human? &&
11-
exercise.vocab_term_id.nil?
10+
requestor.is_human?
1211
when :read
1312
exercise.is_public? || exercise.has_read_permission?(requestor)
1413
when :update, :destroy
1514
!exercise.is_published? &&
16-
exercise.vocab_term_id.nil? &&
1715
exercise.has_write_permission?(requestor)
1816
when :new_version
1917
exercise.is_published? &&
20-
exercise.vocab_term_id.nil? &&
2118
exercise.has_write_permission?(requestor)
2219
else
2320
false

spec/access_policies/exercise_access_policy_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@
8484

8585
expect(described_class.action_allowed?(:new_version, app, exercise)).to eq false
8686
end
87+
it 'cannot be accessed even by an author' do
88+
author = FactoryBot.create(:author, publication: exercise.publication, user: user)
89+
expect(described_class.action_allowed?(:new_version, user, exercise)).to eq false
90+
end
8791
end
8892

8993
context 'not vocab exercise' do
@@ -116,6 +120,11 @@
116120
expect(described_class.action_allowed?(:update, app, exercise)).to eq false
117121
expect(described_class.action_allowed?(:destroy, app, exercise)).to eq false
118122
end
123+
it 'can be accessed by an author' do
124+
author = FactoryBot.create(:author, publication: exercise.publication, user: user)
125+
expect(described_class.action_allowed?(:update, user, exercise)).to eq true
126+
expect(described_class.action_allowed?(:destroy, user, exercise)).to eq true
127+
end
119128
end
120129

121130
context 'not vocab' do
@@ -197,6 +206,7 @@
197206
exercise.vocab_term = FactoryBot.create :vocab_term
198207
exercise.publication.published_at = Time.now
199208
exercise.publication.save!
209+
exercise.save!
200210
end
201211

202212
it 'cannot be accessed by anyone' do
@@ -206,6 +216,10 @@
206216

207217
expect(described_class.action_allowed?(:new_version, app, exercise)).to eq false
208218
end
219+
it 'can be accessed by an author' do
220+
author = FactoryBot.create(:author, publication: exercise.publication, user: user)
221+
expect(described_class.action_allowed?(:new_version, user, exercise.reload)).to eq true
222+
end
209223
end
210224

211225
context 'not vocab' do

0 commit comments

Comments
 (0)