@@ -3,6 +3,7 @@ class ComplaintsController < ApplicationController
33 before_action :access_check , only : [ :show , :comment ]
44 before_action :write_access_check , only : [ :self_assign , :update_status , :change_content_type ]
55 before_action :verify_staff , only : [ :reports , :reporting ]
6+ before_action :training_access , only : [ :training , :training_complete ]
67
78 def index
89 render layout : 'without_sidebar'
@@ -202,6 +203,28 @@ def reporting
202203 render layout : 'without_sidebar'
203204 end
204205
206+ def training
207+ pages = Dir . glob ( Rails . root . join ( 'app' , 'views' , 'complaints' , 'training' , '*.html.erb' ) )
208+ . map { |page | File . basename ( page , '.html.erb' ) }
209+ if pages . include? ( params [ :page ] )
210+ render "complaints/training/#{ params [ :page ] } " , layout : 'osa_training'
211+ else
212+ not_found!
213+ end
214+ end
215+
216+ def training_complete
217+ user_update = current_user . update ( osa_training : DateTime . now )
218+ audit_log = AuditLog . moderator_audit ( event_type : 'osa_training_completed' , user : current_user ,
219+ comment : 'OSA training completed.' )
220+ if user_update && audit_log
221+ flash [ :success ] = I18n . t ( 'safety_center.training_complete' )
222+ else
223+ flash [ :danger ] = I18n . t ( 'safety_center.training_complete_failed' )
224+ end
225+ redirect_to safety_center_path
226+ end
227+
205228 private
206229
207230 def access_check
@@ -235,4 +258,11 @@ def set_complaint
235258
236259 @complaint
237260 end
261+
262+ def training_access
263+ osa_training_enabled = SiteSetting [ 'OSATrainingEnabled' ]
264+ unless user_signed_in? && ( current_user . staff? || current_user . at_least_moderator? ) && osa_training_enabled
265+ not_found!
266+ end
267+ end
238268end
0 commit comments