Sprankelprachtig aan/afmeldsysteem

activities_controller.rb 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. participant.update_attributes(params.permit(:notes, :attending))
  70. end
  71. private
  72. # Use callbacks to share common setup or constraints between actions.
  73. def set_activity
  74. @activity = Activity.find(params[:id])
  75. end
  76. def set_group
  77. @group = Group.find(params[:group_id])
  78. end
  79. # Never trust parameters from the scary internet, only allow the white list through.
  80. def activity_params
  81. params.require(:activity).permit(:public_name, :secret_name, :description, :location, :start, :end, :deadline, :show_hidden)
  82. end
  83. end