Browse Source

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

recurrent
echarp 8 years ago
parent
commit
82207028b2
  1. 1
      Gemfile
  2. 19
      Gemfile.lock
  3. 5
      Guardfile
  4. 3
      Rakefile
  5. 1
      app/admin/admin_user.rb
  6. 3
      app/admin/city.rb
  7. 15
      app/admin/dashboard.rb
  8. 1
      app/controllers/application_controller.rb
  9. 176
      app/controllers/events_controller.rb
  10. 21
      app/controllers/lugs_controller.rb
  11. 26
      app/controllers/maps_controller.rb
  12. 84
      app/controllers/moderations_controller.rb
  13. 55
      app/controllers/notes_controller.rb
  14. 10
      app/controllers/regions_controller.rb
  15. 9
      app/controllers/tags_controller.rb
  16. 26
      app/controllers/users_controller.rb
  17. 1
      app/helpers/application_helper.rb
  18. 1
      app/helpers/cities_helper.rb
  19. 25
      app/helpers/events_helper.rb
  20. 12
      app/helpers/lugs_helper.rb
  21. 1
      app/helpers/maps_helper.rb
  22. 1
      app/helpers/moderations_helper.rb
  23. 1
      app/helpers/notes_helper.rb
  24. 1
      app/helpers/regions_helper.rb
  25. 1
      app/helpers/users_helper.rb
  26. 22
      app/mailers/event_mailer.rb
  27. 25
      app/mailers/moderation_mailer.rb
  28. 14
      app/mailers/note_mailer.rb
  29. 3
      app/models/admin_user.rb
  30. 62
      app/models/event.rb
  31. 4
      app/models/lug.rb
  32. 1
      app/models/note.rb
  33. 1
      app/models/region.rb
  34. 20
      app/models/user.rb
  35. 2
      app/views/events/index.html.haml
  36. 6
      app/views/events/show.html.haml
  37. 6
      app/views/lugs/show.html.haml
  38. 2
      app/views/moderation_mailer/update.text.haml
  39. 8
      app/views/tags/show.html.haml
  40. 18
      config/application.rb
  41. 3
      config/environments/development.rb
  42. 17
      config/environments/production.rb
  43. 3
      config/environments/test.rb
  44. 40
      config/initializers/active_admin.rb
  45. 6
      config/initializers/backtrace_silencers.rb
  46. 2
      config/initializers/cookies_serializer.rb
  47. 97
      config/initializers/devise.rb
  48. 4
      config/initializers/mime_types.rb
  49. 1
      config/initializers/override_mail_recipient.rb
  50. 3
      config/initializers/session_store.rb
  51. 3
      config/initializers/wrap_parameters.rb
  52. 95
      config/locales/fr.yml
  53. 10
      config/locales/kaminari.fr.yml
  54. 26
      config/routes.rb
  55. 25
      db/migrate/20131114103118_devise_create_admin_users.rb
  56. 10
      db/migrate/20131114103121_create_active_admin_comments.rb
  57. 1
      db/migrate/20140403204748_create_translation.rb
  58. 3
      db/schema.rb
  59. 13
      db/seeds.rb
  60. 17
      deploy/before_restart
  61. 1
      test/controllers/events_controller_test.rb
  62. 5
      test/controllers/lugs_controller_test.rb
  63. 4
      test/controllers/maps_controller_test.rb
  64. 2
      test/controllers/moderations_controller_test.rb
  65. 5
      test/controllers/notes_controller_test.rb
  66. 15
      test/controllers/users_controller_test.rb
  67. 8
      test/mailers/event_mailer_test.rb
  68. 11
      test/mailers/moderation_mailer_test.rb
  69. 12
      test/mailers/note_mailer_test.rb
  70. 1
      test/mailers/previews/event_mailer_preview.rb
  71. 4
      test/mailers/previews/moderation_mailer_preview.rb
  72. 35
      test/models/event_test.rb
  73. 5
      test/models/user_test.rb
  74. 23
      test/test_helper.rb

1
Gemfile

@ -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

19
Gemfile.lock

@ -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)

5
Guardfile

@ -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

3
Rakefile

@ -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__)

1
app/admin/admin_user.rb

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

3
app/admin/city.rb

@ -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

15
app/admin/dashboard.rb

@ -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

1
app/controllers/application_controller.rb

@ -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.

176
app/controllers/events_controller.rb

@ -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
# 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 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]
def check_secret
if params[:secret] != @event.secret
redirect_to :root, notice: t(:forbidden, scope: [:events, :edit])
end
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
# Useful to manage absolute url in mails
def set_mailer_host
ActionMailer::Base.default_url_options[:host] = request.host_with_port
# 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
# 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

21
app/controllers/lugs_controller.rb

@ -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

26
app/controllers/maps_controller.rb

@ -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

84
app/controllers/moderations_controller.rb

@ -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

55
app/controllers/notes_controller.rb

@ -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

10
app/controllers/regions_controller.rb

@ -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

9
app/controllers/tags_controller.rb

@ -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

26
app/controllers/users_controller.rb

@ -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

1
app/helpers/application_helper.rb

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

1
app/helpers/cities_helper.rb

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

25
app/helpers/events_helper.rb

@ -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

12
app/helpers/lugs_helper.rb

@ -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

1
app/helpers/maps_helper.rb

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

1
app/helpers/moderations_helper.rb

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

1
app/helpers/notes_helper.rb

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

1
app/helpers/regions_helper.rb

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

1
app/helpers/users_helper.rb

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

22
app/mailers/event_mailer.rb

@ -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

25
app/mailers/moderation_mailer.rb

@ -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

14
app/mailers/note_mailer.rb

@ -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

3
app/models/admin_user.rb

@ -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

62
app/models/event.rb

@ -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

4
app/models/lug.rb

@ -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

1
app/models/note.rb

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

1
app/models/region.rb

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

20
app/models/user.rb

@ -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

2
app/views/events/index.html.haml

@ -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

6
app/views/events/show.html.haml

@ -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)

6
app/views/lugs/show.html.haml

@ -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

2
app/views/moderation_mailer/update.text.haml

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

8
app/views/tags/show.html.haml

@ -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?

18
config/application.rb

@ -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

3
config/environments/development.rb

@ -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

17
config/environments/production.rb

@ -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
@ -16,7 +17,8 @@ Rails.application.configure do
# Enable Rack::Cache to put a simple HTTP cache in front of your application
# Add `rack-cache` to your Gemfile before enabling this.
# For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
# For large-scale production use, consider using a caching reverse proxy like
# nginx, varnish or squid.
# config.action_dispatch.rack_cache = true
# Disable Rails's static asset server (Apache or nginx will already do this).
@ -39,7 +41,8 @@ Rails.application.configure do
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# Force all access to the app over SSL, use Strict-Transport-Security, and
# use secure cookies.
# config.force_ssl = true
# Set to :debug to see everything in the log.
@ -56,14 +59,16 @@ Rails.application.configure do
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = "http://assets.example.com"
config.action_controller.asset_host = "http://assets%d.agendadulibre.org"
config.action_controller.asset_host = 'http://assets%d.agendadulibre.org'
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
# application.js, application.css, and all non-JS/CSS in app/assets folder
# are already added.
# config.assets.precompile += %w( search.js )
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# Set this to true and configure the email server for immediate delivery to
# raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
config.action_mailer.smtp_settings = { openssl_verify_mode: 'none' }

3
config/environments/test.rb

@ -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.
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that

40
config/initializers/active_admin.rb

@ -5,7 +5,7 @@ ActiveAdmin.setup do |config|
# Set the title that is displayed on the main layout
# for each of the active admin pages.
#
config.site_title = "Agenda Du Libre"
config.site_title = 'Agenda Du Libre'
# Set the link url for the title. For example, to take
# users to your main site. Defaults to no link.
@ -84,7 +84,6 @@ ActiveAdmin.setup do |config|
# to return the currently logged in user.
config.current_user_method = :current_admin_user
# == Logging Out
#
# Active Admin displays a logout link on each screen. These
@ -103,7 +102,6 @@ ActiveAdmin.setup do |config|
# Default:
# config.logout_link_method = :get
# == Root
#
# Set the action to call for the root path. You can set different
@ -112,10 +110,10 @@ ActiveAdmin.setup do |config|
# Default:
# config.root_to = 'dashboard#index'
# == Admin Comments
#
# This allows your users to comment on any resource registered with Active Admin.
# This allows your users to comment on any resource registered with Active
# Admin.
#
# You can completely disable comments:
# config.allow_comments = false
@ -126,27 +124,23 @@ ActiveAdmin.setup do |config|
# You can change the name under which comments are registered:
# config.comments_registration_name = 'AdminComment'
# == Batch Actions
#
# Enable and disable Batch Actions
#
config.batch_actions = true
# == Controller Filters
#
# You can add before, after and around filters to all of your
# Active Admin resources and pages from here.
#
# config.before_filter :do_something_awesome
# == Setting a Favicon
#
# config.favicon = '/assets/favicon.ico'
# == Register Stylesheets & Javascripts
#
# We recommend using the built in Active Admin layout and loading
@ -156,13 +150,13 @@ ActiveAdmin.setup do |config|
# To load a stylesheet:
# config.register_stylesheet 'my_stylesheet.css'
#
# You can provide an options hash for more control, which is passed along to stylesheet_link_tag():
# You can provide an options hash for more control, which is passed along to
# stylesheet_link_tag():
# config.register_stylesheet 'my_print_stylesheet.css', :media => :print
#
# To load a javascript file:
# config.register_javascript 'my_javascript.js'
# == CSV options
#
# Set the CSV builder separator
@ -171,16 +165,19 @@ ActiveAdmin.setup do |config|
# Force the use of quotes
# config.csv_options = { :force_quotes => true }
# == Menu System
#
# You can add a navigation menu to be used in your application, or configure a provided menu