Skip to content

Commit e9afed4

Browse files
committed
fix: allow teacher access to student project context
1 parent 6739e96 commit e9afed4

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

app/models/ability.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def define_school_teacher_abilities(user:, school:)
9898
school_class_id: ClassTeacher.where(teacher_id: user.id).select(:school_class_id)
9999
)
100100
).pluck(:id)
101-
can(%i[read], Project, remixed_from_id: teacher_project_ids)
101+
can(%i[read show_context], Project, remixed_from_id: teacher_project_ids)
102102
can(%i[show_status unsubmit return complete], SchoolProject, project: { remixed_from_id: teacher_project_ids })
103103
can(%i[read create destroy], Feedback, school_project: { project: { remixed_from_id: teacher_project_ids } })
104104
can(%i[exchange_code], :google_auth)

spec/models/ability_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@
338338
let(:user) { create(:teacher, school:) }
339339

340340
it { is_expected.not_to be_able_to(:read, remixed_project) }
341+
it { is_expected.not_to be_able_to(:show_context, remixed_project) }
341342
it { is_expected.not_to be_able_to(:create, feedback) }
342343
it { is_expected.not_to be_able_to(:read, feedback) }
343344
it { is_expected.not_to be_able_to(:set_read, feedback) }
@@ -356,6 +357,7 @@
356357
let(:user) { teacher }
357358

358359
it { is_expected.to be_able_to(:read, remixed_project) }
360+
it { is_expected.to be_able_to(:show_context, remixed_project) }
359361
it { is_expected.to be_able_to(:create, feedback) }
360362
it { is_expected.to be_able_to(:read, feedback) }
361363
it { is_expected.not_to be_able_to(:set_read, feedback) }
@@ -382,6 +384,7 @@
382384
it { is_expected.to be_able_to(:update, original_project) }
383385

384386
it { is_expected.to be_able_to(:read, remixed_project) }
387+
it { is_expected.to be_able_to(:show_context, remixed_project) }
385388
it { is_expected.not_to be_able_to(:create, remixed_project) }
386389
it { is_expected.not_to be_able_to(:update, remixed_project) }
387390
it { is_expected.not_to be_able_to(:destroy, remixed_project) }

spec/requests/projects/show_context_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,37 @@
7575
end
7676
end
7777

78+
context 'when loading a student remix context for a lesson the teacher teaches' do
79+
let(:student) { create(:student, school:) }
80+
let!(:project) { create(:project, :with_instructions, school:, lesson:, user_id: teacher.id, locale: nil) }
81+
let!(:student_remix) { create(:project, school:, user_id: student.id, remixed_from_id: project.id, locale: nil) }
82+
let(:expected_context_json) do
83+
{
84+
identifier: student_remix.identifier,
85+
project_type: project.project_type,
86+
school_id: school.id,
87+
lesson_id: lesson.id,
88+
class_id: school_class.id
89+
}.to_json
90+
end
91+
92+
before do
93+
create(:class_student, school_class:, student_id: student.id)
94+
end
95+
96+
it 'returns success response' do
97+
get("/api/projects/#{student_remix.identifier}/context", headers:)
98+
99+
expect(response).to have_http_status(:ok)
100+
end
101+
102+
it 'returns the remix project context json' do
103+
get("/api/projects/#{student_remix.identifier}/context", headers:)
104+
105+
expect(response.body).to eq(expected_context_json)
106+
end
107+
end
108+
78109
context 'when loading another user\'s project context' do
79110
let!(:another_project) { create(:project, user_id: SecureRandom.uuid, locale: nil) }
80111
let(:another_project_json) do

0 commit comments

Comments
 (0)