2014-08-06 14:47:47 +02:00
|
|
|
# Event management life cycle
|
2014-06-23 23:39:42 +02:00
|
|
|
class ModerationsController < ApplicationController
|
2017-07-28 00:35:14 +02:00
|
|
|
has_scope :region, :locality, :tag, :daylimit, :year
|
|
|
|
has_scope :near, type: :hash, using: %i[location distance]
|
|
|
|
|
2014-08-06 14:47:47 +02:00
|
|
|
before_action :authenticate_user!
|
|
|
|
before_action :set_moderation, :set_mailer_host, only:
|
2017-04-22 20:01:47 +02:00
|
|
|
%i[show edit preview update validate accept refuse destroy]
|
2016-09-17 19:41:29 +02:00
|
|
|
before_action :generate_destroy_reason, only: :destroy
|
2014-10-11 16:12:07 +02:00
|
|
|
rescue_from ActiveRecord::StaleObjectError, with: :locked
|
2014-01-06 11:22:39 +01:00
|
|
|
|
|
|
|
def index
|
2014-08-06 14:47:47 +02:00
|
|
|
@events = Event.unmoderated
|
2015-07-25 18:32:27 +02:00
|
|
|
@orgas = Orga.unmoderated
|
2014-01-06 11:22:39 +01:00
|
|
|
end
|
|
|
|
|
2014-08-09 18:59:11 +02:00
|
|
|
def preview
|
|
|
|
@moderation.attributes = moderation_params
|
|
|
|
@moderation.valid?
|
|
|
|
render action: :edit
|
|
|
|
end
|
|
|
|
|
2014-01-06 11:22:39 +01:00
|
|
|
# PATCH/PUT /moderations/1
|
|
|
|
# PATCH/PUT /moderations/1.json
|
|
|
|
def update
|
|
|
|
respond_to do |format|
|
2018-03-17 15:49:43 +01:00
|
|
|
if @moderation.update moderation_params
|
2014-11-05 21:25:18 +01:00
|
|
|
format.html { redirect_to :moderations, notice: t('.ok') }
|
2014-01-06 11:22:39 +01:00
|
|
|
format.json { head :no_content }
|
|
|
|
else
|
|
|
|
format.html { render action: 'edit' }
|
2018-04-05 22:00:07 +02:00
|
|
|
status = :unprocessable_entity
|
|
|
|
format.json { render json: @moderation.errors, status: status }
|
2014-01-06 11:22:39 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-01 15:50:39 +02:00
|
|
|
# PATCH/PUT /accept/1
|
|
|
|
# PATCH/PUT /accept/1.json
|
|
|
|
def accept
|
2014-11-05 21:25:18 +01:00
|
|
|
@moderation.update moderated: true
|
2014-07-01 15:50:39 +02:00
|
|
|
respond_to do |format|
|
2014-11-05 21:25:18 +01:00
|
|
|
format.html { redirect_to :moderations, notice: t('.ok') }
|
|
|
|
format.json { head :no_content }
|
2014-07-01 15:50:39 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-01 17:52:33 +01:00
|
|
|
# DELETE /moderations/1
|
|
|
|
# DELETE /moderations/1.json
|
2014-07-01 15:50:39 +02:00
|
|
|
def destroy
|
2017-05-06 15:46:22 +02:00
|
|
|
if @moderation.reason == 'r_0'
|
|
|
|
@moderation.paper_trail.without_versioning :destroy
|
|
|
|
else
|
|
|
|
@moderation.destroy!
|
|
|
|
end
|
2014-07-01 15:50:39 +02:00
|
|
|
respond_to do |format|
|
2014-11-05 21:25:18 +01:00
|
|
|
format.html { redirect_to :moderations, notice: t('.ok') }
|
2014-07-01 15:50:39 +02:00
|
|
|
format.json { head :no_content }
|
|
|
|
end
|
|
|
|
end
|
2014-01-06 11:22:39 +01:00
|
|
|
|
2014-07-01 15:50:39 +02:00
|
|
|
private
|
2014-01-06 11:22:39 +01:00
|
|
|
|
2014-08-06 14:47:47 +02:00
|
|
|
# Use callbacks to share common setup or constraints between actions.
|
|
|
|
def set_moderation
|
|
|
|
@event = Event.find params[:id]
|
|
|
|
@moderation = @event
|
|
|
|
end
|
2014-06-09 12:18:40 +02:00
|
|
|
|
2014-08-06 14:47:47 +02:00
|
|
|
# Never trust parameters from the scary internet, only allow the white list
|
|
|
|
# through.
|
|
|
|
def moderation_params
|
|
|
|
params.require(:event)
|
2016-09-11 17:40:49 +02:00
|
|
|
.permit :lock_version, :title, :start_time, :end_time, :repeat, :rule,
|
|
|
|
:description, :place_name, :address, :city, :region_id,
|
2017-05-29 22:18:04 +02:00
|
|
|
:locality, :url, :contact, :submitter, :tag_list, :reason
|
2014-08-06 14:47:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
# Useful to manage absolute url in mails
|
|
|
|
def set_mailer_host
|
|
|
|
ActionMailer::Base.default_url_options[:host] = request.host_with_port
|
|
|
|
end
|
|
|
|
|
2015-10-22 21:14:36 +02:00
|
|
|
def locked
|
|
|
|
redirect_to edit_moderation_url(@moderation), alert: t('staleObjectError')
|
2014-10-04 18:12:03 +02:00
|
|
|
end
|
2016-09-17 19:41:29 +02:00
|
|
|
|
|
|
|
def generate_destroy_reason
|
2017-05-29 22:18:04 +02:00
|
|
|
@moderation.attributes = moderation_params
|
|
|
|
return if params[:reason] == 'r_4'
|
2018-09-15 15:05:21 +02:00
|
|
|
|
2017-05-29 22:18:04 +02:00
|
|
|
@moderation.reason = t "moderations.refuse.reason_#{params[:reason]}_long"
|
2016-09-17 19:41:29 +02:00
|
|
|
end
|
2014-01-06 11:22:39 +01:00
|
|
|
end
|