diff --git a/app/models/bookmark.rb b/app/models/bookmark.rb index 75e47a37f..d626e5c67 100644 --- a/app/models/bookmark.rb +++ b/app/models/bookmark.rb @@ -24,14 +24,17 @@ class Bookmark < Content belongs_to :owner, class_name: 'User' validates :title, presence: { message: "Le titre est obligatoire" }, - length: { maximum: 100, message: "Le titre est trop long" } + length: { maximum: 100, message: "Le titre est trop long" }, + uniqueness: { message: "Un lien avec le même titre a déjà été proposé" } validates :link, presence: { message: "Vous ne pouvez pas poster un lien vide" }, http_url: { message: "Le lien n'est pas valide" }, - length: { maximum: 255, message: "Le lien est trop long" } + length: { maximum: 255, message: "Le lien est trop long" }, + uniqueness: { message: "Le lien a déjà été proposé" } + validates :lang, inclusion: { in: Lang.valid_codes, allow_nil: false, message: "La langue du lien doit être définie" } def link=(raw) raw.strip! - return write_attribute :url, nil if raw.blank? + return write_attribute :link, nil if raw.blank? uri = URI.parse(raw) # Default to HTTP link if neither scheme nor host is found if uri.scheme.blank? && uri.host.blank? diff --git a/app/models/lang.rb b/app/models/lang.rb index 28c682fa5..6d3e5a30b 100644 --- a/app/models/lang.rb +++ b/app/models/lang.rb @@ -8,6 +8,10 @@ def self.all vals.zip(keys) end + def self.valid_codes + $redis.lrange("lang", 0, -1).difference(["xx"]) + end + def self.[]=(key, value) $redis.set("lang/#{key}", value) $redis.rpush("lang", key) diff --git a/app/models/link.rb b/app/models/link.rb index 52fde9b42..a8e091227 100644 --- a/app/models/link.rb +++ b/app/models/link.rb @@ -25,10 +25,12 @@ class Link < ActiveRecord::Base Accessible = [:id, :user, :title, :url, :lang] validates :title, presence: { message: "Un lien doit obligatoirement avoir un titre" }, - length: { maximum: 100, message: "Le titre est trop long" } + length: { maximum: 100, message: "Le titre du lien est trop long" } validates :url, http_url: { protocols: PROTOCOLS, message: "L'adresse n'est pas valide" }, presence: { message: "Un lien doit obligatoirement avoir une adresse" }, length: { maximum: 255, message: "L’adresse est trop longue" } + validates :lang, inclusion: { in: Lang.valid_codes, allow_nil: false, message: "La langue du lien doit être définie" } + def url=(raw) raw.strip! diff --git a/app/models/news.rb b/app/models/news.rb index 67d5f4a45..cd6b91d59 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -50,6 +50,8 @@ class News < Content dependent: :destroy, inverse_of: :news + validates_associated :section, message: "Veuillez choisir une section pour cette dépêche" + scope :sorted, -> { order(updated_at: :desc) } scope :draft, -> { where(state: "draft").includes(node: :user) } scope :candidate, -> { where(state: "candidate") } diff --git a/app/models/post.rb b/app/models/post.rb index 9b89706c9..7740a3062 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -23,6 +23,8 @@ 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" } diff --git a/app/models/tracker.rb b/app/models/tracker.rb index f172cafd4..f51216404 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") } diff --git a/app/views/bookmarks/_form.html.haml b/app/views/bookmarks/_form.html.haml index 5c94b3a65..035bcd0b4 100644 --- a/app/views/bookmarks/_form.html.haml +++ b/app/views/bookmarks/_form.html.haml @@ -8,7 +8,7 @@ = 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..fd8ceae89 100644 --- a/app/views/diaries/_form.html.haml +++ b/app/views/diaries/_form.html.haml @@ -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..a073f603e 100644 --- a/app/views/news/_form.html.haml +++ b/app/views/news/_form.html.haml @@ -16,7 +16,7 @@ = form.text_field :title, autocomplete: 'off', required: 'required', spellcheck: 'true', maxlength: 100 %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..0ad198913 100644 --- a/app/views/posts/_form.html.haml +++ b/app/views/posts/_form.html.haml @@ -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