From d6ba4d05694678aa4b73e4e5b95478520b384b32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Sibaud?= Date: Sun, 10 Mar 2024 13:04:50 +0100 Subject: [PATCH 1/9] Add extra validations for links, trackers; and news - bookmarks: unique title, unique URL, force lang definition - news (direct to moderation): force section definition, force lang definition on links, different messages for max length of news title and link title - news (in redaction): force lang definition on links, different messages for max length of news title and link title - trackers: for category definition --- app/models/bookmark.rb | 6 ++++-- app/models/link.rb | 8 +++++++- app/views/bookmarks/_form.html.haml | 2 +- app/views/news/_form.html.haml | 2 +- app/views/trackers/_form.html.haml | 2 +- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/models/bookmark.rb b/app/models/bookmark.rb index 75e47a37f..1ffd60154 100644 --- a/app/models/bookmark.rb +++ b/app/models/bookmark.rb @@ -24,10 +24,12 @@ 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é" } def link=(raw) raw.strip! diff --git a/app/models/link.rb b/app/models/link.rb index 52fde9b42..b2df75d5e 100644 --- a/app/models/link.rb +++ b/app/models/link.rb @@ -25,10 +25,11 @@ 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" } + validate :lang_validation def url=(raw) raw.strip! @@ -44,6 +45,11 @@ def url=(raw) write_attribute :url, raw end + def lang_validation + if lang == "xx" + errors.add(:lang, "La langue du lien doit être définie") unless title.blank? or url.blank? + end + end ### Behaviour ### def self.hit(id) diff --git a/app/views/bookmarks/_form.html.haml b/app/views/bookmarks/_form.html.haml index 5c94b3a65..7d1f04daa 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 diff --git a/app/views/news/_form.html.haml b/app/views/news/_form.html.haml index 845e91081..4fbe36f0a 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' diff --git a/app/views/trackers/_form.html.haml b/app/views/trackers/_form.html.haml index aac89aba8..229ba8f26 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" From 84db41401e502ea5eaad86f432de823b374612fa Mon Sep 17 00:00:00 2001 From: Adrien Dorsaz Date: Thu, 11 Apr 2024 21:03:00 +0200 Subject: [PATCH 2/9] validates lang selection for bookmarks and links As title and link are both mandatory, we set the lang mandatory too. The "xx" language code is removed from the valid list and blank is refused. The "xx" value was used as default value before we enable "blank" in form. It is not really useful now except for links and bookmarks which are already using this value. --- app/models/bookmark.rb | 1 + app/models/lang.rb | 4 ++++ app/models/link.rb | 3 ++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/bookmark.rb b/app/models/bookmark.rb index 1ffd60154..8ec53f940 100644 --- a/app/models/bookmark.rb +++ b/app/models/bookmark.rb @@ -30,6 +30,7 @@ class Bookmark < Content http_url: { message: "Le lien n'est pas valide" }, 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! 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 b2df75d5e..3c4a6684f 100644 --- a/app/models/link.rb +++ b/app/models/link.rb @@ -29,7 +29,8 @@ class Link < ActiveRecord::Base 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" } - validate :lang_validation + validates :lang, inclusion: { in: Lang.valid_codes, allow_nil: false, message: "La langue du lien doit être définie" } + def url=(raw) raw.strip! From ec79de018c6414007cb51313d760d950dce6d4a3 Mon Sep 17 00:00:00 2001 From: Adrien Dorsaz Date: Thu, 11 Apr 2024 21:06:44 +0200 Subject: [PATCH 3/9] bookmarks: do not render preview and save button if bookmark is invalid This way, the errors is easier to see at they appear first on screen. --- app/views/bookmarks/_form.html.haml | 2 +- app/views/bookmarks/new.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/bookmarks/_form.html.haml b/app/views/bookmarks/_form.html.haml index 7d1f04daa..035bcd0b4 100644 --- a/app/views/bookmarks/_form.html.haml +++ b/app/views/bookmarks/_form.html.haml @@ -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/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 From 7a706af7505bf3b126edf273a065b05f8dccc67b Mon Sep 17 00:00:00 2001 From: Adrien Dorsaz Date: Thu, 11 Apr 2024 21:07:47 +0200 Subject: [PATCH 4/9] news: validate association to section and show preview only if valid This shows a user friendly message instead of an exception if user remove the client side validation of section. The exception were thrown by the preview, so we avoid to show preview and submit button for invalid news. --- app/models/news.rb | 2 ++ app/views/news/_form.html.haml | 2 +- app/views/news/new.html.haml | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) 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/views/news/_form.html.haml b/app/views/news/_form.html.haml index 4fbe36f0a..a073f603e 100644 --- a/app/views/news/_form.html.haml +++ b/app/views/news/_form.html.haml @@ -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 From 2552255f3d0f4f3917b8f25ea378a1f530ca1afd Mon Sep 17 00:00:00 2001 From: Adrien Dorsaz Date: Thu, 11 Apr 2024 21:41:29 +0200 Subject: [PATCH 5/9] only show preview and save button if content is valid --- app/views/bookmarks/edit.html.haml | 2 +- app/views/comments/_form.html.haml | 2 +- app/views/comments/edit.html.haml | 2 +- app/views/comments/new.html.haml | 2 +- app/views/diaries/_form.html.haml | 2 +- app/views/diaries/edit.html.haml | 2 +- app/views/diaries/new.html.haml | 2 +- app/views/polls/_form.html.haml | 2 +- app/views/polls/new.html.haml | 2 +- app/views/posts/_form.html.haml | 2 +- app/views/posts/edit.html.haml | 2 +- app/views/posts/new.html.haml | 2 +- app/views/trackers/_form.html.haml | 2 +- app/views/trackers/edit.html.haml | 2 +- app/views/trackers/new.html.haml | 2 +- app/views/wiki_pages/_form.html.haml | 2 +- app/views/wiki_pages/edit.html.haml | 2 +- app/views/wiki_pages/new.html.haml | 2 +- 18 files changed, 18 insertions(+), 18 deletions(-) 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/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/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 229ba8f26..4015bc3d8 100644 --- a/app/views/trackers/_form.html.haml +++ b/app/views/trackers/_form.html.haml @@ -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 From 676b0ef41b9cb22ab97b12ce1914983163a32968 Mon Sep 17 00:00:00 2001 From: Adrien Dorsaz Date: Thu, 11 Apr 2024 21:44:08 +0200 Subject: [PATCH 6/9] add validates_associated for fields user have to choose --- app/models/post.rb | 2 ++ app/models/tracker.rb | 2 ++ 2 files changed, 4 insertions(+) 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..5c0c9028b 100644 --- a/app/models/tracker.rb +++ b/app/models/tracker.rb @@ -28,6 +28,8 @@ 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" }, From e7dffa74d6be67969494a12424a9b72e220468c6 Mon Sep 17 00:00:00 2001 From: Adrien Dorsaz Date: Thu, 11 Apr 2024 22:32:45 +0200 Subject: [PATCH 7/9] fix typo while copying test from model/link The bookmark attribute for URL is "link" and not "url". --- app/models/bookmark.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/bookmark.rb b/app/models/bookmark.rb index 8ec53f940..d626e5c67 100644 --- a/app/models/bookmark.rb +++ b/app/models/bookmark.rb @@ -34,7 +34,7 @@ class Bookmark < Content 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? From 8a918043b53b59c1ae54492d688ac4095a7d5efa Mon Sep 17 00:00:00 2001 From: Adrien Dorsaz Date: Thu, 11 Apr 2024 23:14:40 +0200 Subject: [PATCH 8/9] remove unused lang_validation for links The inclusion validator already does the job correctly. --- app/models/link.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/models/link.rb b/app/models/link.rb index 3c4a6684f..a8e091227 100644 --- a/app/models/link.rb +++ b/app/models/link.rb @@ -46,11 +46,6 @@ def url=(raw) write_attribute :url, raw end - def lang_validation - if lang == "xx" - errors.add(:lang, "La langue du lien doit être définie") unless title.blank? or url.blank? - end - end ### Behaviour ### def self.hit(id) From 46aeadab31a15d97d9526afabf56d58b9b7b7ccc Mon Sep 17 00:00:00 2001 From: Adrien Dorsaz Date: Thu, 11 Apr 2024 23:30:43 +0200 Subject: [PATCH 9/9] tracker: category must be present (update model to follow form) --- app/models/tracker.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/tracker.rb b/app/models/tracker.rb index 5c0c9028b..f51216404 100644 --- a/app/models/tracker.rb +++ b/app/models/tracker.rb @@ -34,6 +34,7 @@ class Tracker < Content 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") }