@@ -125,9 +125,7 @@ def sanitized_filename(filename)
125125 end
126126
127127 def task_file_dir_for_unit ( unit , create = true )
128- file_server = Doubtfire ::Application . config . student_work_dir
129- dst = "#{ file_server } /" # trust the server config and passed in type for paths
130- dst << sanitized_path ( "#{ unit . code } -#{ unit . id } " , 'TaskFiles' ) << '/'
128+ dst = unit_work_root ( unit ) << 'TaskFiles/'
131129
132130 FileUtils . mkdir_p dst if create && ( !Dir . exist? dst )
133131
@@ -176,6 +174,30 @@ def student_work_root
176174 Doubtfire ::Application . config . student_work_dir
177175 end
178176
177+ def archive_root
178+ Doubtfire ::Application . config . archive_dir
179+ end
180+
181+ # Get the path to the unit root - will take into consideration if archived
182+ #
183+ # @param [Unit] unit - the unit to get the root path for
184+ # @param [Boolean] archived - whether to use the archived property (true/false)
185+ # or force it to be the archived path (:force)
186+ def unit_work_root ( unit , archived : true )
187+ dst = if ( unit . archived && archived ) || ( archived == :force )
188+ "#{ archive_root } /"
189+ else
190+ "#{ student_work_root } /"
191+ end
192+
193+ dst << sanitized_path ( "#{ unit . code } -#{ unit . id } " ) << '/'
194+ end
195+
196+ def project_work_root ( project , archived : true , username : nil )
197+ username = project . student . username . to_s if username . nil?
198+ unit_work_root ( project . unit , archived : archived ) << sanitized_path ( username ) << '/'
199+ end
200+
179201 #
180202 # Generates a path for storing student work
181203 # type = [:new, :in_process, :done, :pdf, :plagarism]
@@ -187,18 +209,17 @@ def student_work_dir(type = nil, task = nil, create = true)
187209 file_server = Doubtfire ::Application . config . student_work_dir
188210 dst = "#{ file_server } /" # trust the server config and passed in type for paths
189211
190- if !( type . nil? || task . nil? )
212+ if !( type . nil? || task . nil? ) # we have task and type
191213 if [ :discussion , :pdf , :comment ] . include? type
192- dst << sanitized_path ( " #{ task . project . unit . code } - #{ task . project . unit . id } " , task . project . student . username . to_s , type . to_s ) << '/'
214+ dst = project_work_root ( task . project ) << sanitized_path ( type . to_s ) << '/'
193215 elsif [ :done , :plagarism ] . include? type
194- dst << sanitized_path ( " #{ task . project . unit . code } - #{ task . project . unit . id } " , task . project . student . username . to_s , type . to_s , task . id . to_s ) << '/'
216+ dst = project_work_root ( task . project ) << sanitized_path ( type . to_s , task . id . to_s ) << '/'
195217 else # new and in_process -- just have task id
196218 # Add task id to dst if we want task
197219 dst << "#{ type } /#{ task . id } /"
198220 end
199- elsif !type . nil?
221+ elsif !type . nil? # have type but not task
200222 if [ :in_process , :new ] . include? type
201- # Add task id to dst if we want task
202223 dst << "#{ type } /"
203224 else
204225 raise 'Error in request to student work directory'
@@ -211,27 +232,40 @@ def student_work_dir(type = nil, task = nil, create = true)
211232 dst
212233 end
213234
214- def dir_for_unit_code_and_id ( unit_code , unit_id , create = true )
215- file_server = Doubtfire ::Application . config . student_work_dir
216- dst = "#{ file_server } /" # trust the server config and passed in type for paths
235+ def dir_for_unit_code_and_id ( unit_code , unit_id , create : true , archived : false )
236+ dst = if archived
237+ "#{ archive_root } /"
238+ else
239+ "#{ student_work_root } /"
240+ end
241+
217242 dst << sanitized_path ( "#{ unit_code } -#{ unit_id } " )
218243
219244 FileUtils . mkdir_p dst if create && !Dir . exist? ( dst )
220245
221246 dst
222247 end
223248
224- def unit_dir ( unit , create = true )
225- dir_for_unit_code_and_id ( unit . code , unit . id , create )
249+ def unit_dir ( unit , create : true , archived : true )
250+ dir_for_unit_code_and_id ( unit . code , unit . id , create : create , archived : archived == :force || ( archived && unit . archived ) )
226251 end
227252
228- def root_portfolio_dir
229- file_server = Doubtfire ::Application . config . student_work_dir
253+ def root_portfolio_dir ( archived : false )
254+ file_server = if archived
255+ archive_root
256+ else
257+ student_work_root
258+ end
259+
230260 "#{ file_server } /portfolio/" # trust the server config and passed in type for paths
231261 end
232262
233- def unit_portfolio_dir ( unit , create = true )
234- dst = root_portfolio_dir
263+ def unit_portfolio_dir ( unit , create : true , archived : true )
264+ dst = if ( unit . archived && archived ) || ( archived == :force )
265+ "#{ archive_root } /portfolio/"
266+ else
267+ "#{ student_work_root } /portfolio/"
268+ end
235269
236270 dst << sanitized_path ( "#{ unit . code } -#{ unit . id } " ) << '/'
237271
@@ -243,8 +277,8 @@ def unit_portfolio_dir(unit, create = true)
243277 #
244278 # Generates a path for storing student portfolios
245279 #
246- def student_portfolio_dir ( unit , username , create = true )
247- dst = unit_portfolio_dir ( unit , create )
280+ def student_portfolio_dir ( unit , username , create : true , archived : true )
281+ dst = unit_portfolio_dir ( unit , create : create , archived : archived )
248282
249283 dst << sanitized_path ( username . to_s )
250284
@@ -253,8 +287,8 @@ def student_portfolio_dir(unit, username, create = true)
253287 dst
254288 end
255289
256- def student_portfolio_path ( unit , username , create = true )
257- File . join ( student_portfolio_dir ( unit , username , create ) , FileHelper . sanitized_filename ( "#{ username } -portfolio.pdf" ) )
290+ def student_portfolio_path ( unit , username , create : true , archived : true )
291+ File . join ( student_portfolio_dir ( unit , username , create : create , archived : archived ) , FileHelper . sanitized_filename ( "#{ username } -portfolio.pdf" ) )
258292 end
259293
260294 def comment_attachment_path ( task_comment , attachment_extension )
@@ -679,10 +713,13 @@ def line_wrap(path, width: 160)
679713 module_function :student_group_work_dir
680714 module_function :student_work_dir
681715 module_function :student_work_root
716+ module_function :archive_root
682717 module_function :dir_for_unit_code_and_id
683718 module_function :unit_dir
684719 module_function :root_portfolio_dir
685720 module_function :unit_portfolio_dir
721+ module_function :unit_work_root
722+ module_function :project_work_root
686723 module_function :student_portfolio_dir
687724 module_function :student_portfolio_path
688725 module_function :comment_attachment_path
0 commit comments