2015-02-15 17:10:17 +01:00
|
|
|
# Groups life cycle
|
|
|
|
class OrgasController < ApplicationController
|
2017-07-28 00:35:14 +02:00
|
|
|
has_scope :region, :tag
|
|
|
|
has_scope :near, type: :hash, using: %i[location distance]
|
2019-04-24 19:53:49 +02:00
|
|
|
has_scope :active, type: :boolean, default: true, allow_blank: true
|
2017-07-28 00:35:14 +02:00
|
|
|
|
2017-04-22 20:01:47 +02:00
|
|
|
before_action :set_orga, except: %i[index new create]
|
|
|
|
before_action :authenticate_user!, except: %i[index new create show],
|
2015-05-25 11:42:53 +02:00
|
|
|
unless: :check_secret
|
2015-02-15 17:10:17 +01:00
|
|
|
|
|
|
|
def index
|
2017-09-17 23:43:04 +02:00
|
|
|
@unfiltered_orgas = apply_scopes(Orga.moderated)
|
2018-12-20 12:16:05 +01:00
|
|
|
@search = @unfiltered_orgas.ransack params[:q]
|
2015-12-27 15:51:25 +01:00
|
|
|
@search.sorts = 'updated_at desc' if @search.sorts.empty?
|
2015-02-15 17:10:17 +01:00
|
|
|
@orgas = @search.result.page params[:page]
|
2019-12-30 21:39:40 +01:00
|
|
|
|
|
|
|
respond_to :html, :json
|
2015-02-15 17:10:17 +01:00
|
|
|
end
|
|
|
|
|
2015-02-28 17:28:05 +01:00
|
|
|
# GET /orgas/new
|
|
|
|
def new
|
2017-09-17 18:25:34 +02:00
|
|
|
@orga = Orga.new region_id: session[:region]
|
2015-02-28 17:28:05 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# POST /orgas
|
|
|
|
# POST /orgas.json
|
|
|
|
def create
|
|
|
|
@orga = Orga.new orga_params
|
|
|
|
respond_to do |format|
|
2015-05-25 11:42:53 +02:00
|
|
|
if @orga.save
|
2018-03-01 20:42:14 +01:00
|
|
|
format.html { redirect_to @orga, notice: t('.ok') }
|
2018-05-23 09:24:42 +02:00
|
|
|
format.json { render action: 'show', status: :created, location: @orga }
|
2015-02-28 17:28:05 +01:00
|
|
|
else
|
|
|
|
format.html { render action: 'new' }
|
2018-04-05 22:00:07 +02:00
|
|
|
format.json { render json: @orga.errors, status: :unprocessable_entity }
|
2015-02-28 17:28:05 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-15 17:10:17 +01:00
|
|
|
def show
|
2015-10-22 22:03:18 +02:00
|
|
|
@events_future = Event.moderated.future.tag @orga.name_as_tag
|
|
|
|
@events_past = Event.moderated.past.tag @orga.name_as_tag
|
2015-02-15 17:10:17 +01:00
|
|
|
end
|
|
|
|
|
2015-02-28 17:28:05 +01:00
|
|
|
# PATCH/PUT /orgas/1
|
|
|
|
# PATCH/PUT /orgas/1.json
|
|
|
|
def update
|
|
|
|
respond_to do |format|
|
2015-05-25 11:42:53 +02:00
|
|
|
if @orga.update orga_params
|
2015-02-28 17:28:05 +01:00
|
|
|
format.html { redirect_to @orga, notice: t('.ok') }
|
|
|
|
format.json { head :no_content }
|
|
|
|
else
|
|
|
|
format.html { render action: 'edit' }
|
2018-04-05 22:00:07 +02:00
|
|
|
format.json { render json: @orga.errors, status: :unprocessable_entity }
|
2015-02-28 17:28:05 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-07-25 18:32:27 +02:00
|
|
|
# PATCH/PUT /accept/1
|
|
|
|
# PATCH/PUT /accept/1.json
|
|
|
|
def accept
|
|
|
|
@orga.update moderated: true
|
|
|
|
respond_to do |format|
|
2015-12-27 00:17:09 +01:00
|
|
|
format.html { redirect_to :moderations, notice: t('.ok') }
|
2015-07-25 18:32:27 +02:00
|
|
|
format.json { head :no_content }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# DELETE /orgas/1
|
|
|
|
# DELETE /orgas/1.json
|
|
|
|
def destroy
|
|
|
|
@orga.destroy
|
|
|
|
respond_to do |format|
|
2015-12-27 00:41:47 +01:00
|
|
|
format.html { redirect_to :moderations, notice: t('.ok') }
|
2015-07-25 18:32:27 +02:00
|
|
|
format.json { head :no_content }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-15 17:10:17 +01:00
|
|
|
private
|
|
|
|
|
|
|
|
# Use callbacks to share common setup or constraints between actions.
|
|
|
|
def set_orga
|
|
|
|
@orga = Orga.find params[:id]
|
|
|
|
end
|
2015-02-28 17:28:05 +01:00
|
|
|
|
|
|
|
# Never trust parameters from the scary internet, only allow the white list
|
|
|
|
# through
|
|
|
|
def orga_params
|
|
|
|
params.require(:orga)
|
2016-04-09 16:06:22 +02:00
|
|
|
.permit :lock_version, :kind_id, :name, :description, :place_name,
|
|
|
|
:address, :city, :department, :region_id, :url, :diaspora,
|
2016-12-17 16:59:11 +01:00
|
|
|
:feed, :contact, :submitter, :tag_list, :active
|
2015-02-28 17:28:05 +01:00
|
|
|
end
|
2015-05-25 11:42:53 +02:00
|
|
|
|
|
|
|
# Check that you can only edit an existing event if you know its secret
|
|
|
|
def check_secret
|
2017-04-22 20:01:47 +02:00
|
|
|
!%w[validate refuse].include?(action_name) &&
|
2016-01-26 15:31:03 +01:00
|
|
|
(!@orga.secret || @orga.secret == params[:secret])
|
2015-05-25 11:42:53 +02:00
|
|
|
end
|
2015-02-15 17:10:17 +01:00
|
|
|
end
|