taskbar_controller.rb 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
  2. class TaskbarController < ApplicationController
  3. prepend_before_action :authentication_check
  4. def index
  5. current_user_tasks = Taskbar.where(user_id: current_user.id)
  6. model_index_render_result(current_user_tasks)
  7. end
  8. def show
  9. taskbar = Taskbar.find(params[:id])
  10. access_to_taskbar(taskbar)
  11. model_create_render(Taskbar, params)
  12. end
  13. def create
  14. task_user(params)
  15. model_create_render(Taskbar, params)
  16. end
  17. def update
  18. taskbar = Taskbar.find(params[:id])
  19. access_to_taskbar(taskbar)
  20. task_user(params)
  21. model_update_render(Taskbar, params)
  22. end
  23. def destroy
  24. taskbar = Taskbar.find(params[:id])
  25. access_to_taskbar(taskbar)
  26. model_destroy_render(Taskbar, params)
  27. end
  28. private
  29. def access_to_taskbar(taskbar)
  30. raise Exceptions::UnprocessableEntity, 'Not allowed to access this task.' if taskbar.user_id != current_user.id
  31. end
  32. def task_user(params)
  33. params[:user_id] = current_user.id
  34. end
  35. end