diff --git a/app/assets/stylesheets/all.css.sass b/app/assets/stylesheets/all.css.sass index 65c0c4d3..a2e2055f 100644 --- a/app/assets/stylesheets/all.css.sass +++ b/app/assets/stylesheets/all.css.sass @@ -121,17 +121,24 @@ main margin: 10px 20px input, textarea, select, a.button + color: black margin: 3px 0 + cursor: pointer border: 1px solid #868686 + font-family: georgia, serif + @include border-radius(0.1em) &:focus background-color: #F0F8FF &[type=submit], &.button color: black + border: none padding: 0.2em 0.6em font-size: larger line-height: 1.1em - font-weight: normal - vertical-align: baseline + font-weight: bolder + vertical-align: middle + background-color: #9CC5EE + @include box-shadow(2px 2px 2px gray) select, option color: black background-color: white diff --git a/app/assets/stylesheets/events.css.sass b/app/assets/stylesheets/events.css.sass index 662d4698..5cc3074e 100644 --- a/app/assets/stylesheets/events.css.sass +++ b/app/assets/stylesheets/events.css.sass @@ -163,6 +163,10 @@ body.events.index table display: inline-block &:after content: ':' + input[type=radio] + label + width: 20em + &:after + content: '' .actions margin-left: 6.75em margin-bottom: 10px diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index 478a4e91..739e8ea2 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -4,11 +4,11 @@ class EventsController < ApplicationController before_filter :set_mailer_host def index - @events = Event.moderated - if (params[:region] && params[:region].present? && params[:region] != 'all') - @events = @events.region(params[:region]) + @events = Event.all_moderated + if params[:region] && params[:region].present? && params[:region] != 'all' + @events = @events.region params[:region] end - @events = @events.tag(params[:tag]) if (params[:tag]) + @events = @events.tag(params[:tag]) if params[:tag] respond_to do |format| format.html { @@ -44,9 +44,7 @@ class EventsController < ApplicationController # POST /events # POST /events.json def create - @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] + @event = Event.new event_params if params[:visu] @event.valid? @@ -73,9 +71,6 @@ class EventsController < ApplicationController # PATCH/PUT /events/1 # PATCH/PUT /events/1.json 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] @event.attributes = event_params @event.valid? @@ -84,7 +79,7 @@ class EventsController < ApplicationController end respond_to do |format| - if @event.update(event_params) + if @event.update event_params format.html { redirect_to @event, notice: t('.ok') } format.json { head :no_content } else @@ -99,7 +94,7 @@ class EventsController < ApplicationController def destroy @event.destroy respond_to do |format| - format.html { redirect_to events_url } + format.html { redirect_to events_url, notice: t('.ok') } format.json { head :no_content } end end @@ -110,7 +105,7 @@ class EventsController < ApplicationController if params[:secret].present? @event = Event.where secret: params[:secret] else - @event = Event.moderated + @event = Event.all_moderated end @event = @event.find params[:id] end @@ -118,7 +113,7 @@ class EventsController < ApplicationController # 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, :locality, :url, :contact, :submitter, :tags + .permit :title, :start_time, :end_time, :description, :city, :region, :locality, :url, :contact, :submitter, :tags end def check_secret diff --git a/app/controllers/moderations_controller.rb b/app/controllers/moderations_controller.rb index e7472c3e..7f779a2b 100644 --- a/app/controllers/moderations_controller.rb +++ b/app/controllers/moderations_controller.rb @@ -2,8 +2,8 @@ require 'differ' class ModerationsController < ApplicationController before_filter :authenticate_user! - before_action :set_event, only: [:show, :edit, :update, :destroy] - before_filter :set_mailer_host, only: [:update, :destroy] + before_action :set_moderation, only: [:show, :edit, :update, :validate, :accept, :refuse, :destroy] + before_filter :set_mailer_host, only: [:update, :accept, :destroy] def index @events = Event.where moderated: 0 @@ -12,44 +12,68 @@ class ModerationsController < ApplicationController # PATCH/PUT /moderations/1 # PATCH/PUT /moderations/1.json 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] - @event.attributes = event_params + @moderation.attributes = moderation_params render action: 'edit' return end respond_to do |format| - if @event.update(event_params) + if @moderation.update(moderation_params) # 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 } else 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 - private - def permitted_params - params.require(:event).permit(:title, :start_time, :end_time, :description, :city, :locality, :url, :contact, :submitter, :tags) - end + # PATCH/PUT /accept/1 + # PATCH/PUT /accept/1.json + def accept + 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. - def set_event + 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 event_params + def moderation_params 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 # Useful to manage absolute url in mails diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 71844df2..ca96536a 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -13,9 +13,11 @@ class NotesController < ApplicationController respond_to do |format| if @note.save - if (params[:envoiParMail] == 'oui') + if params[:envoiParMail] == 'oui' # Send an update mail to its author NoteMailer.create(@note).deliver + @note.contents = t('.sendByMailWrap', contents: @note.contents) + @note.save end format.html { redirect_to moderations_url, notice: t('.ok') } diff --git a/app/controllers/regions_controller.rb b/app/controllers/regions_controller.rb index 46879cb3..9c205de3 100644 --- a/app/controllers/regions_controller.rb +++ b/app/controllers/regions_controller.rb @@ -4,7 +4,7 @@ class RegionsController < InheritedResources::Base end 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) diff --git a/app/mailers/moderation_mailer.rb b/app/mailers/moderation_mailer.rb index dc67add6..bc6d8d5b 100644 --- a/app/mailers/moderation_mailer.rb +++ b/app/mailers/moderation_mailer.rb @@ -9,11 +9,6 @@ class ModerationMailer < ActionMailer::Base subject: t('moderation_mailer.create.subject', subject: event.title) 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) @event = event @current_user = current_user @@ -22,16 +17,20 @@ class ModerationMailer < ActionMailer::Base subject: t('moderation_mailer.update.subject', subject: event.title) end - # Subject can be set in your I18n file at config/locales/en.yml - # with the following lookup: - # - # en.moderation_mailer.moderate.subject - # - def moderate(event, current_user) + def accept(event, current_user) @event = event @current_user = current_user mail 'In-Reply-To' => "", - 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' => "", + subject: t('moderation_mailer.destroy.subject', subject: event.title) end end diff --git a/app/models/event.rb b/app/models/event.rb index 885aef08..a13da890 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -1,17 +1,19 @@ +# TODO migrate moderated column to a SQL bool type + class Event < ActiveRecord::Base extend SimpleCalendar - belongs_to :region, foreign_key: 'region' + 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 - 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 :contact, 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 :future, -> { where('end_time >= now()').order(start_time: :asc) } scope :future_30, -> { @@ -49,4 +51,8 @@ class Event < ActiveRecord::Base def same_day? start_time.to_date == end_time.to_date end + + def is_moderated? + moderated == 1 + end end diff --git a/app/models/lug.rb b/app/models/lug.rb index b264edcd..7adafbc2 100644 --- a/app/models/lug.rb +++ b/app/models/lug.rb @@ -1,4 +1,4 @@ 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 end diff --git a/app/views/events/_form.html.haml b/app/views/events/_form.html.haml index fbdecf93..e9f83b6a 100644 --- a/app/views/events/_form.html.haml +++ b/app/views/events/_form.html.haml @@ -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? #error_explanation.error.flash %h2= "#{pluralize(@event.errors.count, "error")} prohibited this event from being saved:" @@ -39,9 +39,9 @@ = f.label Event.human_attribute_name :city = f.text_field :city, required: true, size: 70 .field - = f.label Event.human_attribute_name :region + = f.label Event.human_attribute_name :related_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 = f.label Event.human_attribute_name :locality = f.select :locality, diff --git a/app/views/events/cancel.html.haml b/app/views/events/cancel.html.haml index fd87101d..9a583c1a 100644 --- a/app/views/events/cancel.html.haml +++ b/app/views/events/cancel.html.haml @@ -3,7 +3,7 @@ =t '.title' .box - - if @event.moderated + - if @event.is_moderated? %h3=t '.already_moderated' = form_for @event, method: :delete do |f| diff --git a/app/views/events/index.html.haml b/app/views/events/index.html.haml index 3bcc6408..74e36210 100644 --- a/app/views/events/index.html.haml +++ b/app/views/events/index.html.haml @@ -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 - if params[:start_date] = hidden_field_tag :start_date, params[:start_date] @@ -11,9 +14,9 @@ - if params[:year] -# Whole year calendar %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] - = 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| - 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| %li.event = link_to event do - %strong= event.city.gsub('-', ' ') + %strong= event.city.gsub '-', ' ' = event.title - else = 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'}" }, - previous_link: ->(param, date_range) { link_to '<<', { param => date_range.first - 1.day } }, - next_link: ->(param, date_range) { link_to '>>', { param => date_range.last + 1.day } } do |date, events| + 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, tag: params[:tag], region: params[:region] } } do |date, events| .day_number= date.day %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| %li.event = link_to event do - %strong= event.city.gsub('-', ' ') + %strong= event.city.gsub '-', ' ' = event.title .formats - =t '.calendar_in' - = link_to('rss', events_url(:rss, tag: params[:tag], region: params[:region]))+',' - = link_to 'iCal', events_url(:rss, tag: params[:tag], format: :ics, tag: params[:tag], region: params[:region]) - ou - = link_to 'calendrier Google', "http://www.google.com/calendar/render?cid=#{events_url(format: :ics, tag: params[:tag], region: params[:region])}" + =raw t '.calendar_in', + rss: link_to('rss', events_url(:rss, + tag: params[:tag], region: params[:region])), + ical: link_to('iCal', events_url(:rss, + 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])}") diff --git a/app/views/events/show.html.haml b/app/views/events/show.html.haml index 3dab63cc..f2c6a599 100644 --- a/app/views/events/show.html.haml +++ b/app/views/events/show.html.haml @@ -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' #lug-list %h1=t '.lug-list' - - if @event.region + - if @event.related_region %ul - - @event.region.lugs.order(department: :asc).each do |lug| + - @event.related_region.lugs.order(department: :asc).each do |lug| %li = link_to lug.name, lug.url (#{lug.department}) %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 %em= @event.city + ':' @@ -29,7 +39,7 @@ %p =t '.at' %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' .description @@ -45,7 +55,7 @@ %span.label= Event.human_attribute_name :contact = 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 %span.label= Event.human_attribute_name :tags - @event.tags.split.each do |tag| diff --git a/app/views/moderation_mailer/accept.text.haml b/app/views/moderation_mailer/accept.text.haml new file mode 100644 index 00000000..15a89531 --- /dev/null +++ b/app/views/moderation_mailer/accept.text.haml @@ -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' diff --git a/app/views/moderation_mailer/create.text.haml b/app/views/moderation_mailer/create.text.haml index 3f5773bf..bfff4625 100644 --- a/app/views/moderation_mailer/create.text.haml +++ b/app/views/moderation_mailer/create.text.haml @@ -1,17 +1,17 @@ =t '.title' \ =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(: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} +#{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' diff --git a/app/views/moderation_mailer/destroy.text.haml b/app/views/moderation_mailer/destroy.text.haml new file mode 100644 index 00000000..d9fbf68e --- /dev/null +++ b/app/views/moderation_mailer/destroy.text.haml @@ -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' diff --git a/app/views/moderation_mailer/moderate.text.haml b/app/views/moderation_mailer/moderate.text.haml deleted file mode 100644 index 26123b02..00000000 --- a/app/views/moderation_mailer/moderate.text.haml +++ /dev/null @@ -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' diff --git a/app/views/moderations/edit.html.haml b/app/views/moderations/edit.html.haml index eb779dee..972ee331 100644 --- a/app/views/moderations/edit.html.haml +++ b/app/views/moderations/edit.html.haml @@ -3,6 +3,10 @@ >>> =t '.preview' +- if @moderation.is_moderated? + .box + %h3=t '.warning' + .box= render file: '/events/show' %h3 diff --git a/app/views/moderations/index.html.haml b/app/views/moderations/index.html.haml index 7778f0ee..3bf2a951 100644 --- a/app/views/moderations/index.html.haml +++ b/app/views/moderations/index.html.haml @@ -9,7 +9,7 @@ %th= Event.human_attribute_name :title %th=t '.date' %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=t '.actions' @@ -27,18 +27,18 @@ au =l event.end_time, format: :at %td= event.city - %td= event.region.name + %td= event.related_region.name %td= time_ago_in_words event.submission_time.to_date %th.actions = link_to edit_moderation_path event do %em.fa.fa-pencil =t 'edit' \- - = link_to edit_moderation_path event do + = link_to validate_moderation_path event do %em.fa.fa-thumbs-up =t 'validate' \- - = link_to edit_moderation_path event do + = link_to refuse_moderation_path event do %em.fa.fa-thumbs-down =t 'refuse' %br/ diff --git a/app/views/moderations/refuse.html.haml b/app/views/moderations/refuse.html.haml new file mode 100644 index 00000000..f3f9dcac --- /dev/null +++ b/app/views/moderations/refuse.html.haml @@ -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' diff --git a/app/views/moderations/validate.html.haml b/app/views/moderations/validate.html.haml new file mode 100644 index 00000000..d04110ec --- /dev/null +++ b/app/views/moderations/validate.html.haml @@ -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' diff --git a/app/views/notes/_form.html.haml b/app/views/notes/_form.html.haml index d65db50c..ac1eb5d8 100644 --- a/app/views/notes/_form.html.haml +++ b/app/views/notes/_form.html.haml @@ -27,7 +27,9 @@ .actions = f.submit t('.save') + = link_to t('.ko'), moderations_url, class: :button - else .actions - = f.submit t('save') + = f.submit t('.ok') + = link_to t('.ko'), moderations_url, class: :button diff --git a/config/locales/fr.yml b/config/locales/fr.yml index d05648c7..21069048 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -18,6 +18,7 @@ fr: created: Créé il y a %{date} updated: Mis à jour il y a %{date} + # Base de données activerecord: models: admin_user: Admin @@ -39,7 +40,7 @@ fr: inseecode: Code INSEE regioncode: Code région lug: - region: Région + related_region: Région department: Département url: Adresse web city: Cité @@ -49,7 +50,7 @@ fr: end_time: Fin description: Description city: Ville - region: Région + related_region: Région locality: Portée url: URL contact: Contact @@ -91,6 +92,7 @@ fr: at: "%A %d %B %Y à %Hh%M" hours: "%Hh%M" + # Traductions des écrans layouts: application: login: Authentication @@ -112,7 +114,7 @@ fr: moderation: Modération events: index: - calendar_in: Ce calendrier en + calendar_in: Ce calendrier en %{rss}, %{ical} ou %{googleCal} all_regions: Toutes les régions show: lug-list: Groupes d'utilisateurs de la région @@ -122,6 +124,8 @@ fr: description: Description infos: Informations actions: Actions + edit: Éditer événement + cancel: Annuler événement new: title: Soumettre un évènement create: @@ -129,7 +133,6 @@ fr: edit: title: Éditer un é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 edit: Édition de l'évènement form: @@ -142,6 +145,8 @@ fr: preview: Visualisation de l'évènement ok: Oui ko: Non + destroy: + ok: Votre événément a bien été annulé regions: index: title: Liste des flux RSS @@ -183,16 +188,44 @@ fr: edit: moderation: Modération 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 + 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: new: back: Modération title: Ajout d'une note de modération create: + sendByMailWrap: "

Demande d'informations complémentaires:

%{contents}
" ok: La note a bien été ajoutée, merci! form: title: Rédaction du message save: Envoyer + ok: Enregistrer + ko: Annuler maps: index: title: Carte des évènements @@ -226,13 +259,19 @@ fr: update: subject: "[Agenda du Libre] Édition de l'évènement '%{subject}'" 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" - moderate: + accept: subject: "[Agenda du Libre] Évènement '%{subject}' modéré" title: Bonjour, body: L'évènement a été modéré par %{author} 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: create: subject: "[Agenda du Libre] Demande d'informations sur l'évènement '%{subject}'" diff --git a/config/routes.rb b/config/routes.rb index bd509d2f..3a8afbea 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,6 +13,8 @@ Rails.application.routes.draw do end resources :moderations do resources :notes, only: [:new, :create] + get :validate, :refuse, on: :member + put :accept, on: :member end resources :regions, only: [ :index ] do get 'icallist', on: :collection diff --git a/test/controllers/events_controller_test.rb b/test/controllers/events_controller_test.rb index bf859644..d727034b 100644 --- a/test/controllers/events_controller_test.rb +++ b/test/controllers/events_controller_test.rb @@ -1,103 +1,109 @@ require 'test_helper' class EventsControllerTest < ActionController::TestCase + include Devise::TestHelpers + setup do - @event = events(:one) + @event = events :one end - test "should get index" do + test 'should get index' do get :index assert_response :success assert_not_nil assigns(:events) end - test "should get new" do + test 'should get new' do get :new assert_response :success end - test "should preview event" do - assert_no_difference('Event.count') do + test 'should preview event' do + assert_no_difference 'Event.count' do post :create, visu: 'visualise', event: { title: @event.title, start_time: @event.start_time, end_time: @event.end_time, description: @event.description, city: @event.city, - region: regions(:region_one), + region: @event.related_region, locality: @event.locality, url: @event.url, contact: @event.contact, submitter: @event.submitter, tags: @event.tags } + + assert_empty assigns(:event).errors end assert_response :success end - test "should create event" do - assert_difference('Event.count') do + test 'should create event' do + assert_difference 'Event.count' do post :create, event: { title: @event.title, start_time: @event.start_time, end_time: @event.end_time, description: @event.description, city: @event.city, - region: regions(:region_one), + region: @event.related_region, locality: @event.locality, url: @event.url, contact: @event.contact, submitter: @event.submitter, tags: @event.tags } + + assert_empty assigns(:event).errors.messages end assert_redirected_to root_url end - test "should show event" do + test 'should show event' do get :show, id: @event assert_response :success end - test "should get edit" do + test 'should get edit' do get :edit, id: @event, secret: 'MyString' assert_response :success end - test "should not get edit" do + test 'should not get edit' do get :edit, id: @event assert_redirected_to root_url end - test "should update event" do + test 'should update event' do patch :update, id: @event, secret: 'MyString', event: { title: @event.title, start_time: @event.start_time, end_time: @event.end_time, description: @event.description, city: @event.city, - region: regions(:region_one), + region: @event.related_region, locality: @event.locality, url: @event.url, contact: @event.contact, moderated: @event.moderated, - moderator_mail_id: @event.moderator_mail_id, secret: @event.secret, submission_time: @event.submission_time, submitter: @event.submitter, - submitter_mail_id: @event.submitter_mail_id, tags: @event.tags } + + assert_empty assigns(:event).errors.messages assert_redirected_to event_path(assigns(:event)) end - test "should get cancel page" do + test 'should get cancel page' do get :cancel, id: @event, secret: 'MyString' assert_response :success end - test "should destroy event" do + test 'should destroy event' do assert_difference('Event.count', -1) do delete :destroy, id: @event, secret: 'MyString' end diff --git a/test/controllers/moderations_controller_test.rb b/test/controllers/moderations_controller_test.rb index f4940a3e..47cccb9f 100644 --- a/test/controllers/moderations_controller_test.rb +++ b/test/controllers/moderations_controller_test.rb @@ -1,7 +1,37 @@ require 'test_helper' class ModerationsControllerTest < ActionController::TestCase - # test "the truth" do - # assert true - # end + include Devise::TestHelpers + + 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 diff --git a/test/fixtures/cities.yml b/test/fixtures/cities.yml index 8782b241..150fb76d 100644 --- a/test/fixtures/cities.yml +++ b/test/fixtures/cities.yml @@ -1,6 +1,6 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: +city_one: name: Jolie ville majname: JOLIE VILLE postalcode: 1 @@ -9,7 +9,7 @@ one: latitude: 1.5 longitude: 1.5 -two: +city_two: name: Une autre ville majname: UNE AUTRE VILLE postalcode: 1 diff --git a/test/fixtures/events.yml b/test/fixtures/events.yml index cbf05010..ff01e2ea 100644 --- a/test/fixtures/events.yml +++ b/test/fixtures/events.yml @@ -5,8 +5,8 @@ one: description: MyText start_time: 2013-12-28 16:04:56 end_time: 2013-12-28 16:04:56 - city: Jolie ville - region: region_one + city: city_one.name + related_region: region_one locality: 1 url: http://exemple.com contact: test@example.com @@ -24,8 +24,8 @@ two: description: MyText start_time: 2013-12-28 16:04:56 end_time: 2013-12-28 16:04:56 - city: Une autre ville - region: region_one + city: city_two.name + related_region: region_two locality: 1 url: http://exemple.com contact: test2@example.com diff --git a/test/fixtures/lugs.yml b/test/fixtures/lugs.yml index 416a2172..95d0761f 100644 --- a/test/fixtures/lugs.yml +++ b/test/fixtures/lugs.yml @@ -1,15 +1,15 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html one: - region: region_one + related_region: region_one + city: Jolie ville department: 1 name: MyString url: MyString - city: MyString two: - region: region_one + related_region: region_two + city: Jolie ville department: 1 name: MyString url: MyString - city: MyString diff --git a/test/mailers/moderation_mailer_test.rb b/test/mailers/moderation_mailer_test.rb index 2424c072..38fb9c04 100644 --- a/test/mailers/moderation_mailer_test.rb +++ b/test/mailers/moderation_mailer_test.rb @@ -5,24 +5,31 @@ class ModerationMailerTest < ActionMailer::TestCase ActionMailer::Base.default_url_options[:host] = 'localhost:3000' end - test "create" do - mail = ModerationMailer.create(Event.unscoped.last) + test 'create' do + mail = ModerationMailer.create Event.unscoped.last 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.from + assert_equal ['moderateurs@agendadulibre.org'], mail.to + assert_equal ['moderateurs@agendadulibre.org'], mail.from end - test "update" do - mail = ModerationMailer.update(Event.unscoped.last, User.last) + test 'update' do + mail = ModerationMailer.update Event.unscoped.last, User.last 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.from + assert_equal ['moderateurs@agendadulibre.org'], mail.to + assert_equal ['moderateurs@agendadulibre.org'], mail.from end - test "moderate" do - mail = ModerationMailer.moderate(Event.unscoped.last, User.last) + test 'accept' do + mail = ModerationMailer.accept Event.unscoped.last, User.last assert_match(/\[Agenda du Libre\] Évènement .* modéré/, mail.subject) - assert_equal ["moderateurs@agendadulibre.org"], mail.to - assert_equal ["moderateurs@agendadulibre.org"], mail.from + assert_equal ['moderateurs@agendadulibre.org'], mail.to + 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 diff --git a/test/mailers/note_mailer_test.rb b/test/mailers/note_mailer_test.rb index 8100284d..4dddd89e 100644 --- a/test/mailers/note_mailer_test.rb +++ b/test/mailers/note_mailer_test.rb @@ -5,8 +5,8 @@ class NoteMailerTest < ActionMailer::TestCase ActionMailer::Base.default_url_options[:host] = 'localhost:3000' end - test "create" do - mail = NoteMailer.create(Note.last) + test 'create' do + mail = NoteMailer.create Note.last assert_match(/\[Agenda du Libre\] Demande d'informations sur l'évènement .*/, mail.subject) assert_equal [Note.last.event.contact], mail.to assert_equal ["moderateurs@agendadulibre.org"], mail.from diff --git a/test/mailers/previews/event_mailer_preview.rb b/test/mailers/previews/event_mailer_preview.rb index e0f2de84..86f10966 100644 --- a/test/mailers/previews/event_mailer_preview.rb +++ b/test/mailers/previews/event_mailer_preview.rb @@ -4,7 +4,6 @@ class EventMailerPreview < ActionMailer::Preview # Preview this email at http://localhost:3000/rails/mailers/event_mailer/create def create ActionMailer::Base.default_url_options[:host] = 'localhost:3000' - EventMailer.create(Event.last) + EventMailer.create Event.last end - end diff --git a/test/mailers/previews/moderation_mailer_preview.rb b/test/mailers/previews/moderation_mailer_preview.rb index 74ea5d72..41f8a0fd 100644 --- a/test/mailers/previews/moderation_mailer_preview.rb +++ b/test/mailers/previews/moderation_mailer_preview.rb @@ -5,7 +5,7 @@ class ModerationMailerPreview < ActionMailer::Preview # Preview this email at http://localhost:3000/rails/mailers/moderation_mailer/create def create ActionMailer::Base.default_url_options[:host] = 'localhost:3000' - ModerationMailer.create(Event.last) + ModerationMailer.create Event.last end # Preview this email at http://localhost:3000/rails/mailers/moderation_mailer/update @@ -14,12 +14,19 @@ class ModerationMailerPreview < ActionMailer::Preview event = Event.last event.description = event.description + ' hello world' - ModerationMailer.update(event, User.last) + ModerationMailer.update event, User.last end - # Preview this email at http://localhost:3000/rails/mailers/moderation_mailer/moderate - def moderate + # Preview this email at http://localhost:3000/rails/mailers/moderation_mailer/accept + def accept 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 diff --git a/test/mailers/previews/note_mailer_preview.rb b/test/mailers/previews/note_mailer_preview.rb index 70a91990..63543b9e 100644 --- a/test/mailers/previews/note_mailer_preview.rb +++ b/test/mailers/previews/note_mailer_preview.rb @@ -3,6 +3,6 @@ class NoteMailerPreview < ActionMailer::Preview # Preview this email at http://localhost:3000/rails/mailers/note_mailer/create def create ActionMailer::Base.default_url_options[:host] = 'localhost:3000' - NoteMailer.create(Note.last) + NoteMailer.create Note.last end end diff --git a/test/models/event_test.rb b/test/models/event_test.rb index 65ef84cf..b6f4a311 100644 --- a/test/models/event_test.rb +++ b/test/models/event_test.rb @@ -7,8 +7,8 @@ class EventTest < ActiveSupport::TestCase start_time: Time.new(), end_time: Time.new() + 1, description: 'et hop!', - city: City.first().name, - region: Region.first(), + city: City.first(), + related_region: Region.first(), url: 'http://example.com', contact: 'contact@example.com', submitter: 'submitter@example.com' @@ -26,8 +26,8 @@ class EventTest < ActiveSupport::TestCase start_time: Time.new(), end_time: Time.new() + 1, description: 'et hop!', - city: City.first().name, - region: Region.first(), + city: City.first(), + related_region: Region.first(), url: 'http://example.com', contact: 'contact@example.com' )