Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def define_school_student_abilities(user:, school:)
can(%i[read], SchoolClass, school: { id: school.id }, students: { student_id: user.id })
# Ensure no access to ClassMember resources, relationships otherwise allow access in some circumstances.
can(%i[read], Lesson, school_id: school.id, visibility: 'students', school_class: { students: { student_id: user.id } })
can(%i[read create update], Project, school_id: school.id, user_id: user.id, lesson_id: nil, remixed_from_id: visible_lesson_project_ids)
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)
can(%i[read show_context], Project, lesson: { school_id: school.id, visibility: 'students', school_class: { students: { student_id: user.id } } })
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 } })
can(%i[show_finished set_finished show_status unsubmit submit], SchoolProject, project: { user_id: user.id, lesson_id: nil }, school_id: school.id)
Expand Down
8 changes: 5 additions & 3 deletions app/views/api/projects/context.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# frozen_string_literal: true

source_lesson = @project.lesson || @project.parent&.lesson

json.call(
@project,
:identifier,
:project_type,
:school_id,
:lesson_id
:school_id
)
Comment thread
cocomarine marked this conversation as resolved.

json.class_id(@project.lesson.school_class_id)
json.lesson_id source_lesson&.id
json.class_id source_lesson&.school_class_id
23 changes: 23 additions & 0 deletions spec/requests/projects/show_context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,29 @@
end
end

context 'when loading context of a remixed project that is visible to students' do
let!(:student_remix) { create(:project, school:, user_id: student.id, remixed_from_id: project.id, locale: nil) }
let(:expected_context_json) do
{
identifier: student_remix.identifier,
project_type: project.project_type,
school_id: school.id,
lesson_id: lesson.id,
class_id: school_class.id
}.to_json
end

it 'returns success response' do
get("/api/projects/#{student_remix.identifier}/context", headers:)
expect(response).to have_http_status(:ok)
end

it 'returns the remix project context json' do
get("/api/projects/#{student_remix.identifier}/context", headers:)
expect(response.body).to eq(expected_context_json)
end
end

context 'when loading context of a lesson project that is not visible to students' do
before do
project.lesson.update(visibility: 'teachers')
Expand Down
Loading