diff --git a/app/api/entities/group_entity.rb b/app/api/entities/group_entity.rb index f48086c71..1fc44a73a 100644 --- a/app/api/entities/group_entity.rb +++ b/app/api/entities/group_entity.rb @@ -4,7 +4,7 @@ class GroupEntity < Grape::Entity expose :name expose :tutorial_id expose :group_set_id - expose :student_count + expose :student_count #TODO: remove this and request it dynamically when needed expose :capacity_adjustment expose :locked end diff --git a/app/api/entities/tutorial_entity.rb b/app/api/entities/tutorial_entity.rb index d3db2048c..624f57ff0 100644 --- a/app/api/entities/tutorial_entity.rb +++ b/app/api/entities/tutorial_entity.rb @@ -10,7 +10,7 @@ class TutorialEntity < Grape::Entity expose :tutorial_stream do |tutorial, options| tutorial.tutorial_stream.abbreviation unless tutorial.tutorial_stream.nil? end - expose :num_students + expose :num_students #TODO: remove this and request it dynamically when needed expose :tutor do |tutorial, options| Entities::UserEntity.represent tutorial.tutor, only: [:id, :name] end diff --git a/app/api/entities/unit_entity.rb b/app/api/entities/unit_entity.rb index 53494fb34..434e26be3 100644 --- a/app/api/entities/unit_entity.rb +++ b/app/api/entities/unit_entity.rb @@ -5,7 +5,7 @@ class UnitEntity < Grape::Entity end def is_staff?(user, unit) - [ Role.convenor, Role.tutor, Role.admin ].include? unit.role_for(user) + [ Role.convenor_id, Role.tutor_id, Role.admin_id ].include? unit.role_for(user).id end expose :code diff --git a/app/api/units_api.rb b/app/api/units_api.rb index aecfe9aba..d75ea531c 100644 --- a/app/api/units_api.rb +++ b/app/api/units_api.rb @@ -40,7 +40,19 @@ class UnitsApi < Grape::API desc "Get a unit's details" get '/units/:id' do - unit = Unit.find(params[:id]) + unit = Unit.includes( + {unit_roles: [:role, :user]}, + {task_definitions: :tutorial_stream}, + :learning_outcomes, + {tutorial_streams: :activity_type}, + {tutorials: [:tutor, :tutorial_stream]}, + :tutorial_enrolments, + {staff: [:role, :user]}, + :group_sets, + :groups, + :group_memberships + ).find(params[:id]) + unless (authorise? current_user, unit, :get_unit) || (authorise? current_user, User, :admin_units) error!({ error: "Couldn't find Unit with id=#{params[:id]}" }, 403) end diff --git a/app/models/tutorial.rb b/app/models/tutorial.rb index 6ed6b47dc..4a9635fe7 100644 --- a/app/models/tutorial.rb +++ b/app/models/tutorial.rb @@ -42,8 +42,7 @@ def self.find_by_user(user) end def tutor - result = UnitRole.find_by(id: unit_role_id) - result.user unless result.nil? + unit_role.user unless unit_role.nil? end def name