Sprankelprachtig aan/afmeldsysteem

groups_controller.rb 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Provides API views to read information related to Groups.
  2. # This controller provides two methods to authenticate and authorize a request:
  3. # - By the Session used to authenticate logged-in users, and
  4. # - By passing a custom Authorization:-header of the form 'Group :api_key'.
  5. #
  6. # If the API key method is used, the :id parameter is ignored, but still required in the URL.
  7. class Api::GroupsController < ApiController
  8. has_no_group = [:index]
  9. # Session-based authentication / authorization filters
  10. before_action :set_group, except: has_no_group
  11. before_action :require_membership!, except: has_no_group
  12. before_action :api_require_admin!, only: has_no_group
  13. skip_before_action :set_group, :require_membership!, :api_require_authentication!, if: 'request.authorization'
  14. # API key based filter (both authenticates and authorizes)
  15. before_action :api_auth_group_token, if: 'request.authorization'
  16. # GET /api/groups
  17. def index
  18. @groups = Group.all
  19. end
  20. # GET /api/groups/1
  21. def show; end
  22. # GET /api/groups/1/current_activities
  23. def current_activities
  24. @activities = @group.current_activities
  25. render 'api/activities/index'
  26. end
  27. # GET /api/groups/1/upcoming_activities
  28. def upcoming_activities
  29. @activities = @group.upcoming_activities
  30. render 'api/activities/index'
  31. end
  32. # GET /api/groups/1/previous_activities
  33. def previous_activities
  34. @activities = @group.previous_activities
  35. render 'api/activities/index'
  36. end
  37. private
  38. # Set group from the :id parameter.
  39. def set_group
  40. @group = Group.find(params[:id])
  41. end
  42. end