Skip to content
Merged
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
13 changes: 13 additions & 0 deletions app/api/projects_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,17 @@ class ProjectsApi < Grape::API
present portfolio_tasks.map(&:id)
end

desc 'Get IDs of tasks that are still processing a PDF '
get '/projects/:id/tasks_processing' do
project = Project.find(params[:id])

unless authorise? current_user, project, :get
error!({ error: "Couldn't find Project with id=#{params[:id]}" }, 403)
end

portfolio_tasks = project.tasks_processing_pdf

present portfolio_tasks.map(&:id)
end

end
13 changes: 13 additions & 0 deletions app/models/pdf_generation/project_compile_portfolio_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,19 @@ def portfolio_tasks
end
end

# Return the tasks that are currently being processed
def tasks_processing_pdf
# Get assigned tasks that should be included in the portfolio
tasks = self.tasks.joins(:task_definition).order('task_definitions.target_date, task_definitions.abbreviation')

# Select tasks that should have a PDF submission, but is currently being processed
tasks.select do |task|
!task.has_pdf &&
task.processing_pdf? &&
task.task_definition.upload_requirements.present?
end
end

#
# Return the path to the student's learning summary report.
# This returns nil if there is no learning summary report.
Expand Down
43 changes: 43 additions & 0 deletions test/models/project_model_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,49 @@ def test_create_empty_portfolio
unit.destroy!
end

def test_portfolio_tasks_excludes_tasks_until_pdf_processing_finishes
unit = FactoryBot.create(:unit, with_students: false, task_count: 0)
project = FactoryBot.create(:project, unit: unit)
no_upload_task_definition = FactoryBot.create(:task_definition, unit: unit, upload_requirements: [])
finished_task_definition = FactoryBot.create(:task_definition, unit: unit)
processing_task_definition = FactoryBot.create(:task_definition, unit: unit)

no_upload_task = FactoryBot.create(
:task,
project: project,
task_definition: no_upload_task_definition,
task_status: TaskStatus.ready_for_feedback
)
finished_task = FactoryBot.create(
:task,
project: project,
task_definition: finished_task_definition,
task_status: TaskStatus.ready_for_feedback
)
processing_task = FactoryBot.create(
:task,
project: project,
task_definition: processing_task_definition,
task_status: TaskStatus.ready_for_feedback
)

FileUtils.touch(finished_task.final_pdf_path)
FileUtils.touch(processing_task.final_pdf_path)
processing_dir = FileHelper.student_work_dir(:new, processing_task, true)

assert_includes project.portfolio_tasks, no_upload_task
assert_includes project.portfolio_tasks, finished_task
assert_not_includes project.portfolio_tasks, processing_task
assert_includes project.tasks_processing_pdf, processing_task

FileUtils.rm_r(processing_dir)

assert_includes project.portfolio_tasks, processing_task
assert_not_includes project.tasks_processing_pdf, processing_task

unit.destroy!
end

def test_create_portfolio_with_lsr
project = FactoryBot.create(:project)
unit = project.unit
Expand Down
Loading