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
4 changes: 4 additions & 0 deletions app/api/entities/project_entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class ProjectEntity < Grape::Entity
expose :tasks, using: TaskEntity, unless: :summary_only do |project, options|
project.task_details_for_shallow_serializer(options[:user])
end
# changed here
expose :task_definitions, using: TaskDefinitionEntity, if: :include_task_definitions do |project, options|
project.unit.task_definitions
end

expose :tutorial_enrolments, using: TutorialEnrolmentEntity, unless: :summary_only
expose :groups, using: GroupEntity, unless: :summary_only
Expand Down
11 changes: 9 additions & 2 deletions app/api/projects_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@ class ProjectsApi < Grape::API
desc "Fetches all of the current user's projects"
params do
optional :include_inactive, type: Boolean, desc: 'Include projects for units that are no longer active?'
optional :include_task_definitions, type: Boolean, desc: 'Include all task definitions for each project unit? Also exposes tasks.'
end
get '/projects' do
include_inactive = params[:include_inactive] || false
include_task_definitions = params[:include_task_definitions] || false

projects = Project.eager_load(:unit, :user).for_user current_user, include_inactive
present projects, with: Entities::ProjectEntity, for_student: true, summary_only: true, user: current_user
projects = if include_task_definitions
Project.eager_load(:unit, :user, :tasks, unit: :task_definitions).for_user(current_user, include_inactive)
else
Project.eager_load(:unit, :user).for_user(current_user, include_inactive)
end
# Disable summary_only so tasks are exposed for request
present projects, with: Entities::ProjectEntity, for_student: true, summary_only: !include_task_definitions, include_task_definitions: include_task_definitions, user: current_user
end

desc 'Get project'
Expand Down