course_participations_controller.rb 861 B

12345678910111213141516171819202122232425262728293031
  1. class CourseParticipationsController < ApplicationController
  2. def create
  3. @course = Course.find(participation_params[:course_id])
  4. check_permissions
  5. @participation = CourseParticipation.new(participation_params)
  6. @participation.save
  7. redirect_to @course
  8. end
  9. def destroy
  10. @participation = CourseParticipation.find(params[:id])
  11. @course = @participation.course
  12. check_permissions
  13. @participation.destroy
  14. redirect_to @course
  15. end
  16. private
  17. def participation_params
  18. params.require(:course_participation).permit(:course_id,
  19. :user_id,
  20. :role)
  21. end
  22. def check_permissions
  23. unless current_user.is_administrator_at?(@course.school) || current_user.admin?
  24. redirect_to root_url
  25. end
  26. end
  27. end