diff --git a/app/controllers/org_admin/templates_controller.rb b/app/controllers/org_admin/templates_controller.rb index 782e021..c0040ed 100644 --- a/app/controllers/org_admin/templates_controller.rb +++ b/app/controllers/org_admin/templates_controller.rb @@ -397,6 +397,5 @@ def plan_params params.require(:plan).permit(:org_id, :funder_id) end - end end \ No newline at end of file diff --git a/app/controllers/phases_controller.rb b/app/controllers/phases_controller.rb index 39c9ae9..f5c2cff 100644 --- a/app/controllers/phases_controller.rb +++ b/app/controllers/phases_controller.rb @@ -67,6 +67,9 @@ else @original_org = @phase.template.org end + + in_use_check(@phase) + render('/org_admin/templates/container', locals: { partial_path: 'admin_show', @@ -180,4 +183,24 @@ end end + + private + def in_use_check(phase) + # Check to see if anyone else has recently been working with this template. If so warn the user + current_editors = Rails.cache.read("phase_#{phase.id}") || [] + current_editors.delete(current_user.id) + + unless current_editors.empty? + flash[:notice] = _('%{users} also appears to be editing this phase!') % + { users: current_editors.collect{ |u| User.find(u).name(false) if User.find(u).present? }.join(', ') } + end + + current_editors << current_user.id unless current_editors.include?(current_user.id) + # Record the activity in the Rails cache + begin + Rails.cache.write("phase_#{phase.id}", current_editors, :expires_in => 15.minutes) + rescue Exception => e + logger.error("Caught exception RSS parse: #{e}.") + end + end end