diff --git a/app/controllers/bookmarks_controller.rb b/app/controllers/bookmarks_controller.rb
index 91aa89629..a1f0659ee 100644
--- a/app/controllers/bookmarks_controller.rb
+++ b/app/controllers/bookmarks_controller.rb
@@ -35,7 +35,9 @@ def create
redirect_to [@bookmark.owner, @bookmark], notice: "Votre lien a bien été partagé"
else
@bookmark.node = Node.new(user_id: current_user.id, cc_licensed: false)
- @bookmark.node.preview_tags = params[:tags]
+ if params.include?(:tags)
+ @bookmark.node.preview_tags = params[:tags]
+ end
@bookmark.valid?
flash.now[:alert] = "Votre lien semble invalide. Le confimez‑vous ?" unless @bookmark.link =~ /\A#{URI::regexp(['http', 'https'])}\z/
render :new
diff --git a/app/controllers/diaries_controller.rb b/app/controllers/diaries_controller.rb
index 110485af9..ff8282bba 100644
--- a/app/controllers/diaries_controller.rb
+++ b/app/controllers/diaries_controller.rb
@@ -33,7 +33,9 @@ def create
redirect_to [@diary.owner, @diary], notice: "Votre journal a bien été créé"
else
@diary.node = Node.new(user_id: current_user.id, cc_licensed: @diary.cc_licensed)
- @diary.node.preview_tags = params[:tags]
+ if params.include?(:tags)
+ @diary.node.preview_tags = params[:tags]
+ end
@diary.valid?
flash.now[:alert] = "Votre journal ne contient pas de liens. Confirmez‑vous que cela est normal ?" unless @diary.body =~ / { order(updated_at: :desc) }
scope :draft, -> { where(state: "draft").includes(node: :user) }
scope :candidate, -> { where(state: "candidate") }
@@ -57,7 +59,7 @@ class News < Content
scope :with_node_ordered_by, ->(order) { joins(:node).where("nodes.public = 1").order("nodes.#{order} DESC") }
validates :title, presence: { message: "Le titre est obligatoire" },
- length: { maximum: 100, message: "Le titre est trop long" }
+ length: { maximum: 160, message: "Le titre est trop long" }
validates :body, presence: { message: "Nous n’acceptons pas les dépêches vides" }
validates :section, presence: { message: "Veuillez choisir une section pour cette dépêche" }
validates :author_name, presence: { message: "Veuillez entrer votre nom" },
@@ -65,6 +67,11 @@ class News < Content
validates :author_email, presence: { message: "Veuillez entrer votre adresse de courriel" },
length: { maximum: 64, message: "L’adresse de courriel de l’auteur est trop longue" }
+ def title=(raw)
+ raw.strip!
+ write_attribute :title, raw
+ end
+
### SEO ###
extend FriendlyId
diff --git a/app/models/node.rb b/app/models/node.rb
index 5b4460f06..f71a7e54c 100644
--- a/app/models/node.rb
+++ b/app/models/node.rb
@@ -160,7 +160,11 @@ def board_status(account)
attr_reader :preview_tags
def preview_tags=(list)
- @preview_tags = TagList.new(list)
+ if list.nil?
+ @preview_tags = TagList.new
+ else
+ @preview_tags = TagList.new(list)
+ end
end
def set_taglist(list, user_id)
diff --git a/app/models/poll.rb b/app/models/poll.rb
index eced3d034..7ec275e03 100644
--- a/app/models/poll.rb
+++ b/app/models/poll.rb
@@ -44,6 +44,11 @@ def mark_answers_for_destruction
end
end
+ def title=(raw)
+ raw.strip!
+ write_attribute :title, raw
+ end
+
### Associated node ###
def create_node(attrs={})
diff --git a/app/models/post.rb b/app/models/post.rb
index 9b89706c9..d8168283f 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -23,16 +23,23 @@ class Post < Content
belongs_to :forum
+ validates_associated :forum, message: "Vous devez choisir un forum"
+
scope :with_node_ordered_by, ->(order) { joins(:node).where("nodes.public = 1").order("nodes.#{order} DESC") }
validates :forum, presence: { message: "Vous devez choisir un forum" }
validates :title, presence: { message: "Le titre est obligatoire" },
- length: { maximum: 100, message: "Le titre est trop long" }
+ length: { maximum: 160, message: "Le titre est trop long" }
validates :wiki_body, presence: { message: "Vous ne pouvez pas poster une entrée de forum vide" }
wikify_attr :body
truncate_attr :body
+ def title=(raw)
+ raw.strip!
+ write_attribute :title, raw
+ end
+
### SEO ###
extend FriendlyId
diff --git a/app/models/tracker.rb b/app/models/tracker.rb
index f172cafd4..bf1444512 100644
--- a/app/models/tracker.rb
+++ b/app/models/tracker.rb
@@ -28,10 +28,13 @@ class Tracker < Content
belongs_to :assigned_to_user, class_name: "User"
belongs_to :category
+ validates_associated :category, message: "Veuillez choisir une catégorie pour cette entrée de suivi"
+
attr_accessor :pot_de_miel
validates :title, presence: { message: "Le titre est obligatoire" },
length: { maximum: 100, message: "Le titre est trop long" }
+ validates :category, presence: { message: "Veuillez choisir une catégorie pour cette entrée de suivi" }
validates :wiki_body, presence: { message: "Veuillez décrire cette entrée du suivi" }
scope :opened, -> { where(state: "opened") }
@@ -39,6 +42,11 @@ class Tracker < Content
wikify_attr :body
truncate_attr :body
+ def title=(raw)
+ raw.strip!
+ write_attribute :title, raw
+ end
+
### SEO ###
extend FriendlyId
diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb
index 2d2a467c5..f8b896be3 100644
--- a/app/models/wiki_page.rb
+++ b/app/models/wiki_page.rb
@@ -31,6 +31,11 @@ class WikiPage < Content
exclusion: { in: reserved, message: "Ce titre est réservé pour une page spéciale" }
validates :body, presence: { message: "Le corps est obligatoire" }
+ def title=(raw)
+ raw.strip!
+ write_attribute :title, raw
+ end
+
### SEO ###
extend FriendlyId
diff --git a/app/models/wiki_version.rb b/app/models/wiki_version.rb
index ae800c99d..998e25cc7 100644
--- a/app/models/wiki_version.rb
+++ b/app/models/wiki_version.rb
@@ -22,6 +22,11 @@ class WikiVersion < ActiveRecord::Base
validates :message, length: { maximum: 255, message: "Le message est trop long" }
+ def message=(raw)
+ raw.strip!
+ write_attribute :message, raw
+ end
+
### Append-only ###
before_update :raise_on_update
diff --git a/app/views/bookmarks/_form.html.haml b/app/views/bookmarks/_form.html.haml
index 5c94b3a65..e4486b529 100644
--- a/app/views/bookmarks/_form.html.haml
+++ b/app/views/bookmarks/_form.html.haml
@@ -2,13 +2,13 @@
%p
= form.label :title, "Sujet du lien"
- = form.text_field :title, autocomplete: 'off', required: 'required', spellcheck: 'true', maxlength: 100
+ = form.text_field :title, autocomplete: 'off', required: 'required', spellcheck: 'true', maxlength: 160
%p
= form.label :link, "Lien à partager"
= form.text_field :link, autocomplete: 'off', required: 'required', spellcheck: 'false', maxlength: 1024
%p
= form.label :lang, "Langue"
- = form.select :lang, Lang.all
+ = form.select :lang, Lang.all, { include_blank: true }, { required: "required" }
%p
- if form.object.new_record?
%p
@@ -16,4 +16,4 @@
= text_field_tag :tags, nil, class: 'autocomplete', 'data-url' => autocomplete_tags_path, value: params[:tags], size: 100
%p
= form.submit "Prévisualiser", id: "bookmark_preview"
- = form.submit "Poster le lien", 'data-disable-with' => "Enregistrement en cours" if @preview_mode
+ = form.submit "Poster le lien", 'data-disable-with' => "Enregistrement en cours" if @preview_mode and @bookmark.valid?
diff --git a/app/views/bookmarks/edit.html.haml b/app/views/bookmarks/edit.html.haml
index d4f196aae..ec9978046 100644
--- a/app/views/bookmarks/edit.html.haml
+++ b/app/views/bookmarks/edit.html.haml
@@ -1,7 +1,7 @@
%main#contents(role="main")
=h1 "Éditer un lien"
- = render "preview", preview: @bookmark if @preview_mode
+ = render "preview", preview: @bookmark if @preview_mode and @bookmark.valid?
%h2 Édition
= form_for [@bookmark.owner, @bookmark] do |form|
diff --git a/app/views/bookmarks/new.html.haml b/app/views/bookmarks/new.html.haml
index 6cef285b9..bfd923406 100644
--- a/app/views/bookmarks/new.html.haml
+++ b/app/views/bookmarks/new.html.haml
@@ -9,7 +9,7 @@
%p
Les règles de modération sont applicables aux liens comme au reste du site.
- = render "preview", preview: @bookmark if @preview_mode
+ = render "preview", preview: @bookmark if @preview_mode and @bookmark.valid?
= form_for @bookmark do |form|
= render form
diff --git a/app/views/comments/_form.html.haml b/app/views/comments/_form.html.haml
index c27164075..d95b70a57 100644
--- a/app/views/comments/_form.html.haml
+++ b/app/views/comments/_form.html.haml
@@ -8,4 +8,4 @@
= form.text_area :wiki_body, required: 'required', spellcheck: 'true', class: 'markItUp', placeholder: "Vous pouvez écrire votre commentaire ici.\n\nMerci de rester poli et courtois, on compte sur vous !"
%p
= form.submit "Prévisualiser", id: "comment_preview"
- = form.submit "Poster le commentaire", 'data-disable-with' => "Enregistrement en cours" if @preview_mode
+ = form.submit "Poster le commentaire", 'data-disable-with' => "Enregistrement en cours" if @preview_mode and @comment.valid?
diff --git a/app/views/comments/edit.html.haml b/app/views/comments/edit.html.haml
index 2b068a3b2..02ec847c6 100644
--- a/app/views/comments/edit.html.haml
+++ b/app/views/comments/edit.html.haml
@@ -2,7 +2,7 @@
=h1 "Éditer un commentaire"
%div#comments
- = render "preview", preview: @comment if @preview_mode
+ = render "preview", preview: @comment if @preview_mode and @comment.valid?
= form_for [@comment.node, @comment] do |form|
= render form
diff --git a/app/views/comments/new.html.haml b/app/views/comments/new.html.haml
index cd2626bb6..8e99ffabc 100644
--- a/app/views/comments/new.html.haml
+++ b/app/views/comments/new.html.haml
@@ -18,7 +18,7 @@
- else
= render @comment.node.content
%div#comments
- = render "preview", preview: @comment if @preview_mode
+ = render "preview", preview: @comment if @preview_mode and @comment.valid?
= form_for [@node, @comment], url: "/nodes/#{@node.id}/comments#comment_new" do |form|
= form.hidden_field :parent_id
diff --git a/app/views/diaries/_form.html.haml b/app/views/diaries/_form.html.haml
index c4dcd6eed..6cfacfa7f 100644
--- a/app/views/diaries/_form.html.haml
+++ b/app/views/diaries/_form.html.haml
@@ -2,7 +2,7 @@
%p
= form.label :title, "Sujet du journal"
- = form.text_field :title, autocomplete: 'off', required: 'required', spellcheck: 'true', maxlength: 100
+ = form.text_field :title, autocomplete: 'off', required: 'required', spellcheck: 'true', maxlength: 160
%p
= form.label :wiki_body, "Journal complet"
= form.text_area :wiki_body, required: 'required', spellcheck: 'true', class: 'markItUp'
@@ -15,4 +15,4 @@
= form.label :cc_licensed, 'Je place ce document sous licence Creative Commons Attribution et Partage dans les mêmes conditions, version 4.0 (licence CC By‑SA 4.0)'.html_safe
%p
= form.submit "Prévisualiser", id: "diary_preview"
- = form.submit "Poster le journal", 'data-disable-with' => "Enregistrement en cours" if @preview_mode
+ = form.submit "Poster le journal", 'data-disable-with' => "Enregistrement en cours" if @preview_mode and @diary.valid?
diff --git a/app/views/diaries/edit.html.haml b/app/views/diaries/edit.html.haml
index be5d75ac3..a29f74f91 100644
--- a/app/views/diaries/edit.html.haml
+++ b/app/views/diaries/edit.html.haml
@@ -1,7 +1,7 @@
%main#contents(role="main")
=h1 "Éditer un journal"
- = render "preview", preview: @diary if @preview_mode
+ = render "preview", preview: @diary if @preview_mode and @diary.valid?
%h2 Édition
= form_for [@diary.owner, @diary] do |form|
diff --git a/app/views/diaries/new.html.haml b/app/views/diaries/new.html.haml
index f9a4e75aa..ef40e25c4 100644
--- a/app/views/diaries/new.html.haml
+++ b/app/views/diaries/new.html.haml
@@ -4,7 +4,7 @@
%p
Des règles de modération sont applicables aux journaux (et au reste du site).
- = render "preview", preview: @diary if @preview_mode
+ = render "preview", preview: @diary if @preview_mode and @diary.valid?
= form_for @diary do |form|
= render form
diff --git a/app/views/news/_form.html.haml b/app/views/news/_form.html.haml
index 845e91081..1e6bd4d5d 100644
--- a/app/views/news/_form.html.haml
+++ b/app/views/news/_form.html.haml
@@ -13,10 +13,10 @@
= form.text_field :pot_de_miel
%p
= form.label :title, "Titre de la dépêche"
- = form.text_field :title, autocomplete: 'off', required: 'required', spellcheck: 'true', maxlength: 100
+ = form.text_field :title, autocomplete: 'off', required: 'required', spellcheck: 'true', maxlength: 160
%p
= form.label :section_id, "Section de la dépêche"
- = form.collection_select :section_id, Section.published, :id, :title
+ = form.collection_select :section_id, Section.published, :id, :title, { include_blank: true }, { required: "required" }
%p
= form.label :wiki_body, "Contenu de la dépêche"
= form.text_area :wiki_body, required: 'required', spellcheck: 'true', class: 'markItUp'
@@ -51,4 +51,4 @@
= form.label :cc_licensed, 'Je place ce document sous licence Creative Commons Paternité - Partage des conditions initiales à l’identique, version 4.0 (licence CC By-SA 4.0). Ceci est conseillé afin de permettre l’édition coopérative de la dépêche si elle doit être complétée.'.html_safe
%p
= form.submit "Prévisualiser", id: "news_preview"
- = form.submit "Soumettre cette dépêche", 'data-disable-with' => "Enregistrement en cours" if @preview_mode
+ = form.submit "Soumettre cette dépêche", 'data-disable-with' => "Enregistrement en cours" if @preview_mode and @news.valid?
diff --git a/app/views/news/new.html.haml b/app/views/news/new.html.haml
index 85230fc21..409c56e3d 100644
--- a/app/views/news/new.html.haml
+++ b/app/views/news/new.html.haml
@@ -11,7 +11,7 @@
= list_of(news) do |news|
= link_to news.title, [:redaction, news]
- = render "preview", preview: @news if @preview_mode
+ = render "preview", preview: @news if @preview_mode and @news.valid?
= form_for setup_news(@news), url: '/news' do |form|
= render form
diff --git a/app/views/polls/_form.html.haml b/app/views/polls/_form.html.haml
index 19099b997..afd45f82c 100644
--- a/app/views/polls/_form.html.haml
+++ b/app/views/polls/_form.html.haml
@@ -14,4 +14,4 @@
= aform.text_field :answer, maxlength: 128, size: 30
%p
= form.submit "Prévisualiser", id: "poll_preview"
- = form.submit "Proposer ce sondage", 'data-disable-with' => "Enregistrement en cours" if @preview_mode
+ = form.submit "Proposer ce sondage", 'data-disable-with' => "Enregistrement en cours" if @preview_mode and @poll.valid?
diff --git a/app/views/polls/new.html.haml b/app/views/polls/new.html.haml
index e20def975..3763d2540 100644
--- a/app/views/polls/new.html.haml
+++ b/app/views/polls/new.html.haml
@@ -4,7 +4,7 @@
%p
Des règles de modération sont applicables aux sondages (et au reste du site).
- = render "preview", preview: @poll if @preview_mode
+ = render "preview", preview: @poll if @preview_mode and @poll.valid?
= form_for setup_poll(@poll) do |form|
= render form
diff --git a/app/views/posts/_form.html.haml b/app/views/posts/_form.html.haml
index 3439666d7..de29de708 100644
--- a/app/views/posts/_form.html.haml
+++ b/app/views/posts/_form.html.haml
@@ -5,7 +5,7 @@
= form.select :forum_id, forums_select_list, { include_blank: true }, { required: "required" }
%p
= form.label :title, "Sujet du message"
- = form.text_field :title, autocomplete: 'off', required: 'required', spellcheck: 'true', maxlength: 100
+ = form.text_field :title, autocomplete: 'off', required: 'required', spellcheck: 'true', maxlength: 160
%p
= form.label :wiki_body, "Message complet"
= form.text_area :wiki_body, required: 'required', spellcheck: 'true', class: 'markItUp'
@@ -15,4 +15,4 @@
= text_field_tag :tags, nil, class: 'autocomplete', 'data-url' => autocomplete_tags_path, value: params[:tags], size: 100
%p
= form.submit "Prévisualiser", id: "post_preview"
- = form.submit "Poster le message", 'data-disable-with' => "Enregistrement en cours" if @preview_mode
+ = form.submit "Poster le message", 'data-disable-with' => "Enregistrement en cours" if @preview_mode and @post.valid?
diff --git a/app/views/posts/edit.html.haml b/app/views/posts/edit.html.haml
index 5bda1c196..7f37214af 100644
--- a/app/views/posts/edit.html.haml
+++ b/app/views/posts/edit.html.haml
@@ -1,7 +1,7 @@
%main#contents(role="main")
=h1 "Éditer un message"
- = render "preview", preview: @post if @preview_mode
+ = render "preview", preview: @post if @preview_mode and @post.valid?
%h2 Édition
= form_for [@forum, @post] do |form|
diff --git a/app/views/posts/new.html.haml b/app/views/posts/new.html.haml
index d54158e9a..c97e44a1a 100644
--- a/app/views/posts/new.html.haml
+++ b/app/views/posts/new.html.haml
@@ -4,7 +4,7 @@
%p
Des règles de modération sont applicables aux forums (et au reste du site).
- = render "preview", preview: @post if @preview_mode
+ = render "preview", preview: @post if @preview_mode and @post.valid?
= form_for @post, url: "/posts" do |form|
= render form
diff --git a/app/views/trackers/_form.html.haml b/app/views/trackers/_form.html.haml
index aac89aba8..4015bc3d8 100644
--- a/app/views/trackers/_form.html.haml
+++ b/app/views/trackers/_form.html.haml
@@ -5,7 +5,7 @@
= form.text_field :title, autocomplete: 'off', required: 'required', spellcheck: 'true', maxlength: 100
%p
= form.label :category_id, "Catégorie"
- = form.collection_select :category_id, Category.all, :id, :title
+ = form.collection_select :category_id, Category.all, :id, :title, { include_blank: true }, { required: "required" }
- if @tracker.new_record?
%p.pot_de_miel
= form.label :pot_de_miel, "Ne pas remplir ce champ"
@@ -23,4 +23,4 @@
= form.collection_select :assigned_to_user_id, Account.tracker_admin, :user_id, :login, include_blank: true
%p
= form.submit "Prévisualiser", id: "tracker_preview"
- = form.submit "Soumettre", 'data-disable-with' => "Enregistrement en cours" if @preview_mode || @tracker.persisted?
+ = form.submit "Soumettre", 'data-disable-with' => "Enregistrement en cours" if (@preview_mode || @tracker.persisted?) and @tracker.valid?
diff --git a/app/views/trackers/edit.html.haml b/app/views/trackers/edit.html.haml
index db7f0eebd..c131a4717 100644
--- a/app/views/trackers/edit.html.haml
+++ b/app/views/trackers/edit.html.haml
@@ -1,7 +1,7 @@
%main#contents(role="main")
=h1 "Modifier une entrée dans le suivi"
- = render "preview", preview: @tracker if @preview_mode
+ = render "preview", preview: @tracker if @preview_mode and @tracker.valid?
%h2 Édition
= form_for @tracker do |form|
diff --git a/app/views/trackers/new.html.haml b/app/views/trackers/new.html.haml
index d2e4a9325..7981dea75 100644
--- a/app/views/trackers/new.html.haml
+++ b/app/views/trackers/new.html.haml
@@ -4,7 +4,7 @@
%p
Il s’agit du suivi des suggestions et bogues concernant le site LinuxFr.org.
- - if @preview_mode
+ - if @preview_mode and @tracker.valid?
= render "preview", preview: @tracker
- else
= image_tag "/images/dessins/geekscottes_068.png", alt: "Tu coderas pour moi !", title: "Tu coderas pour moi ! — © Johann « nojhan » Dréo, 7 novembre 2007 — Licence CC‑By‑SA 2.5"
diff --git a/app/views/wiki_pages/_form.html.haml b/app/views/wiki_pages/_form.html.haml
index ef2144de2..c7ae7db63 100644
--- a/app/views/wiki_pages/_form.html.haml
+++ b/app/views/wiki_pages/_form.html.haml
@@ -6,4 +6,4 @@
= form.text_field :message, autocomplete: 'off', spellcheck: 'true', maxlength: 250, size: 80
%p
= form.submit "Prévisualiser", id: "wiki_preview"
- = form.submit (form.object.new_record? ? "Créer" : "Mettre à jour") if @preview_mode
+ = form.submit (form.object.new_record? ? "Créer" : "Mettre à jour") if @preview_mode and @wiki_page.valid?
diff --git a/app/views/wiki_pages/edit.html.haml b/app/views/wiki_pages/edit.html.haml
index 58eaeda01..ea741db14 100644
--- a/app/views/wiki_pages/edit.html.haml
+++ b/app/views/wiki_pages/edit.html.haml
@@ -1,7 +1,7 @@
%main#contents(role="main")
=h1 "Modifier une page de wiki"
- = render "preview", preview: @wiki_page if @preview_mode
+ = render "preview", preview: @wiki_page if @preview_mode and @wiki_page.valid?
= form_for @wiki_page do |form|
= messages_on_error @wiki_page
diff --git a/app/views/wiki_pages/new.html.haml b/app/views/wiki_pages/new.html.haml
index 1348cf479..7451d3b2e 100644
--- a/app/views/wiki_pages/new.html.haml
+++ b/app/views/wiki_pages/new.html.haml
@@ -4,7 +4,7 @@
%p
Des règles de modération sont applicables aux pages du wiki (et au reste du site).
- = render "preview", preview: @wiki_page if @preview_mode
+ = render "preview", preview: @wiki_page if @preview_mode and @wiki_page.valid?
= form_for @wiki_page do |form|
= messages_on_error @wiki_page