agenda-libre-ruby/app/controllers/moderations_controller.rb

60 lines
1.8 KiB
Ruby
Raw Normal View History

2014-06-09 12:18:40 +02:00
require 'differ'
2014-06-23 23:39:42 +02:00
class ModerationsController < ApplicationController
before_filter :authenticate_user!
2014-01-06 11:22:39 +01:00
before_action :set_event, only: [:show, :edit, :update, :destroy]
2014-06-09 12:18:40 +02:00
before_filter :set_mailer_host, only: [:update, :destroy]
2014-01-06 11:22:39 +01:00
def index
2014-06-23 23:39:42 +02:00
@events = Event.where moderated: 0
2014-01-06 11:22:39 +01:00
end
# PATCH/PUT /moderations/1
# PATCH/PUT /moderations/1.json
def update
# This is a special case, required to handle the region attribute with same foreign key name
@event.region = Region.find(params[:event][:region])
2014-01-06 11:22:39 +01:00
if params[:visu]
@event.attributes = event_params
render action: 'edit'
return
end
respond_to do |format|
if @event.update(event_params)
# Send an update mail to its author
ModerationMailer.update(@event, current_user).deliver
2014-01-06 11:22:39 +01:00
format.html { redirect_to moderations_path, notice: 'Event was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @event.errors, status: :unprocessable_entity }
end
end
end
private
def permitted_params
2014-06-23 23:39:42 +02:00
params.require(:event).permit(:title, :start_time, :end_time, :description, :city, :locality, :url, :contact, :submitter, :tags)
2014-01-06 11:22:39 +01:00
end
# Use callbacks to share common setup or constraints between actions.
def set_event
2014-06-23 23:39:42 +02:00
@event = Event.find params[:id]
2014-01-06 11:22:39 +01:00
@moderation = @event
end
# Never trust parameters from the scary internet, only allow the white list through.
def event_params
params.require(:event)
.permit :title, :start_time, :end_time, :description, :city, :locality, :url, :contact, :submitter, :tags
end
2014-06-09 12:18:40 +02:00
# Useful to manage absolute url in mails
def set_mailer_host
ActionMailer::Base.default_url_options[:host] = request.host_with_port
end
2014-01-06 11:22:39 +01:00
end