Sprankelprachtig aan/afmeldsysteem

activities_controller.rb 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. class ActivitiesController < ApplicationController
  2. include GroupsHelper
  3. before_action :set_activity, only: [:show, :edit, :update, :destroy, :presence]
  4. before_action :set_group
  5. before_action :require_membership!
  6. # GET /groups/:id/activities
  7. # GET /activities.json
  8. def index
  9. @activities = @group.activities
  10. end
  11. # GET /activities/1
  12. # GET /activities/1.json
  13. def show
  14. end
  15. # GET /activities/new
  16. def new
  17. @activity = Activity.new
  18. end
  19. # GET /activities/1/edit
  20. def edit
  21. end
  22. # POST /activities
  23. # POST /activities.json
  24. def create
  25. @activity = Activity.new(activity_params)
  26. @activity.group = @group
  27. respond_to do |format|
  28. if @activity.save
  29. format.html { redirect_to group_activity_url(@group, @activity), notice: 'Activity was successfully created.' }
  30. format.json { render :show, status: :created, location: @activity }
  31. else
  32. format.html { render :new }
  33. format.json { render json: @activity.errors, status: :unprocessable_entity }
  34. end
  35. end
  36. end
  37. # PATCH/PUT /activities/1
  38. # PATCH/PUT /activities/1.json
  39. def update
  40. respond_to do |format|
  41. if @activity.update(activity_params)
  42. format.html { redirect_to group_activity_url(@group, @activity), notice: 'Activity was successfully updated.' }
  43. format.json { render :show, status: :ok, location: @activity }
  44. else
  45. format.html { render :edit }
  46. format.json { render json: @activity.errors, status: :unprocessable_entity }
  47. end
  48. end
  49. end
  50. # DELETE /activities/1
  51. # DELETE /activities/1.json
  52. def destroy
  53. @activity.destroy
  54. respond_to do |format|
  55. format.html { redirect_to group_activities_url(@group), notice: 'Activity was successfully destroyed.' }
  56. format.json { head :no_content }
  57. end
  58. end
  59. # PATCH/PUT /groups/:group_id/activities/:id/presence
  60. # PATCH/PUT /groups/:group_id/activities/:id/presence.json
  61. def presence
  62. participant = Participant.find_by(
  63. person_id: params[:person_id],
  64. activity: @activity
  65. )
  66. if !@activity.may_change?(current_person)
  67. render status: :forbidden
  68. end
  69. if params[:participant]
  70. params[:notes] = params[:participant][:notes]
  71. end
  72. participant.update_attributes(params.permit(:notes, :attending))
  73. end
  74. private
  75. # Use callbacks to share common setup or constraints between actions.
  76. def set_activity
  77. @activity = Activity.find(params[:id])
  78. end
  79. def set_group
  80. @group = Group.find(params[:group_id])
  81. end
  82. # Never trust parameters from the scary internet, only allow the white list through.
  83. def activity_params
  84. params.require(:activity).permit(:public_name, :secret_name, :description, :location, :start, :end, :deadline, :show_hidden)
  85. end
  86. end