Modération presque terminée

This commit is contained in:
echarp 2014-07-01 15:50:39 +02:00
parent c30a74af25
commit 681d97a8b0
35 changed files with 376 additions and 168 deletions

View File

@ -121,17 +121,24 @@ main
margin: 10px 20px margin: 10px 20px
input, textarea, select, a.button input, textarea, select, a.button
color: black
margin: 3px 0 margin: 3px 0
cursor: pointer
border: 1px solid #868686 border: 1px solid #868686
font-family: georgia, serif
@include border-radius(0.1em)
&:focus &:focus
background-color: #F0F8FF background-color: #F0F8FF
&[type=submit], &.button &[type=submit], &.button
color: black color: black
border: none
padding: 0.2em 0.6em padding: 0.2em 0.6em
font-size: larger font-size: larger
line-height: 1.1em line-height: 1.1em
font-weight: normal font-weight: bolder
vertical-align: baseline vertical-align: middle
background-color: #9CC5EE
@include box-shadow(2px 2px 2px gray)
select, option select, option
color: black color: black
background-color: white background-color: white

View File

@ -163,6 +163,10 @@ body.events.index table
display: inline-block display: inline-block
&:after &:after
content: ':' content: ':'
input[type=radio] + label
width: 20em
&:after
content: ''
.actions .actions
margin-left: 6.75em margin-left: 6.75em
margin-bottom: 10px margin-bottom: 10px

View File

@ -4,11 +4,11 @@ class EventsController < ApplicationController
before_filter :set_mailer_host before_filter :set_mailer_host
def index def index
@events = Event.moderated @events = Event.all_moderated
if (params[:region] && params[:region].present? && params[:region] != 'all') if params[:region] && params[:region].present? && params[:region] != 'all'
@events = @events.region(params[:region]) @events = @events.region params[:region]
end end
@events = @events.tag(params[:tag]) if (params[:tag]) @events = @events.tag(params[:tag]) if params[:tag]
respond_to do |format| respond_to do |format|
format.html { format.html {
@ -44,9 +44,7 @@ class EventsController < ApplicationController
# POST /events # POST /events
# POST /events.json # POST /events.json
def create def create
@event = Event.new(event_params) @event = Event.new event_params
# This is a special case, required to handle the region attribute with same foreign key name
@event.region = Region.find params[:event][:region]
if params[:visu] if params[:visu]
@event.valid? @event.valid?
@ -73,9 +71,6 @@ class EventsController < ApplicationController
# PATCH/PUT /events/1 # PATCH/PUT /events/1
# PATCH/PUT /events/1.json # PATCH/PUT /events/1.json
def update 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])
if params[:visu] if params[:visu]
@event.attributes = event_params @event.attributes = event_params
@event.valid? @event.valid?
@ -84,7 +79,7 @@ class EventsController < ApplicationController
end end
respond_to do |format| respond_to do |format|
if @event.update(event_params) if @event.update event_params
format.html { redirect_to @event, notice: t('.ok') } format.html { redirect_to @event, notice: t('.ok') }
format.json { head :no_content } format.json { head :no_content }
else else
@ -99,7 +94,7 @@ class EventsController < ApplicationController
def destroy def destroy
@event.destroy @event.destroy
respond_to do |format| respond_to do |format|
format.html { redirect_to events_url } format.html { redirect_to events_url, notice: t('.ok') }
format.json { head :no_content } format.json { head :no_content }
end end
end end
@ -110,7 +105,7 @@ class EventsController < ApplicationController
if params[:secret].present? if params[:secret].present?
@event = Event.where secret: params[:secret] @event = Event.where secret: params[:secret]
else else
@event = Event.moderated @event = Event.all_moderated
end end
@event = @event.find params[:id] @event = @event.find params[:id]
end end
@ -118,7 +113,7 @@ class EventsController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through. # Never trust parameters from the scary internet, only allow the white list through.
def event_params def event_params
params.require(:event) params.require(:event)
.permit :title, :start_time, :end_time, :description, :city, :locality, :url, :contact, :submitter, :tags .permit :title, :start_time, :end_time, :description, :city, :region, :locality, :url, :contact, :submitter, :tags
end end
def check_secret def check_secret

View File

@ -2,8 +2,8 @@ require 'differ'
class ModerationsController < ApplicationController class ModerationsController < ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
before_action :set_event, only: [:show, :edit, :update, :destroy] before_action :set_moderation, only: [:show, :edit, :update, :validate, :accept, :refuse, :destroy]
before_filter :set_mailer_host, only: [:update, :destroy] before_filter :set_mailer_host, only: [:update, :accept, :destroy]
def index def index
@events = Event.where moderated: 0 @events = Event.where moderated: 0
@ -12,44 +12,68 @@ class ModerationsController < ApplicationController
# PATCH/PUT /moderations/1 # PATCH/PUT /moderations/1
# PATCH/PUT /moderations/1.json # PATCH/PUT /moderations/1.json
def update 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])
if params[:visu] if params[:visu]
@event.attributes = event_params @moderation.attributes = moderation_params
render action: 'edit' render action: 'edit'
return return
end end
respond_to do |format| respond_to do |format|
if @event.update(event_params) if @moderation.update(moderation_params)
# Send an update mail to its author # Send an update mail to its author
ModerationMailer.update(@event, current_user).deliver ModerationMailer.update(@moderation, current_user).deliver
format.html { redirect_to moderations_path, notice: 'Event was successfully updated.' } format.html { redirect_to moderations_path, notice: t('.ok') }
format.json { head :no_content } format.json { head :no_content }
else else
format.html { render action: 'edit' } format.html { render action: 'edit' }
format.json { render json: @event.errors, status: :unprocessable_entity } format.json { render json: @moderation.errors, status: :unprocessable_entity }
end end
end end
end end
private # PATCH/PUT /accept/1
def permitted_params # PATCH/PUT /accept/1.json
params.require(:event).permit(:title, :start_time, :end_time, :description, :city, :locality, :url, :contact, :submitter, :tags) def accept
end respond_to do |format|
if @moderation.update(moderated: 1)
# Send an update mail to its author
ModerationMailer.accept(@moderation, current_user).deliver
format.html { redirect_to moderations_path, notice: t('.ok') }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @moderation.errors, status: :unprocessable_entity }
end
end
end
# DELETE /events/1
# DELETE /events/1.json
def destroy
if @moderation.destroy
# Send a notification to its author
@reason = 'pas cool'
ModerationMailer.destroy(@moderation, current_user, @reason).deliver
end
respond_to do |format|
format.html { redirect_to moderations_url, notice: t('.ok') }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions. # Use callbacks to share common setup or constraints between actions.
def set_event def set_moderation
@event = Event.find params[:id] @event = Event.find params[:id]
@moderation = @event @moderation = @event
end end
# Never trust parameters from the scary internet, only allow the white list through. # Never trust parameters from the scary internet, only allow the white list through.
def event_params def moderation_params
params.require(:event) params.require(:event)
.permit :title, :start_time, :end_time, :description, :city, :locality, :url, :contact, :submitter, :tags .permit :title, :start_time, :end_time, :description, :city, :region, :locality, :url, :contact, :submitter, :tags
end end
# Useful to manage absolute url in mails # Useful to manage absolute url in mails

View File

@ -13,9 +13,11 @@ class NotesController < ApplicationController
respond_to do |format| respond_to do |format|
if @note.save if @note.save
if (params[:envoiParMail] == 'oui') if params[:envoiParMail] == 'oui'
# Send an update mail to its author # Send an update mail to its author
NoteMailer.create(@note).deliver NoteMailer.create(@note).deliver
@note.contents = t('.sendByMailWrap', contents: @note.contents)
@note.save
end end
format.html { redirect_to moderations_url, notice: t('.ok') } format.html { redirect_to moderations_url, notice: t('.ok') }

View File

@ -4,7 +4,7 @@ class RegionsController < InheritedResources::Base
end end
def stats def stats
@region_events = Event.joins(:region).group(:name).count(:name) @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)

View File

@ -9,11 +9,6 @@ class ModerationMailer < ActionMailer::Base
subject: t('moderation_mailer.create.subject', subject: event.title) subject: t('moderation_mailer.create.subject', subject: event.title)
end end
# Subject can be set in your I18n file at config/locales/en.yml
# with the following lookup:
#
# en.moderation_mailer.update.subject
#
def update(event, current_user) def update(event, current_user)
@event = event @event = event
@current_user = current_user @current_user = current_user
@ -22,16 +17,20 @@ class ModerationMailer < ActionMailer::Base
subject: t('moderation_mailer.update.subject', subject: event.title) subject: t('moderation_mailer.update.subject', subject: event.title)
end end
# Subject can be set in your I18n file at config/locales/en.yml def accept(event, current_user)
# with the following lookup:
#
# en.moderation_mailer.moderate.subject
#
def moderate(event, current_user)
@event = event @event = event
@current_user = current_user @current_user = current_user
mail 'In-Reply-To' => "<mod-#{event.id}@#{ActionMailer::Base.default_url_options[:host]}>", mail 'In-Reply-To' => "<mod-#{event.id}@#{ActionMailer::Base.default_url_options[:host]}>",
subject: t('moderation_mailer.moderate.subject', subject: event.title) subject: t('moderation_mailer.accept.subject', subject: event.title)
end
def destroy(event, current_user, reason)
@event = event
@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)
end end
end end

View File

@ -1,17 +1,19 @@
# TODO migrate moderated column to a SQL bool type
class Event < ActiveRecord::Base class Event < ActiveRecord::Base
extend SimpleCalendar extend SimpleCalendar
belongs_to :region, foreign_key: 'region' belongs_to :related_region, foreign_key: 'region', class_name: Region
has_many :notes, dependent: :destroy 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, :region, :url, :contact validates_presence_of :title, :description, :city, :related_region, :url, :contact
validates_format_of :url, with: /\Ahttps?:\/\/.*\z/ validates_format_of :url, with: /\Ahttps?:\/\/.*\z/
validates :contact, email: true validates :contact, email: true
validates :submitter, email: true validates :submitter, email: true
scope :moderated, -> { where moderated: 1 } scope :all_moderated, -> { where moderated: 1 }
scope :past, -> { where('end_time < now()').order(start_time: :desc) } scope :past, -> { where('end_time < now()').order(start_time: :desc) }
scope :future, -> { where('end_time >= now()').order(start_time: :asc) } scope :future, -> { where('end_time >= now()').order(start_time: :asc) }
scope :future_30, -> { scope :future_30, -> {
@ -49,4 +51,8 @@ class Event < ActiveRecord::Base
def same_day? def same_day?
start_time.to_date == end_time.to_date start_time.to_date == end_time.to_date
end end
def is_moderated?
moderated == 1
end
end end

View File

@ -1,4 +1,4 @@
class Lug < ActiveRecord::Base class Lug < ActiveRecord::Base
belongs_to :region, foreign_key: 'region' 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 end

View File

@ -1,4 +1,4 @@
= form_for @event do |f| = form_for @event, url: (@moderation ? moderation_path(@moderation) : @event.persisted? ? event_path(@event) : nil) do |f|
- if @event.errors.any? - if @event.errors.any?
#error_explanation.error.flash #error_explanation.error.flash
%h2= "#{pluralize(@event.errors.count, "error")} prohibited this event from being saved:" %h2= "#{pluralize(@event.errors.count, "error")} prohibited this event from being saved:"
@ -39,9 +39,9 @@
= f.label Event.human_attribute_name :city = f.label Event.human_attribute_name :city
= f.text_field :city, required: true, size: 70 = f.text_field :city, required: true, size: 70
.field .field
= f.label Event.human_attribute_name :region = f.label Event.human_attribute_name :related_region
= f.select :region, = f.select :region,
options_from_collection_for_select(Region.all, 'id', 'name', @event.region && @event.region.id) options_from_collection_for_select(Region.all, 'id', 'name', @event.region)
.field .field
= f.label Event.human_attribute_name :locality = f.label Event.human_attribute_name :locality
= f.select :locality, = f.select :locality,

View File

@ -3,7 +3,7 @@
=t '.title' =t '.title'
.box .box
- if @event.moderated - if @event.is_moderated?
%h3=t '.already_moderated' %h3=t '.already_moderated'
= form_for @event, method: :delete do |f| = form_for @event, method: :delete do |f|

View File

@ -1,3 +1,6 @@
-# Otherwise the simple calendar could be empty during the first hours of a new month
- Time.zone = 'Paris'
%form.region_selector %form.region_selector
- if params[:start_date] - if params[:start_date]
= hidden_field_tag :start_date, params[:start_date] = hidden_field_tag :start_date, params[:start_date]
@ -11,9 +14,9 @@
- if params[:year] - if params[:year]
-# Whole year calendar -# Whole year calendar
%header.calendar-header.year %header.calendar-header.year
= link_to '<<', "?year=#{params[:year].to_i-1}" = link_to '<<', year: params[:year].to_i-1, tag: params[:tag], region: params[:region]
= params[:year] = params[:year]
= link_to '>>', "?year=#{params[:year].to_i+1}" = link_to '>>', year: params[:year].to_i+1, tag: params[:tag], region: params[:region]
- (1..12).each do |i| - (1..12).each do |i|
- params[:start_date] = "#{params[:year]}-#{i}-01" - params[:start_date] = "#{params[:year]}-#{i}-01"
@ -27,25 +30,27 @@
- events.select { |e| e.start_time.to_date <= date and date <= e.end_time.to_date }.sort_by { |e| e.city }.each do |event| - events.select { |e| e.start_time.to_date <= date and date <= e.end_time.to_date }.sort_by { |e| e.city }.each do |event|
%li.event %li.event
= link_to event do = link_to event do
%strong= event.city.gsub('-', ' ') %strong= event.city.gsub '-', ' '
= event.title = event.title
- else - else
= month_calendar events: @events, = month_calendar events: @events,
title: ->(start_date) { raw "#{I18n.t('date.month_names')[start_date.month]} #{link_to start_date.year, root_url(year: start_date.year), class: 'year_selector'}" }, title: ->(start_date) { raw "#{I18n.t('date.month_names')[start_date.month]} #{link_to start_date.year, root_url(year: start_date.year), class: 'year_selector'}" },
previous_link: ->(param, date_range) { link_to '<<', { param => date_range.first - 1.day } }, previous_link: ->(param, date_range) { link_to '<<', { param => date_range.first - 1.day, tag: params[:tag], region: params[:region] } },
next_link: ->(param, date_range) { link_to '>>', { param => date_range.last + 1.day } } do |date, events| next_link: ->(param, date_range) { link_to '>>', { param => date_range.last + 1.day, tag: params[:tag], region: params[:region] } } do |date, events|
.day_number= date.day .day_number= date.day
%ul.events %ul.events
- events.select { |e| e.start_time.to_date <= date and date <= e.end_time.to_date }.sort_by { |e| e.city }.each do |event| - events.select { |e| e.start_time.to_date <= date and date <= e.end_time.to_date }.sort_by { |e| e.city }.each do |event|
%li.event %li.event
= link_to event do = link_to event do
%strong= event.city.gsub('-', ' ') %strong= event.city.gsub '-', ' '
= event.title = event.title
.formats .formats
=t '.calendar_in' =raw t '.calendar_in',
= link_to('rss', events_url(:rss, tag: params[:tag], region: params[:region]))+',' rss: link_to('rss', events_url(:rss,
= link_to 'iCal', events_url(:rss, tag: params[:tag], format: :ics, tag: params[:tag], region: params[:region]) tag: params[:tag], region: params[:region])),
ou ical: link_to('iCal', events_url(:rss,
= link_to 'calendrier Google', "http://www.google.com/calendar/render?cid=#{events_url(format: :ics, tag: params[:tag], region: params[:region])}" tag: params[:tag], format: :ics, tag: params[:tag], region: params[:region])),
googleCal: link_to('calendrier Google',
"http://www.google.com/calendar/render?cid=#{events_url(format: :ics, tag: params[:tag], region: params[:region])}")

View File

@ -1,15 +1,25 @@
- if request.format == 'text/html' && controller.controller_name != 'moderations' && controller.controller_name != 'notes' && controller.action_name != 'edit' && controller.action_name != 'cancel' - if request.format == 'text/html' && controller.controller_name != 'moderations' && controller.controller_name != 'notes' && controller.action_name != 'edit' && controller.action_name != 'cancel'
#lug-list #lug-list
%h1=t '.lug-list' %h1=t '.lug-list'
- if @event.region - if @event.related_region
%ul %ul
- @event.region.lugs.order(department: :asc).each do |lug| - @event.related_region.lugs.order(department: :asc).each do |lug|
%li %li
= link_to lug.name, lug.url = link_to lug.name, lug.url
(#{lug.department}) (#{lug.department})
%h1=t '.actions' %h1=t '.actions'
= link_to t('.add_to_calendar'), root_url = link_to root_url do
%em.fa.fa-calendar
=t '.add_to_calendar'
- if user_signed_in?
= link_to edit_moderation_path @event do
%em.fa.fa-pencil
=t '.edit'
%br/
= link_to cancel_event_path @event, secret: @event.secret do
%em.fa.fa-thumbs-down
=t '.cancel'
%h2 %h2
%em= @event.city + ':' %em= @event.city + ':'
@ -29,7 +39,7 @@
%p %p
=t '.at' =t '.at'
%em= link_to(@event.city, "http://fr.wikipedia.org/wiki/#{url_encode @event.city}") + ',' %em= link_to(@event.city, "http://fr.wikipedia.org/wiki/#{url_encode @event.city}") + ','
= link_to @event.region.name, "http://fr.wikipedia.org/wiki/#{url_encode @event.region.name}" rescue nil = link_to @event.related_region.name, "http://fr.wikipedia.org/wiki/#{url_encode @event.related_region.name}" rescue nil
%h3=t '.description' %h3=t '.description'
.description .description
@ -45,7 +55,7 @@
%span.label= Event.human_attribute_name :contact %span.label= Event.human_attribute_name :contact
= mail_to @event.contact, nil, encode: :javascript, replace_at: ' CHEZ ', replace_dot: ' POINT ' = mail_to @event.contact, nil, encode: :javascript, replace_at: ' CHEZ ', replace_dot: ' POINT '
- if (@event.tags && @event.tags.present?) - if @event.tags && @event.tags.present?
%p.tags %p.tags
%span.label= Event.human_attribute_name :tags %span.label= Event.human_attribute_name :tags
- @event.tags.split.each do |tag| - @event.tags.split.each do |tag|

View File

@ -0,0 +1,18 @@
=t '.title'
\
=t '.body', author: @current_user
\
=====================================================
#{Event.human_attribute_name :title}: #{@event.title}
#{Event.human_attribute_name :start_time}: #{l @event.start_time, format: :at}
#{Event.human_attribute_name :end_time}: #{l @event.end_time, format: :at}
#{Event.human_attribute_name :region}: #{@event.region}
#{Event.human_attribute_name :city}: #{@event.city}
#{Event.human_attribute_name :url}: #{@event.url}
#{Event.human_attribute_name :contact}: #{@event.contact}
#{Event.human_attribute_name :submitter}: #{@event.submitter}
#{Event.human_attribute_name :tags}: #{@event.tags}
#{Event.human_attribute_name :description}: #{raw @event.description}
=====================================================
\
=t '.signature'

View File

@ -1,17 +1,17 @@
=t '.title' =t '.title'
\ \
=t '.body', subject: @event.title, start_time: l(@event.start_time, format: :at) =t '.body', subject: @event.title, start_time: l(@event.start_time, format: :at)
= edit_moderation_url @event = moderations_url
\ \
#{Event.human_attribute_name(:title)}: #{@event.title} #{Event.human_attribute_name :title}: #{@event.title}
#{Event.human_attribute_name(:start_time)}: #{l @event.start_time, format: :at} #{Event.human_attribute_name :start_time}: #{l @event.start_time, format: :at}
#{Event.human_attribute_name(:end_time)}: #{l @event.end_time, format: :at} #{Event.human_attribute_name :end_time}: #{l @event.end_time, format: :at}
#{Event.human_attribute_name(:region)}: #{@event.region} #{Event.human_attribute_name :region}: #{@event.region}
#{Event.human_attribute_name(:city)}: #{@event.city} #{Event.human_attribute_name :city}: #{@event.city}
#{Event.human_attribute_name(:url)}: #{@event.url} #{Event.human_attribute_name :url}: #{@event.url}
#{Event.human_attribute_name(:contact)}: #{@event.contact} #{Event.human_attribute_name :contact}: #{@event.contact}
#{Event.human_attribute_name(:submitter)}: #{@event.submitter} #{Event.human_attribute_name :submitter}: #{@event.submitter}
#{Event.human_attribute_name(:tags)}: #{@event.tags} #{Event.human_attribute_name :tags}: #{@event.tags}
#{Event.human_attribute_name(:description)}: #{raw @event.description} #{Event.human_attribute_name :description}: #{raw @event.description}
\ \
=t '.signature' =t '.signature'

View File

@ -0,0 +1,21 @@
=t '.title'
\
=t '.body', author: @current_user
\
= @reason
\
=t '.reminder'
=====================================================
#{Event.human_attribute_name :title}: #{@event.title}
#{Event.human_attribute_name :start_time}: #{l @event.start_time, format: :at}
#{Event.human_attribute_name :end_time}: #{l @event.end_time, format: :at}
#{Event.human_attribute_name :region}: #{@event.region}
#{Event.human_attribute_name :city}: #{@event.city}
#{Event.human_attribute_name :url}: #{@event.url}
#{Event.human_attribute_name :contact}: #{@event.contact}
#{Event.human_attribute_name :submitter}: #{@event.submitter}
#{Event.human_attribute_name :tags}: #{@event.tags}
#{Event.human_attribute_name :description}: #{raw @event.description}
=====================================================
\
=t '.signature'

View File

@ -1,18 +0,0 @@
=t '.title'
\
=t '.body', author: @current_user
\
=====================================================
#{Event.human_attribute_name(:title)}: #{@event.title}
#{Event.human_attribute_name(:start_time)}: #{l @event.start_time, format: :at}
#{Event.human_attribute_name(:end_time)}: #{l @event.end_time, format: :at}
#{Event.human_attribute_name(:region)}: #{@event.region}
#{Event.human_attribute_name(:city)}: #{@event.city}
#{Event.human_attribute_name(:url)}: #{@event.url}
#{Event.human_attribute_name(:contact)}: #{@event.contact}
#{Event.human_attribute_name(:submitter)}: #{@event.submitter}
#{Event.human_attribute_name(:tags)}: #{@event.tags}
#{Event.human_attribute_name(:description)}: #{raw @event.description}
=====================================================
\
=t '.signature'

View File

@ -3,6 +3,10 @@
>>> >>>
=t '.preview' =t '.preview'
- if @moderation.is_moderated?
.box
%h3=t '.warning'
.box= render file: '/events/show' .box= render file: '/events/show'
%h3 %h3

View File

@ -9,7 +9,7 @@
%th= Event.human_attribute_name :title %th= Event.human_attribute_name :title
%th=t '.date' %th=t '.date'
%th= Event.human_attribute_name :city %th= Event.human_attribute_name :city
%th= Event.human_attribute_name :region %th= Event.human_attribute_name :related_region
%th= Event.human_attribute_name :submission_time %th= Event.human_attribute_name :submission_time
%th=t '.actions' %th=t '.actions'
@ -27,18 +27,18 @@
au au
=l event.end_time, format: :at =l event.end_time, format: :at
%td= event.city %td= event.city
%td= event.region.name %td= event.related_region.name
%td= time_ago_in_words event.submission_time.to_date %td= time_ago_in_words event.submission_time.to_date
%th.actions %th.actions
= link_to edit_moderation_path event do = link_to edit_moderation_path event do
%em.fa.fa-pencil %em.fa.fa-pencil
=t 'edit' =t 'edit'
\- \-
= link_to edit_moderation_path event do = link_to validate_moderation_path event do
%em.fa.fa-thumbs-up %em.fa.fa-thumbs-up
=t 'validate' =t 'validate'
\- \-
= link_to edit_moderation_path event do = link_to refuse_moderation_path event do
%em.fa.fa-thumbs-down %em.fa.fa-thumbs-down
=t 'refuse' =t 'refuse'
%br/ %br/

View File

@ -0,0 +1,26 @@
%h3
= link_to t('.moderation'), moderations_path
>>>
=t '.title'
.box
%h2=t '.question'
= form_for @moderation, method: :delete do |f|
.field
= radio_button_tag :event, :contents_1, {}, value: t('.contents_1_long')
= label_tag :event_contents_1, t('.contents_1')
.field
= radio_button_tag :event, :contents_2, {}, value: t('.contents_2_long')
= label_tag :event_contents_2, t('.contents_2')
.field
= radio_button_tag :event, :contents_3, {}, value: t('.contents_3_long')
= label_tag :event_contents_3, t('.contents_3')
.field
= radio_button_tag :event, :contents_4, {}, value: t('.contents_4_long')
= label_tag :event_contents_4, t('.contents_4')
= f.submit t('.ok')
= link_to t('.ko'), moderations_url, class: :button
.box= render file: '/events/show'

View File

@ -0,0 +1,13 @@
%h3
= link_to t('.moderation'), moderations_path
>>>
=t '.title'
.box
%h2=t '.question'
= form_for @moderation, url: { action: :accept }, html: { method: :put } do |f|
= f.submit t('.ok'), name: :yes
= link_to t('.ko'), moderations_url, class: :button
.box= render file: '/events/show'

View File

@ -27,7 +27,9 @@
.actions .actions
= f.submit t('.save') = f.submit t('.save')
= link_to t('.ko'), moderations_url, class: :button
- else - else
.actions .actions
= f.submit t('save') = f.submit t('.ok')
= link_to t('.ko'), moderations_url, class: :button

View File

@ -18,6 +18,7 @@ fr:
created: Créé il y a %{date} created: Créé il y a %{date}
updated: Mis à jour il y a %{date} updated: Mis à jour il y a %{date}
# Base de données
activerecord: activerecord:
models: models:
admin_user: Admin admin_user: Admin
@ -39,7 +40,7 @@ fr:
inseecode: Code INSEE inseecode: Code INSEE
regioncode: Code région regioncode: Code région
lug: lug:
region: Région related_region: Région
department: Département department: Département
url: Adresse web url: Adresse web
city: Cité city: Cité
@ -49,7 +50,7 @@ fr:
end_time: Fin end_time: Fin
description: Description description: Description
city: Ville city: Ville
region: Région related_region: Région
locality: Portée locality: Portée
url: URL url: URL
contact: Contact contact: Contact
@ -91,6 +92,7 @@ fr:
at: "%A %d %B %Y à %Hh%M" at: "%A %d %B %Y à %Hh%M"
hours: "%Hh%M" hours: "%Hh%M"
# Traductions des écrans
layouts: layouts:
application: application:
login: Authentication login: Authentication
@ -112,7 +114,7 @@ fr:
moderation: Modération moderation: Modération
events: events:
index: index:
calendar_in: Ce calendrier en calendar_in: Ce calendrier en %{rss}, %{ical} ou %{googleCal}
all_regions: Toutes les régions all_regions: Toutes les régions
show: show:
lug-list: Groupes d'utilisateurs de la région lug-list: Groupes d'utilisateurs de la région
@ -122,6 +124,8 @@ fr:
description: Description description: Description
infos: Informations infos: Informations
actions: Actions actions: Actions
edit: Éditer événement
cancel: Annuler événement
new: new:
title: Soumettre un évènement title: Soumettre un évènement
create: create:
@ -129,7 +133,6 @@ fr:
edit: edit:
title: Éditer un évènement title: Éditer un évènement
preview: Prévisualisation de l'évènement preview: Prévisualisation de l'évènement
warning: Attention, cet évènement est déjà modéré. Toute modification sera immédiatement visible sur le site.
forbidden: Vous n'êtes pas authorisé à modifier cet événement forbidden: Vous n'êtes pas authorisé à modifier cet événement
edit: Édition de l'évènement edit: Édition de l'évènement
form: form:
@ -142,6 +145,8 @@ fr:
preview: Visualisation de l'évènement preview: Visualisation de l'évènement
ok: Oui ok: Oui
ko: Non ko: Non
destroy:
ok: Votre événément a bien été annulé
regions: regions:
index: index:
title: Liste des flux RSS title: Liste des flux RSS
@ -183,16 +188,44 @@ fr:
edit: edit:
moderation: Modération moderation: Modération
preview: Prévisualisation de l'évènement preview: Prévisualisation de l'évènement
warning: Attention, cet évènement est déjà modéré. Toute modification sera immédiatement visible sur le site.
edit: Édition de l'évènement edit: Édition de l'évènement
update:
ok: Événement mis à jour
validate:
title: Validation de l'évènement
question: Confirmez-vous la validation de cet évènement?
ok: Oui
ko: Non
accept:
ok: Évènement accepté
refuse:
title: Rejet de l'évènement
question: Quel motif souhaitez-vous associer au rejet de cet évènement?
ok: Rejeter
ko: Annuler
contents_1: Hors sujet
contents_2: Pas assez d'informations
contents_3: Évènement déjà enregistré
contents_4: Raison spécifique (précisez)
contents_1_long: Toutefois, l'évènement proposé n'a pour l'instant pas retenu l'attention des modérateurs. En effet, l'évènement proposé ne concerne pas le Logiciel Libre, ou bien le lien avec le Logiciel Libre n'est pas évident dans la formulation actuelle, ou alors il s'agit d'un évènement ou d'une formation payante et coûteuse. Si l'évènement concerne vraiment le Logiciel Libre et qu'il ne s'agit pas d'une formation payante, n'hésitez pas à le soumettre à nouveau avec une description plus claire.
contents_2_long: Votre évènement a tout à fait sa place dans l'Agenda du Libre, mais les modérateurs trouvent que la description de celui-ci n'est pas assez complète pour être validée.\n\nLa description doit être compréhensible par un nouveau venu dans le monde du Libre, et doit donc préciser le principe de la rencontre, le public visé, la rôle du ou des Logiciels Libres qui seront exposés, la date et le lieu précis de la rencontre. Même si il s'agit d'une rencontre régulière, n'hésitez pas à répéter à chaque fois ces informations, elles sont importantes.\n\nNous vous invitons donc vivement à soumettre à nouveau cet évènement avec une description plus complète.
contents_3_long: Votre évènement a tout à fait sa place dans l'Agenda du Libre, mais il est déjà enregistré dans celui-ci.
contents_4_long: Toutefois, votre évènement n'a pour le moment pas retenu l'attention des modérateurs, pour la raison suivante
destroy:
ok: Évènement rejeté
notes: notes:
new: new:
back: Modération back: Modération
title: Ajout d'une note de modération title: Ajout d'une note de modération
create: create:
sendByMailWrap: "<p>Demande d'informations complémentaires:</p><pre>%{contents}</pre>"
ok: La note a bien été ajoutée, merci! ok: La note a bien été ajoutée, merci!
form: form:
title: Rédaction du message title: Rédaction du message
save: Envoyer save: Envoyer
ok: Enregistrer
ko: Annuler
maps: maps:
index: index:
title: Carte des évènements title: Carte des évènements
@ -226,13 +259,19 @@ fr:
update: update:
subject: "[Agenda du Libre] Édition de l'évènement '%{subject}'" subject: "[Agenda du Libre] Édition de l'évènement '%{subject}'"
title: Bonjour, title: Bonjour,
body: "L'évènement '%{subject}' a été modifié par\n%{author}\n\nModifications apportées:" body: "L'évènement '%{subject}' a été modifié par %{author}\n\nModifications apportées:"
signature: "Bonne journée\n\n-- \nL'équipe de modération" signature: "Bonne journée\n\n-- \nL'équipe de modération"
moderate: accept:
subject: "[Agenda du Libre] Évènement '%{subject}' modéré" subject: "[Agenda du Libre] Évènement '%{subject}' modéré"
title: Bonjour, title: Bonjour,
body: L'évènement a été modéré par %{author} body: L'évènement a été modéré par %{author}
signature: "-- \nL'équipe de modération" signature: "-- \nL'équipe de modération"
destroy:
subject: "[Agenda du Libre] Évènement '%{subject}' refusé"
title: Bonjour,
body: Vous avez soumis l'évènement suivant dans l'Agenda du Libre, et nous vous remercions de cette contribution.
reminder: "Pour rappel, voici le contenu de votre évènement:"
signature: "Avec tous nos remerciements pour votre contribution,\n\n-- \nL'équipe de modération"
note_mailer: note_mailer:
create: create:
subject: "[Agenda du Libre] Demande d'informations sur l'évènement '%{subject}'" subject: "[Agenda du Libre] Demande d'informations sur l'évènement '%{subject}'"

View File

@ -13,6 +13,8 @@ Rails.application.routes.draw do
end end
resources :moderations do resources :moderations do
resources :notes, only: [:new, :create] resources :notes, only: [:new, :create]
get :validate, :refuse, on: :member
put :accept, on: :member
end end
resources :regions, only: [ :index ] do resources :regions, only: [ :index ] do
get 'icallist', on: :collection get 'icallist', on: :collection

View File

@ -1,103 +1,109 @@
require 'test_helper' require 'test_helper'
class EventsControllerTest < ActionController::TestCase class EventsControllerTest < ActionController::TestCase
include Devise::TestHelpers
setup do setup do
@event = events(:one) @event = events :one
end end
test "should get index" do test 'should get index' do
get :index get :index
assert_response :success assert_response :success
assert_not_nil assigns(:events) assert_not_nil assigns(:events)
end end
test "should get new" do test 'should get new' do
get :new get :new
assert_response :success assert_response :success
end end
test "should preview event" do test 'should preview event' do
assert_no_difference('Event.count') do assert_no_difference 'Event.count' do
post :create, visu: 'visualise', event: { post :create, visu: 'visualise', event: {
title: @event.title, title: @event.title,
start_time: @event.start_time, start_time: @event.start_time,
end_time: @event.end_time, end_time: @event.end_time,
description: @event.description, description: @event.description,
city: @event.city, city: @event.city,
region: regions(:region_one), region: @event.related_region,
locality: @event.locality, locality: @event.locality,
url: @event.url, url: @event.url,
contact: @event.contact, contact: @event.contact,
submitter: @event.submitter, submitter: @event.submitter,
tags: @event.tags tags: @event.tags
} }
assert_empty assigns(:event).errors
end end
assert_response :success assert_response :success
end end
test "should create event" do test 'should create event' do
assert_difference('Event.count') do assert_difference 'Event.count' do
post :create, event: { post :create, event: {
title: @event.title, title: @event.title,
start_time: @event.start_time, start_time: @event.start_time,
end_time: @event.end_time, end_time: @event.end_time,
description: @event.description, description: @event.description,
city: @event.city, city: @event.city,
region: regions(:region_one), region: @event.related_region,
locality: @event.locality, locality: @event.locality,
url: @event.url, url: @event.url,
contact: @event.contact, contact: @event.contact,
submitter: @event.submitter, submitter: @event.submitter,
tags: @event.tags tags: @event.tags
} }
assert_empty assigns(:event).errors.messages
end end
assert_redirected_to root_url assert_redirected_to root_url
end end
test "should show event" do test 'should show event' do
get :show, id: @event get :show, id: @event
assert_response :success assert_response :success
end end
test "should get edit" do test 'should get edit' do
get :edit, id: @event, secret: 'MyString' get :edit, id: @event, secret: 'MyString'
assert_response :success assert_response :success
end end
test "should not get edit" do test 'should not get edit' do
get :edit, id: @event get :edit, id: @event
assert_redirected_to root_url assert_redirected_to root_url
end end
test "should update event" do test 'should update event' do
patch :update, id: @event, secret: 'MyString', event: { patch :update, id: @event, secret: 'MyString', event: {
title: @event.title, title: @event.title,
start_time: @event.start_time, start_time: @event.start_time,
end_time: @event.end_time, end_time: @event.end_time,
description: @event.description, description: @event.description,
city: @event.city, city: @event.city,
region: regions(:region_one), region: @event.related_region,
locality: @event.locality, locality: @event.locality,
url: @event.url, url: @event.url,
contact: @event.contact, contact: @event.contact,
moderated: @event.moderated, moderated: @event.moderated,
moderator_mail_id: @event.moderator_mail_id,
secret: @event.secret, secret: @event.secret,
submission_time: @event.submission_time, submission_time: @event.submission_time,
submitter: @event.submitter, submitter: @event.submitter,
submitter_mail_id: @event.submitter_mail_id,
tags: @event.tags } tags: @event.tags }
assert_empty assigns(:event).errors.messages
assert_redirected_to event_path(assigns(:event)) assert_redirected_to event_path(assigns(:event))
end end
test "should get cancel page" do test 'should get cancel page' do
get :cancel, id: @event, secret: 'MyString' get :cancel, id: @event, secret: 'MyString'
assert_response :success assert_response :success
end end
test "should destroy event" do test 'should destroy event' do
assert_difference('Event.count', -1) do assert_difference('Event.count', -1) do
delete :destroy, id: @event, secret: 'MyString' delete :destroy, id: @event, secret: 'MyString'
end end

View File

@ -1,7 +1,37 @@
require 'test_helper' require 'test_helper'
class ModerationsControllerTest < ActionController::TestCase class ModerationsControllerTest < ActionController::TestCase
# test "the truth" do include Devise::TestHelpers
# assert true
# end setup do
@moderation = events :one
sign_in users(:one)
end
test 'should edit event' do
put :update, id: @moderation, event: {
title: 'hello world',
related_region: regions(:region_one)
}
assert_redirected_to moderations_path
end
test 'should accept event' do
put :accept, id: @moderation
assert assigns(:moderation).is_moderated?
assert_empty assigns(:moderation).errors
assert_redirected_to moderations_path
end
test 'should reject event' do
assert_difference 'Event.count', -1 do
delete :destroy, id: @moderation
end
assert_empty assigns(:moderation).errors
assert_redirected_to moderations_path
end
end end

View File

@ -1,6 +1,6 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one: city_one:
name: Jolie ville name: Jolie ville
majname: JOLIE VILLE majname: JOLIE VILLE
postalcode: 1 postalcode: 1
@ -9,7 +9,7 @@ one:
latitude: 1.5 latitude: 1.5
longitude: 1.5 longitude: 1.5
two: city_two:
name: Une autre ville name: Une autre ville
majname: UNE AUTRE VILLE majname: UNE AUTRE VILLE
postalcode: 1 postalcode: 1

View File

@ -5,8 +5,8 @@ one:
description: MyText description: MyText
start_time: 2013-12-28 16:04:56 start_time: 2013-12-28 16:04:56
end_time: 2013-12-28 16:04:56 end_time: 2013-12-28 16:04:56
city: Jolie ville city: city_one.name
region: region_one related_region: region_one
locality: 1 locality: 1
url: http://exemple.com url: http://exemple.com
contact: test@example.com contact: test@example.com
@ -24,8 +24,8 @@ two:
description: MyText description: MyText
start_time: 2013-12-28 16:04:56 start_time: 2013-12-28 16:04:56
end_time: 2013-12-28 16:04:56 end_time: 2013-12-28 16:04:56
city: Une autre ville city: city_two.name
region: region_one related_region: region_two
locality: 1 locality: 1
url: http://exemple.com url: http://exemple.com
contact: test2@example.com contact: test2@example.com

View File

@ -1,15 +1,15 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one: one:
region: region_one related_region: region_one
city: Jolie ville
department: 1 department: 1
name: MyString name: MyString
url: MyString url: MyString
city: MyString
two: two:
region: region_one related_region: region_two
city: Jolie ville
department: 1 department: 1
name: MyString name: MyString
url: MyString url: MyString
city: MyString

View File

@ -5,24 +5,31 @@ class ModerationMailerTest < ActionMailer::TestCase
ActionMailer::Base.default_url_options[:host] = 'localhost:3000' ActionMailer::Base.default_url_options[:host] = 'localhost:3000'
end end
test "create" do test 'create' do
mail = ModerationMailer.create(Event.unscoped.last) mail = ModerationMailer.create Event.unscoped.last
assert_match(/\[Agenda du Libre\] Nouvel évènement à modérer: .*/, mail.subject) assert_match(/\[Agenda du Libre\] Nouvel évènement à modérer: .*/, mail.subject)
assert_equal ["moderateurs@agendadulibre.org"], mail.to assert_equal ['moderateurs@agendadulibre.org'], mail.to
assert_equal ["moderateurs@agendadulibre.org"], mail.from assert_equal ['moderateurs@agendadulibre.org'], mail.from
end end
test "update" do test 'update' do
mail = ModerationMailer.update(Event.unscoped.last, User.last) mail = ModerationMailer.update Event.unscoped.last, User.last
assert_match(/\[Agenda du Libre\] Édition de l'évènement .*/, mail.subject) assert_match(/\[Agenda du Libre\] Édition de l'évènement .*/, mail.subject)
assert_equal ["moderateurs@agendadulibre.org"], mail.to assert_equal ['moderateurs@agendadulibre.org'], mail.to
assert_equal ["moderateurs@agendadulibre.org"], mail.from assert_equal ['moderateurs@agendadulibre.org'], mail.from
end end
test "moderate" do test 'accept' do
mail = ModerationMailer.moderate(Event.unscoped.last, User.last) mail = ModerationMailer.accept Event.unscoped.last, User.last
assert_match(/\[Agenda du Libre\] Évènement .* modéré/, mail.subject) assert_match(/\[Agenda du Libre\] Évènement .* modéré/, mail.subject)
assert_equal ["moderateurs@agendadulibre.org"], mail.to assert_equal ['moderateurs@agendadulibre.org'], mail.to
assert_equal ["moderateurs@agendadulibre.org"], mail.from assert_equal ['moderateurs@agendadulibre.org'], mail.from
end
test 'destroy' do
mail = ModerationMailer.destroy Event.unscoped.last, User.last, 'hello world'
assert_match(/\[Agenda du Libre\] Évènement .* refusé/, mail.subject)
assert_equal ['moderateurs@agendadulibre.org'], mail.to
assert_equal ['moderateurs@agendadulibre.org'], mail.from
end end
end end

View File

@ -5,8 +5,8 @@ class NoteMailerTest < ActionMailer::TestCase
ActionMailer::Base.default_url_options[:host] = 'localhost:3000' ActionMailer::Base.default_url_options[:host] = 'localhost:3000'
end end
test "create" do test 'create' do
mail = NoteMailer.create(Note.last) mail = NoteMailer.create Note.last
assert_match(/\[Agenda du Libre\] Demande d'informations sur l'évènement .*/, mail.subject) assert_match(/\[Agenda du Libre\] Demande d'informations sur l'évènement .*/, mail.subject)
assert_equal [Note.last.event.contact], mail.to assert_equal [Note.last.event.contact], mail.to
assert_equal ["moderateurs@agendadulibre.org"], mail.from assert_equal ["moderateurs@agendadulibre.org"], mail.from

View File

@ -4,7 +4,6 @@ class EventMailerPreview < ActionMailer::Preview
# Preview this email at http://localhost:3000/rails/mailers/event_mailer/create # Preview this email at http://localhost:3000/rails/mailers/event_mailer/create
def create def create
ActionMailer::Base.default_url_options[:host] = 'localhost:3000' ActionMailer::Base.default_url_options[:host] = 'localhost:3000'
EventMailer.create(Event.last) EventMailer.create Event.last
end end
end end

View File

@ -5,7 +5,7 @@ class ModerationMailerPreview < ActionMailer::Preview
# Preview this email at http://localhost:3000/rails/mailers/moderation_mailer/create # Preview this email at http://localhost:3000/rails/mailers/moderation_mailer/create
def create def create
ActionMailer::Base.default_url_options[:host] = 'localhost:3000' ActionMailer::Base.default_url_options[:host] = 'localhost:3000'
ModerationMailer.create(Event.last) ModerationMailer.create Event.last
end end
# Preview this email at http://localhost:3000/rails/mailers/moderation_mailer/update # Preview this email at http://localhost:3000/rails/mailers/moderation_mailer/update
@ -14,12 +14,19 @@ class ModerationMailerPreview < ActionMailer::Preview
event = Event.last event = Event.last
event.description = event.description + ' event.description = event.description + '
hello world' hello world'
ModerationMailer.update(event, User.last) ModerationMailer.update event, User.last
end end
# Preview this email at http://localhost:3000/rails/mailers/moderation_mailer/moderate # Preview this email at http://localhost:3000/rails/mailers/moderation_mailer/accept
def moderate def accept
ActionMailer::Base.default_url_options[:host] = 'localhost:3000' ActionMailer::Base.default_url_options[:host] = 'localhost:3000'
ModerationMailer.moderate(Event.last, User.last) ModerationMailer.accept Event.last, User.last
end
# Preview this email at http://localhost:3000/rails/mailers/moderation_mailer/destroy
def destroy
ActionMailer::Base.default_url_options[:host] = 'localhost:3000'
@reason = 'pas cool'
ModerationMailer.destroy Event.last, User.last, @reason
end end
end end

View File

@ -3,6 +3,6 @@ class NoteMailerPreview < ActionMailer::Preview
# Preview this email at http://localhost:3000/rails/mailers/note_mailer/create # Preview this email at http://localhost:3000/rails/mailers/note_mailer/create
def create def create
ActionMailer::Base.default_url_options[:host] = 'localhost:3000' ActionMailer::Base.default_url_options[:host] = 'localhost:3000'
NoteMailer.create(Note.last) NoteMailer.create Note.last
end end
end end

View File

@ -7,8 +7,8 @@ class EventTest < ActiveSupport::TestCase
start_time: Time.new(), start_time: Time.new(),
end_time: Time.new() + 1, end_time: Time.new() + 1,
description: 'et hop!', description: 'et hop!',
city: City.first().name, city: City.first(),
region: Region.first(), related_region: Region.first(),
url: 'http://example.com', url: 'http://example.com',
contact: 'contact@example.com', contact: 'contact@example.com',
submitter: 'submitter@example.com' submitter: 'submitter@example.com'
@ -26,8 +26,8 @@ class EventTest < ActiveSupport::TestCase
start_time: Time.new(), start_time: Time.new(),
end_time: Time.new() + 1, end_time: Time.new() + 1,
description: 'et hop!', description: 'et hop!',
city: City.first().name, city: City.first(),
region: Region.first(), related_region: Region.first(),
url: 'http://example.com', url: 'http://example.com',
contact: 'contact@example.com' contact: 'contact@example.com'
) )