Skip to content

Commit 3315f38

Browse files
committed
update student ability and json response to handle remix project and add test
1 parent f34f8cb commit 3315f38

3 files changed

Lines changed: 28 additions & 2 deletions

File tree

app/models/ability.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def define_school_student_abilities(user:, school:)
115115
can(%i[read], SchoolClass, school: { id: school.id }, students: { student_id: user.id })
116116
# Ensure no access to ClassMember resources, relationships otherwise allow access in some circumstances.
117117
can(%i[read], Lesson, school_id: school.id, visibility: 'students', school_class: { students: { student_id: user.id } })
118-
can(%i[read create update], Project, school_id: school.id, user_id: user.id, lesson_id: nil, remixed_from_id: visible_lesson_project_ids)
118+
can(%i[read create update show_context], Project, school_id: school.id, user_id: user.id, lesson_id: nil, remixed_from_id: visible_lesson_project_ids)
119119
can(%i[read show_context], Project, lesson: { school_id: school.id, visibility: 'students', school_class: { students: { student_id: user.id } } })
120120
can(%i[read set_read], Feedback, school_project: { project: { school_id: school.id, user_id: user.id, lesson_id: nil, remixed_from_id: visible_lesson_project_ids } })
121121
can(%i[show_finished set_finished show_status unsubmit submit], SchoolProject, project: { user_id: user.id, lesson_id: nil }, school_id: school.id)
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
source_lesson = @project.lesson || @project.parent&.lesson
4+
35
json.call(
46
@project,
57
:identifier,
@@ -8,4 +10,5 @@ json.call(
810
:lesson_id
911
)
1012

11-
json.class_id(@project.lesson.school_class_id)
13+
json.lesson_id source_lesson&.id
14+
json.class_id source_lesson&.school_class_id

spec/requests/projects/show_context_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,29 @@
136136
end
137137
end
138138

139+
context 'when loading context of a remixed project that is visible to students' do
140+
let!(:student_remix) { create(:project, school:, user_id: student.id, remixed_from_id: project.id, locale: nil) }
141+
let(:expected_context_json) do
142+
{
143+
identifier: student_remix.identifier,
144+
project_type: project.project_type,
145+
school_id: school.id,
146+
lesson_id: lesson.id,
147+
class_id: school_class.id
148+
}.to_json
149+
end
150+
151+
it 'returns success response' do
152+
get("/api/projects/#{student_remix.identifier}/context", headers:)
153+
expect(response).to have_http_status(:ok)
154+
end
155+
156+
it 'returns the remix project context json' do
157+
get("/api/projects/#{student_remix.identifier}/context", headers:)
158+
expect(response.body).to eq(expected_context_json)
159+
end
160+
end
161+
139162
context 'when loading context of a lesson project that is not visible to students' do
140163
before do
141164
project.lesson.update(visibility: 'teachers')

0 commit comments

Comments
 (0)