Mise à jour sur les styles du code, afin de mieux suivres les préconisations de rubocop

This commit is contained in:
echarp 2014-08-06 14:47:47 +02:00
parent 26522aa4f2
commit 82207028b2
74 changed files with 708 additions and 493 deletions

View File

@ -94,6 +94,7 @@ group :development do
gem 'guard-bundler'
gem 'guard-minitest'
gem 'quiet_assets'
gem 'guard-rubocop'
gem 'webrick', '>= 1.3.1'
# Security checks
gem 'brakeman', require: false

View File

@ -1,6 +1,6 @@
GIT
remote: git://github.com/gregbell/active_admin.git
revision: 7a2a31067e99e8e484942a3cddc44be1980b1ae6
revision: efe5a86968c81fd12244e6c4b6957d93d0a4b7ee
specs:
activeadmin (1.0.0.pre)
arbre (~> 1.0)
@ -58,6 +58,7 @@ GEM
arbre (1.0.1)
activesupport (>= 3.0.0)
arel (5.0.1.20140414130214)
ast (2.0.0)
bcrypt (3.1.7)
bourbon (3.2.3)
sass (~> 3.2)
@ -134,6 +135,9 @@ GEM
guard-minitest (2.3.1)
guard (~> 2.0)
minitest (>= 3.0)
guard-rubocop (1.1.0)
guard (~> 2.0)
rubocop (~> 0.20)
haml (4.0.5)
tilt
haml-rails (0.5.3)
@ -185,9 +189,13 @@ GEM
multi_json (1.10.1)
mysql2 (0.3.16)
orm_adapter (0.5.0)
parser (2.2.0.pre.3)
ast (>= 1.1, < 3.0)
slop (~> 3.4, >= 3.4.5)
polyamorous (1.0.0)
activerecord (>= 3.0)
polyglot (0.3.5)
powerpack (0.0.9)
pry (0.10.0)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
@ -215,6 +223,7 @@ GEM
activesupport (= 4.1.4)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rainbow (2.0.0)
rake (10.3.2)
ransack (1.2.3)
actionpack (>= 3.0)
@ -231,6 +240,13 @@ GEM
ref (1.0.5)
responders (1.0.0)
railties (>= 3.2, < 5)
rubocop (0.24.1)
json (>= 1.7.7, < 2)
parser (>= 2.2.0.pre.3, < 3.0)
powerpack (~> 0.0.6)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.4)
ruby-progressbar (1.5.1)
ruby2ruby (2.0.8)
ruby_parser (~> 3.1)
sexp_processor (~> 4.0)
@ -311,6 +327,7 @@ DEPENDENCIES
guard-bundler
guard-livereload
guard-minitest
guard-rubocop
haml-rails
i18n-active_record!
jbuilder (~> 2.0)

View File

@ -34,3 +34,8 @@ guard 'brakeman', run_on_start: true, quiet: true, min_confidence: 10 do
watch(%r{^lib/.+\.rb$})
watch('Gemfile')
end
guard :rubocop, cli: ['--rails'] do
watch(%r{.+\.rb$})
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
end

View File

@ -1,5 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
# for example lib/tasks/capistrano.rake, and they will automatically be
# available to Rake.
require File.expand_path('../config/application', __FILE__)

View File

@ -1,3 +1,4 @@
# Managing the new agenda moderators, from active_admin
ActiveAdmin.register AdminUser do
index do
column :email

View File

@ -1,3 +1,4 @@
ActiveAdmin.register City do
permit_params :name, :majname, :postalcode, :inseecode, :regioncode, :latitude, :longitude
permit_params :name, :majname, :postalcode, :inseecode, :regioncode,
:latitude, :longitude
end

View File

@ -1,13 +1,14 @@
ActiveAdmin.register_page 'Dashboard' do
menu priority: 1, label: proc{ I18n.t('active_admin.dashboard') }
menu priority: 1, label: proc { I18n.t('active_admin.dashboard') }
content title: proc{ I18n.t('active_admin.dashboard') } do
content title: proc { I18n.t('active_admin.dashboard') } do
columns do
column do
panel 'Moderateurs' do
ul do
User.all.map do |user|
li link_to("#{user.firstname} #{user.lastname} (#{user.login})", user)
li link_to("#{user.firstname} #{user.lastname} (#{user.login})",
user)
end
end
end
@ -23,8 +24,12 @@ ActiveAdmin.register_page 'Dashboard' do
end
end
end
panel "ActiveAdmin" do
para %(Currently deployed: #{`git describe --tags --abbrev=0`}, #{link_to(`git rev-parse --short HEAD`, "https://gitorious.org/agenda-du-libre-rails/agenda-du-libre-rails/commit/#{`git rev-parse HEAD`}")}).html_safe
panel 'ActiveAdmin' do
para %(Currently deployed: #{`git describe --tags --abbrev=0`},
#{link_to(`git rev-parse --short HEAD`,
"https://gitorious.org/agenda-du-libre-rails/agenda-du-libre-rails/commit/
#{`git rev-parse HEAD`}")})
.html_safe
end
end
end

View File

@ -1,3 +1,4 @@
# The top level controller, where can be centralised almost everything
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.

View File

@ -1,55 +1,19 @@
# Event life cycle
# This is a central part to this project
class EventsController < ApplicationController
before_action :set_event, only: [:show, :edit, :update, :cancel, :destroy]
before_action :check_secret, only: [:edit, :update, :cancel, :destroy]
before_filter :set_mailer_host
before_action :set_mailer_host
def index
@events = Event.moderated
if params[:region] && params[:region].present? && params[:region] != 'all'
@events = @events.region params[:region]
end
@events = @events.tag(params[:tag]) if params[:tag]
respond_to do |format|
format.html {
if params[:year]
# Whole year calendar
@events = @events.year params[:year].to_i
else
if params[:start_date]
start_date = Date.parse params[:start_date]
else
start_date = Date.today
end
@events = @events.month start_date.change day: 1
end
set_meta_tags description: "#{t('layouts.application.subtitle')} - #{start_date ? t('date.month_names')[start_date.month] : ''} #{start_date ? start_date.year.to_s : params[:year]} - #{t '.nb_events', count: @events.size}",
keywords: @events.pluck(:tags)
.join(' ')
.split
.group_by { |i| i }
.reject { |k, v| v.size < 2 }
.collect { |k, v| k },
DC: {
title: t('layouts.application.title'),
subject: t('layouts.application.subtitle'),
date: start_date.to_s
}
}
format.rss {
@events = @events.future_30.includes(:related_city)
format.html { set_events }
format.rss do
@events = @events.future_30.includes :related_city
@events = @events.limit params[:daylimit] if params[:daylimit]
}
format.ics {
@events = @events.where('start_time > ?', 360.days.ago).order :id
}
format.xml {
@events = @events.order :id
}
end
format.ics { @events = @events.last_year.order :id }
format.xml { @events = @events.order :id }
end
end
@ -64,20 +28,10 @@ class EventsController < ApplicationController
# POST /events.json
def create
@event = Event.new event_params
if params[:visu]
@event.valid?
render action: :new
return
end
preview && return if params[:visu]
respond_to do |format|
if @event.save
# Send an event creation mail to its author
EventMailer.create(@event).deliver
# Send a mail to moderators
ModerationMailer.create(@event).deliver
if @event.save && send_creation_mails
format.html { redirect_to :root, notice: t('.ok') }
format.json { render action: 'show', status: :created, location: @event }
else
@ -90,19 +44,11 @@ class EventsController < ApplicationController
# PATCH/PUT /events/1
# PATCH/PUT /events/1.json
def update
olderEvent = Event.new @event.attributes
if params[:visu]
@event.attributes = event_params
@event.valid?
render action: :edit
return
end
preview_update && return if params[:visu]
@older_event = Event.new @event.attributes
respond_to do |format|
if @event.update event_params
# Send an update mail to moderators
ModerationMailer.update(olderEvent, @event, nil).deliver
if @event.update(event_params) && send_update_mails
format.html { redirect_to :root, notice: t('.ok') }
format.json { head :no_content }
else
@ -123,43 +69,69 @@ class EventsController < ApplicationController
end
private
# Use callbacks to share common setup or constraints between actions.
def set_event
if params[:secret].present?
@event = Event.where secret: params[:secret]
else
@event = Event.moderated
end
@event = @event.find params[:id]
set_meta_tags title: @event.title,
description: @event.description,
keywords: @event.tags,
DC: {
title: @event.title,
date: @event.start_time.to_s
},
geo: {
region: @event.related_region,
placename: @event.city,
position: "#{@event.related_city.try :latitude};#{@event.related_city.try :longitude}"
}
end
def set_events
@events = Event.moderated
@events = @events.region params[:region] \
if params[:region].present? && params[:region] != 'all'
@events = @events.tag(params[:tag]) if params[:tag]
# 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, :region, :locality, :url, :contact, :submitter, :tags
if params[:year]
# Whole year calendar
@events = @events.year params[:year].to_i
else
@events = @events.month params[:start_date].try(:to_date) || Date.today
end
end
def check_secret
if params[:secret] != @event.secret
redirect_to :root, notice: t(:forbidden, scope: [:events, :edit])
end
# Use callbacks to share common setup or constraints between actions.
def set_event
if params[:secret].present?
@event = Event.where secret: params[:secret]
else
@event = Event.moderated
end
@event = @event.find params[:id]
end
# Useful to manage absolute url in mails
def set_mailer_host
ActionMailer::Base.default_url_options[:host] = request.host_with_port
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, :region,
:locality, :url, :contact, :submitter, :tags
end
def check_secret
redirect_to :root, notice: t(:forbidden, scope: [:events, :edit]) \
unless params[:secret] == @event.secret
end
# Useful to manage absolute url in mails
def set_mailer_host
ActionMailer::Base.default_url_options[:host] = request.host_with_port
end
def send_creation_mails
# Send an event creation mail to its author
EventMailer.create(@event).deliver
# Send a mail to moderators
ModerationMailer.create(@event).deliver
end
def send_update_mails
# Send an update mail to moderators
ModerationMailer.update(@older_event, @event, nil).deliver
end
def preview
@event.valid?
render action: :new
end
def preview_update
@event.attributes = event_params
@event.valid?
render action: :edit
end
end

View File

@ -1,10 +1,11 @@
# Groups life cycle
class LugsController < ApplicationController
before_action :set_lug, only: [:show]
def index
@search = Lug.search params[:q]
@search.sorts = 'name' if @search.sorts.empty?
@lugs = @search.result().page params[:page]
@lugs = @search.result.page params[:page]
end
def show
@ -12,19 +13,9 @@ class LugsController < ApplicationController
end
private
# Use callbacks to share common setup or constraints between actions.
def set_lug
@lug = Lug.find params[:id]
set_meta_tags title: @lug.name,
description: @lug.url,
DC: {
title: @lug.name
},
geo: {
region: @lug.related_region,
placename: @lug.city,
position: "#{@lug.related_city.try :latitude};#{@lug.related_city.try :longitude}"
}
end
# Use callbacks to share common setup or constraints between actions.
def set_lug
@lug = Lug.find params[:id]
end
end

View File

@ -1,25 +1,15 @@
# Geocoding
#
# Access to OSM controls
class MapsController < ApplicationController
def index
respond_to do |format|
format.html
format.json {
events = Event.moderated.future.joins(:related_city).includes(:related_city)
#@cities_lug = City.joins :lugs
render json: events.collect { |event|
{
type: 'Feature',
properties: {
name: event.title,
popupContent: "<a href=\"#{event_url event}\">#{event.city}: #{event.title}</a>",
}, geometry: {
type: 'Point',
coordinates: [event.related_city.longitude, event.related_city.latitude]
}
}
}
}
format.json do
render json: Event.moderated.future
.joins(:related_city).includes(:related_city)
.map { |event| event.to_json }
end
end
end
end

View File

@ -1,29 +1,27 @@
require 'differ'
# Event management life cycle
class ModerationsController < ApplicationController
before_filter :authenticate_user!
before_action :set_moderation, only: [:show, :edit, :update, :validate, :accept, :refuse, :destroy]
before_filter :set_mailer_host, only: [:update, :accept, :destroy]
before_action :authenticate_user!
before_action :set_moderation, :set_mailer_host, only:
[:show, :edit, :update, :validate, :accept, :refuse, :destroy]
def index
@events = Event.where moderated: 0
@events = Event.unmoderated
end
# PATCH/PUT /moderations/1
# PATCH/PUT /moderations/1.json
def update
olderModeration = Event.new @event.attributes
if params[:visu]
@moderation.attributes = moderation_params
render action: 'edit'
return
end
@older_mod = Event.new @event.attributes
respond_to do |format|
if @moderation.update(moderation_params)
# Send an update mail to moderators
ModerationMailer.update(olderModeration, @moderation, current_user).deliver
if @moderation.update(moderation_params) && send_moderation_mails
format.html { redirect_to moderations_path, notice: t('.ok') }
format.json { head :no_content }
else
@ -37,13 +35,7 @@ class ModerationsController < ApplicationController
# PATCH/PUT /accept/1.json
def accept
respond_to do |format|
if @moderation.update(moderated: 1)
# Send an acceptation mail to its author
EventMailer.accept(@moderation, current_user).deliver
# Send an acceptation mail to moderators
ModerationMailer.accept(@moderation, current_user).deliver
if @moderation.update(moderated: true) && send_accept_mails
format.html { redirect_to moderations_path, notice: t('.ok') }
format.json { head :no_content }
else
@ -56,14 +48,7 @@ class ModerationsController < ApplicationController
# DELETE /events/1
# DELETE /events/1.json
def destroy
if @moderation.destroy
# Send a notification to its author
if params[:reason] == 'r_4'
@reason = params[:reason_text]
else
@reason = t("reason_#{params[:reason]}_long", scope: [:moderations, :refuse])
end
if @moderation.destroy && send_destroy_mails
EventMailer.destroy(@moderation, current_user, @reason).deliver
ModerationMailer.destroy(@moderation, current_user, @reason).deliver
end
@ -74,20 +59,45 @@ class ModerationsController < ApplicationController
end
private
# Use callbacks to share common setup or constraints between actions.
def set_moderation
@event = Event.find params[:id]
@moderation = @event
end
# Never trust parameters from the scary internet, only allow the white list through.
def moderation_params
params.require(:event)
.permit :title, :start_time, :end_time, :description, :city, :region, :locality, :url, :contact, :submitter, :tags
end
# Use callbacks to share common setup or constraints between actions.
def set_moderation
@event = Event.find params[:id]
@moderation = @event
end
# Useful to manage absolute url in mails
def set_mailer_host
ActionMailer::Base.default_url_options[:host] = request.host_with_port
# Never trust parameters from the scary internet, only allow the white list
# through.
def moderation_params
params.require(:event)
.permit :title, :start_time, :end_time, :description, :city, :region,
:locality, :url, :contact, :submitter, :tags
end
# Useful to manage absolute url in mails
def set_mailer_host
ActionMailer::Base.default_url_options[:host] = request.host_with_port
end
def send_moderation_mails
# Send an update mail to moderators
ModerationMailer.update(@older_mod, @moderation, current_user).deliver
end
def send_accept_mails
# Send an acceptation mail to its author
EventMailer.accept(@moderation, current_user).deliver
# Send an acceptation mail to moderators
ModerationMailer.accept(@moderation, current_user).deliver
end
def send_destroy_mails
# Send a notification to its author
if params[:reason] == 'r_4'
@reason = params[:reason_text]
else
@reason = t "moderations.refuse.reason_#{params[:reason]}_long"
end
end
end

View File

@ -1,6 +1,6 @@
# Events, particulary during moderation, can have notes associated to them
class NotesController < ApplicationController
before_action :set_event, only: [:new, :create]
before_filter :set_mailer_host, only: [:create]
before_action :set_event, :set_mailer_host, only: [:new, :create]
# GET /moderations/id/new
def new
@ -8,21 +8,12 @@ class NotesController < ApplicationController
end
def create
@note = @moderation.notes.new(note_params)
@note.author = current_user
@note = @moderation.notes.new note_params.merge author: current_user
respond_to do |format|
if @note.save
if params[:envoiParMail] == 'oui'
# Send an update mail to its author
NoteMailer.notify(@note).deliver
@note.contents = t '.sendByMailWrap', contents: @note.contents
@note.save
end
NoteMailer.create(@note).deliver
if @note.save && send_mails
format.html { redirect_to moderations_url, notice: t('.ok') }
format.json { render action: 'show', status: :created, location: @event }
format.json { render action: :show, status: :created, location: @event }
else
format.html { render action: 'new' }
format.json { render json: @note.errors, status: :unprocessable_entity }
@ -31,19 +22,31 @@ class NotesController < ApplicationController
end
private
# Use callbacks to share common setup or constraints between actions.
def set_event
@event = Event.find params[:moderation_id]
@moderation = @event
end
# Never trust parameters from the scary internet, only allow the white list through.
def note_params
params.require(:note).permit :contents
end
# Use callbacks to share common setup or constraints between actions.
def set_event
@event = Event.find params[:moderation_id]
@moderation = @event
end
# Useful to manage absolute url in mails
def set_mailer_host
ActionMailer::Base.default_url_options[:host] = request.host_with_port
# Never trust parameters from the scary internet, only allow the white list
# through.
def note_params
params.require(:note).permit :contents
end
# Useful to manage absolute url in mails
def set_mailer_host
ActionMailer::Base.default_url_options[:host] = request.host_with_port
end
def send_mails
if params[:envoiParMail] == 'oui'
# Send an update mail to its author
NoteMailer.notify(@note).deliver
@note.contents = t '.sendByMailWrap', contents: @note.contents
@note.save
end
NoteMailer.create(@note).deliver
end
end

View File

@ -1,15 +1,17 @@
# Manage regions, mostly get stats out of them
class RegionsController < InheritedResources::Base
def stats
@region_events = Event.joins(:related_region).group(:name).count(:name)
@city_events = Event.group(:city).having('count(city) > 3').order('count(city) desc').count(:city)
@city_events = Event.group(:city).having('count(city) > 3')
.order('count(city) desc').count :city
# Used in sqlite
#.group('strftime("%Y", start_time)')
#.group('strftime("%m", start_time)')
# .group('strftime("%Y", start_time)')
# .group('strftime("%m", start_time)')
@month_events = Event
.group('extract(year from start_time)')
.group('extract(month from start_time)')
.count()
.count
end
end

View File

@ -1,3 +1,4 @@
# Manage event tags
class TagsController < InheritedResources::Base
def index
@tags = Event
@ -5,13 +6,13 @@ class TagsController < InheritedResources::Base
.join(' ')
.split
.group_by { |i| i }
.reject { |k, v| v.size < 2 }
.collect { |k, v| [k, v.size()] }
.reject { |_k, v| v.size < 2 }
.map { |k, v| [k, v.size] }
.sort
end
def show
@eventsFuture = Event.future.tag params[:id]
@eventsPast = Event.past.tag params[:id]
@events_future = Event.future.tag params[:id]
@events_past = Event.past.tag params[:id]
end
end

View File

@ -1,5 +1,6 @@
# Moderators life cycle
class UsersController < ApplicationController
before_filter :authenticate_user!
before_action :authenticate_user!
before_action :set_user, only: [:show, :edit, :update, :destroy]
# GET /users
@ -29,7 +30,7 @@ class UsersController < ApplicationController
respond_to do |format|
if @user.save
format.html { redirect_to @user, notice: 'User was successfully created.' }
format.html { redirect_to @user, notice: 'User successfully created' }
format.json { render action: 'show', status: :created, location: @user }
else
format.html { render action: 'new' }
@ -43,7 +44,7 @@ class UsersController < ApplicationController
def update
respond_to do |format|
if @user.update(user_params)
format.html { redirect_to @user, notice: 'User was successfully updated.' }
format.html { redirect_to @user, notice: 'User successfully updated' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
@ -63,13 +64,16 @@ class UsersController < ApplicationController
end
private
# Use callbacks to share common setup or constraints between actions.
def set_user
@user = User.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def user_params
params.require(:user).permit(:login, :email, :lastname, :firstname, :password)
end
# Use callbacks to share common setup or constraints between actions.
def set_user
@user = User.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list
# through.
def user_params
params.require(:user).permit :login, :email, :lastname, :firstname,
:password
end
end

View File

@ -1,2 +1,3 @@
# Helper for the global application
module ApplicationHelper
end

View File

@ -1,2 +1,3 @@
# Helper for the city views
module CitiesHelper
end

View File

@ -1,2 +1,27 @@
# Helper for the event views
module EventsHelper
def set_events_meta
set_meta_tags \
description: "#{t 'layouts.application.subtitle'} \
- #{t '.nb_events', count: @events.size}",
keywords: @events.pluck(:tags)
.join(' ').split.group_by { |i| i }
.reject { |_k, v| v.size < 2 }.map { |k, _v| k },
DC: {
title: t('layouts.application.title'),
subject: t('layouts.application.subtitle')
}
end
def set_event_meta
set_meta_tags \
keywords: @event.tags,
DC: { title: @event.title, date: @event.start_time.to_s },
geo: {
region: @event.related_region,
placename: @event.city,
position: "#{@event.related_city.try :latitude};" \
+ "#{@event.related_city.try :longitude}"
}
end
end

View File

@ -1,2 +1,14 @@
# Helper for the lug views
module LugsHelper
def set_lug_meta
set_meta_tags \
description: @lug.url,
DC: { title: @lug.name },
geo: {
region: @lug.related_region,
placename: @lug.city,
position: "#{@lug.related_city.try :latitude};" \
+ "#{@lug.related_city.try :longitude}"
}
end
end

View File

@ -1,2 +1,3 @@
# Helper for the map views
module MapsHelper
end

View File

@ -1,2 +1,3 @@
# Helper for the moderation views
module ModerationsHelper
end

View File

@ -1,2 +1,3 @@
# Helper for the note views
module NotesHelper
end

View File

@ -1,2 +1,3 @@
# Helper for the region views
module RegionsHelper
end

View File

@ -1,2 +1,3 @@
# Helper for the user views
module UsersHelper
end

View File

@ -1,19 +1,22 @@
# Sending mails related to events life cycle
class EventMailer < ActionMailer::Base
def create(event)
@event = event
mail 'Message-ID' => "<event-#{event.id}@#{ActionMailer::Base.default_url_options[:host]}>",
to: event.submitter,
subject: t('event_mailer.create.subject', subject: event.title)
mail 'Message-ID' =>
"<event-#{event.id}@#{ActionMailer::Base.default_url_options[:host]}>",
to: event.submitter,
subject: t('event_mailer.create.subject', subject: event.title)
end
def accept(event, current_user)
@event = event
@current_user = current_user
mail 'In-Reply-To' => "<event-#{event.id}@#{ActionMailer::Base.default_url_options[:host]}>",
to: event.submitter,
subject: t('event_mailer.accept.subject', subject: event.title)
mail 'In-Reply-To' =>
"<event-#{event.id}@#{ActionMailer::Base.default_url_options[:host]}>",
to: event.submitter,
subject: t('event_mailer.accept.subject', subject: event.title)
end
def destroy(event, current_user, reason)
@ -21,8 +24,9 @@ class EventMailer < ActionMailer::Base
@current_user = current_user
@reason = reason
mail 'In-Reply-To' => "<event-#{event.id}@#{ActionMailer::Base.default_url_options[:host]}>",
to: event.submitter,
subject: t('event_mailer.destroy.subject', subject: event.title)
mail 'In-Reply-To' =>
"<event-#{event.id}@#{ActionMailer::Base.default_url_options[:host]}>",
to: event.submitter,
subject: t('event_mailer.destroy.subject', subject: event.title)
end
end

View File

@ -1,26 +1,30 @@
# Sending mails related to events' moderation
class ModerationMailer < ActionMailer::Base
def create(event)
@event = event
mail 'Message-ID' => "<mod-#{event.id}@#{ActionMailer::Base.default_url_options[:host]}>",
subject: t('moderation_mailer.create.subject', subject: event.title)
mail 'Message-ID' =>
"<mod-#{event.id}@#{ActionMailer::Base.default_url_options[:host]}>",
subject: t('moderation_mailer.create.subject', subject: event.title)
end
def update(olderEvent, event, current_user)
@olderEvent = olderEvent
def update(older_event, event, current_user)
@older_event = older_event
@event = event
@current_user = current_user
mail 'In-Reply-To' => "<mod-#{event.id}@#{ActionMailer::Base.default_url_options[:host]}>",
subject: t('moderation_mailer.update.subject', subject: event.title)
mail 'In-Reply-To' =>
"<mod-#{event.id}@#{ActionMailer::Base.default_url_options[:host]}>",
subject: t('moderation_mailer.update.subject', subject: event.title)
end
def accept(event, current_user)
@event = event
@current_user = current_user
mail 'In-Reply-To' => "<mod-#{event.id}@#{ActionMailer::Base.default_url_options[:host]}>",
subject: t('moderation_mailer.accept.subject', subject: event.title)
mail 'In-Reply-To' =>
"<mod-#{event.id}@#{ActionMailer::Base.default_url_options[:host]}>",
subject: t('moderation_mailer.accept.subject', subject: event.title)
end
def destroy(event, current_user, reason)
@ -28,7 +32,8 @@ class ModerationMailer < ActionMailer::Base
@current_user = current_user
@reason = reason
mail 'In-Reply-To' => "<mod-#{event.id}@#{ActionMailer::Base.default_url_options[:host]}>",
subject: t('moderation_mailer.destroy.subject', subject: event.title)
mail 'In-Reply-To' =>
"<mod-#{event.id}@#{ActionMailer::Base.default_url_options[:host]}>",
subject: t('moderation_mailer.destroy.subject', subject: event.title)
end
end

View File

@ -1,16 +1,20 @@
# Sending mails related to events' notes
class NoteMailer < ActionMailer::Base
def notify(note)
@note = note
mail 'In-Reply-To' => "<event-#{note.event.id}@#{ActionMailer::Base.default_url_options[:host]}>",
to: note.event.submitter,
subject: t('note_mailer.notify.subject', subject: note.event.title)
mail 'In-Reply-To' =>
"<event-#{note.event.id}@" \
+ "#{ActionMailer::Base.default_url_options[:host]}>",
to: note.event.submitter,
subject: t('note_mailer.notify.subject', subject: note.event.title)
end
def create(note)
@note = note
mail 'In-Reply-To' => "<mod-#{note.event.id}@#{ActionMailer::Base.default_url_options[:host]}>",
subject: t('note_mailer.create.subject', subject: note.event.title)
mail 'In-Reply-To' =>
"<mod-#{note.event.id}@#{ActionMailer::Base.default_url_options[:host]}>",
subject: t('note_mailer.create.subject', subject: note.event.title)
end
end

View File

@ -1,6 +1,7 @@
# The new agenda moderators, from active_admin
class AdminUser < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable,
devise :database_authenticatable,
:recoverable, :rememberable, :trackable, :validatable
end

View File

@ -1,43 +1,52 @@
# This is the central ADL class, where are managed all events
class Event < ActiveRecord::Base
extend SimpleCalendar
belongs_to :related_region, foreign_key: 'region', class_name: Region
has_many :notes, dependent: :destroy
has_one :related_city, foreign_key: :name, primary_key: :city, class_name: City
has_one :related_city, foreign_key: :name, primary_key: :city,
class_name: City
validates_presence_of :title, :description, :city, :related_region, :url, :contact
validates_format_of :url, with: /\Ahttps?:\/\/.*\z/
validates :title, presence: true
validates :description, presence: true
validates :city, presence: true
validates :related_region, presence: true
validates :url, presence: true, format: %r{\Ahttps?:\/\/.*\z}
validates :contact, presence: true
validates :contact, email: true
validates :submitter, email: true
scope :moderated, -> { where moderated: true }
scope :past, -> { where('end_time < ?', DateTime.now).order(start_time: :desc) }
scope :future, -> { where('end_time >= ?', DateTime.now).order(start_time: :asc) }
scope :future_30, -> {
scope :unmoderated, -> { where moderated: false }
scope :last_year, -> { where 'start_time >= ?', 360.days.ago }
scope :past, (lambda do
where('end_time < ?', DateTime.now).order start_time: :desc
end)
scope :future, (lambda do
where('end_time >= ?', DateTime.now).order start_time: :asc
end)
scope :future_30, (lambda do
where('start_time >= ? and end_time <= ?', DateTime.now, 30.days.from_now)
.order :start_time
}
scope :year, -> year {
end)
scope :year, (lambda do |year|
where '? <= end_time and start_time <= ?',
Date.new(year, 1, 1).beginning_of_week, Date.new(year, 12, 31).end_of_week
}
scope :month, -> start_date {
Date.new(year, 1, 1).beginning_of_week, Date.new(year, 12, 31)
.end_of_week
end)
scope :month, (lambda do |start_date|
where '? <= end_time and start_time <= ?',
start_date.beginning_of_week,
start_date.next_month.end_of_week
}
start_date.beginning_of_month.beginning_of_week,
start_date.beginning_of_month.next_month.end_of_week
end)
scope :region, -> region { where 'region = ? or locality', region }
scope :tag, -> tag { where 'tags like ?', "%#{tag}%" }
before_validation on: :create do
self.submission_time = DateTime.now
self.decision_time = DateTime.now
if self.submitter.empty?
self.submitter = self.contact
end
self.submitter = contact if submitter.empty?
end
before_create do
@ -47,7 +56,7 @@ class Event < ActiveRecord::Base
end
before_update do
if moderated? and moderated_was != moderated
if moderated? && moderated_was != moderated
self.decision_time = DateTime.now
end
end
@ -55,4 +64,17 @@ class Event < ActiveRecord::Base
def same_day?
start_time.to_date == end_time.to_date
end
def to_json
{ type: 'Feature', properties: {
name: title,
popupContent: "<a href=\"/#{self.class.name.downcase.pluralize}/#{id}\"" \
+ ">#{city}: #{title}</a>"
},
geometry: {
type: 'Point',
coordinates: [related_city.longitude, related_city.latitude]
}
}
end
end

View File

@ -1,4 +1,6 @@
# Groups related to this agenda
class Lug < ActiveRecord::Base
belongs_to :related_region, foreign_key: 'region', class_name: Region
has_one :related_city, foreign_key: :name, primary_key: :city, class_name: City
has_one :related_city, foreign_key: :name, primary_key: :city,
class_name: City
end

View File

@ -1,3 +1,4 @@
# Manages data related to events' moderation
class Note < ActiveRecord::Base
belongs_to :event
belongs_to :author, class_name: User

View File

@ -1,3 +1,4 @@
# This is mostly to group events around a region
class Region < ActiveRecord::Base
has_many :lugs, foreign_key: :region

View File

@ -1,25 +1,28 @@
require 'digest/md5'
# Moderators, but using a failed pwd mechanism
# TODO, migrate to full active_admin
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, authentication_keys: [:login]
#, :registerable, :validatable
# :registerable, :validatable
has_many :notes
def encrypted_password=(pass)
write_attribute :password, pass
self[:password] = pass
end
def encrypted_password
read_attribute :password
self[:password]
end
def self.find_first_by_auth_conditions(warden_conditions)
conditions = warden_conditions.dup
if login = conditions.delete(:login)
where(conditions).where(["login = :value", { value: login }]).first
login = conditions.delete(:login)
if login.present?
where(conditions).where(['login = :value', { value: login }]).first
else
where(conditions).first
end
@ -34,7 +37,8 @@ class User < ActiveRecord::Base
end
protected
def password_digest(password)
Digest::MD5.hexdigest password
end
def password_digest(password)
Digest::MD5.hexdigest password
end
end

View File

@ -1,3 +1,5 @@
- set_events_meta
= render '/lugs/search' unless controller.controller_name == 'lugs'
-# Seems necessary, for the time being, to ensure calendar is changing days correctly

View File

@ -1,6 +1,8 @@
- set_event_meta
%h2
%em.city= @event.city
= @event.title
= title @event.title
- if @event.persisted? && request.format == 'text/html' && controller.controller_name == 'events' && controller.action_name == 'show'
%sidebar#lug-list
@ -47,7 +49,7 @@
%h3=t '.description'
.description
- markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true)
= sanitize markdown.render(@event.description),
= description sanitize markdown.render(@event.description),
tags: %w(p br table tr th td ul ol li a strong b em i img),
attributes: %w(href src width height)

View File

@ -1,6 +1,8 @@
- set_lug_meta
%h2
%em.fa.fa-users
= title t 'lugs.search.title', entity: Lug.model_name.human
= t 'lugs.search.title', entity: Lug.model_name.human
= render 'search'
@ -9,7 +11,7 @@
%dd
%h3
= image_tag @lug.url+'/favicon.ico', alt: '', class: :favicon
= @lug.name
= title @lug.name
- if @lug.city.present?
%dt= Lug.human_attribute_name :city
%dd= @lug.city

View File

@ -5,7 +5,7 @@
- new = render file: '/events/show'
- former = @event
- @event = @olderEvent
- @event = @older_event
- prev = render file: '/events/show'
- @event = former

View File

@ -2,9 +2,9 @@
=t '.title'
%em= params[:id]
%p=raw t '.future', count: @eventsFuture.count
%p=raw t '.future', count: @events_future.count
%ul
- @eventsFuture.each do |event|
- @events_future.each do |event|
%li
%div= link_to event.title, event
- if event.same_day?
@ -18,9 +18,9 @@
à
= event.city
%p=raw t '.past', count: @eventsPast.count
%p=raw t '.past', count: @events_past.count
%ul
- @eventsPast.each do |event|
- @events_past.each do |event|
%li
%div= link_to event.title, event
- if event.same_day?

View File

@ -7,17 +7,23 @@ require 'rails/all'
Bundler.require(*Rails.groups)
module AgendaDuLibreRails
# All the specific configuraton for ADL
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Settings in config/environments/* take precedence over those specified
# here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# Set Time.zone default to the specified zone and make Active Record
# auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names.
# Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# The default locale is :en and all translations from
# config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path +=
# Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
config.i18n.default_locale = :fr
@ -28,6 +34,6 @@ module AgendaDuLibreRails
to: 'moderateurs@agendadulibre.org'
}
#config.quiet_assets = false
# config.quiet_assets = false
end
end

View File

@ -1,5 +1,6 @@
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Settings specified here will take precedence over those in
# config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development

View File

@ -1,5 +1,6 @@
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Settings specified here will take precedence over those in
# config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true