@@ -136,6 +136,10 @@ class TaskDefinitionsApi < Grape::API
136136 optional :assess_in_portfolio_only , type : Boolean , desc : 'Whether a task can only be signed off during portfolio assessment'
137137 optional :use_resources_for_jplag_base_code , type : Boolean , desc : 'Include the common base code from task resources for JPlag comparisons'
138138 optional :lock_assessments_to_tutorial_stream , type : Boolean , desc : 'Only allow tutors in this tutorial stream to assess this task'
139+ # optional :p_target_date, type: Date, desc: 'Pass due date override'
140+ optional :c_target_date , type : Date , desc : 'Credit due date override'
141+ optional :d_target_date , type : Date , desc : 'Distinction due date override'
142+ optional :hd_target_date , type : Date , desc : 'High Distinction due date override'
139143 end
140144 end
141145 put '/units/:unit_id/task_definitions/:id' do
@@ -146,6 +150,10 @@ class TaskDefinitionsApi < Grape::API
146150 error! ( { error : 'Not authorised to create a task definition of this unit' } , 403 )
147151 end
148152
153+ # strip these out so TaskDefinition#update! never sees them
154+ grade_due_overrides = params [ :task_def ] . slice ( 'p_target_date' , 'c_target_date' , 'd_target_date' , 'hd_target_date' )
155+ params [ :task_def ] . except! ( 'p_target_date' , 'c_target_date' , 'd_target_date' , 'hd_target_date' )
156+
149157 task_params = ActionController ::Parameters . new ( params )
150158 . require ( :task_def )
151159 . permit (
@@ -218,6 +226,25 @@ class TaskDefinitionsApi < Grape::API
218226 end
219227 end
220228
229+ grade_map = { 'c_target_date' => 1 , 'd_target_date' => 2 , 'hd_target_date' => 3 }
230+
231+ grade_due_overrides . each do |key , date |
232+ next if date . blank?
233+ next unless grade_map . key? ( key ) # skip p_target_date
234+
235+ if task_def . start_date > date
236+ error! ( { error : 'Target date cannot be earlier than start date' } , 400 )
237+ end
238+
239+ unless unit . allow_flexible_dates
240+ error! ( { error : 'This unit must have Allow Flexible Dates enabled to modify target dates per grade' } , 403 )
241+ end
242+
243+ TaskDefinitionGradeDueDate
244+ . find_or_initialize_by ( task_definition : task_def , target_grade : grade_map [ key ] )
245+ . update! ( target_due_date : date )
246+ end
247+
221248 present task_def , with : Entities ::TaskDefinitionEntity , my_role : unit . role_for ( current_user )
222249 end
223250
0 commit comments