Skip to content

Commit b6fc0b7

Browse files
authored
Distinguish owners in class members list (#522)
## Status closes RaspberryPiFoundation/digital-editor-issues#485 ## What's changed? - Class teachers that are also a school owner are not returned in the format `owner: {class_member}` rather than `teacher: {class_member}` when listing class members. This allows the owner icon to be displayed next to them on the frontend.
1 parent 02be4f3 commit b6fc0b7

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

app/controllers/api/class_members_controller.rb

+2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ class ClassMembersController < ApiController
99

1010
def index
1111
@class_students = @school_class.students.accessible_by(current_ability)
12+
owners = SchoolOwner::List.call(school: @school).fetch(:school_owners, [])
1213
result = ClassMember::List.call(school_class: @school_class, class_students: @class_students, token: current_user.token)
1314

1415
if result.success?
16+
@school_owner_ids = owners.map(&:id)
1517
@class_members = result[:class_members]
1618
render :index, formats: [:json], status: :ok
1719
else

app/views/api/class_members/index.json.jbuilder

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
json.array!(@class_members) do |class_member|
44
if class_member.respond_to?(:student_id)
55
json.partial! 'class_member', class_member:
6+
elsif @school_owner_ids.include?(class_member.id)
7+
json.set! :owner do
8+
json.partial! '/api/school_owners/school_owner', owner: class_member
9+
end
610
else
711
json.set! :teacher do
812
json.partial! '/api/school_teachers/school_teacher', teacher: class_member

0 commit comments

Comments
 (0)