-
Notifications
You must be signed in to change notification settings - Fork 54
Add extra validations for links, trackers; and news #385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
d6ba4d0
84db414
ec79de0
7a706af
2552255
676b0ef
e7dffa7
8a91804
46aeada
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On a aussi besoin d'ajouter la même validation pour la section dans ce controlleur. Si je procède à la même manipulation (enlever l'attribut required), alors, j'ai cette erreur qui apparaît: Ça serait plus sympa d'avoir un bon message d'erreur du controlleur pour éviter de perdre le contenu de la dépêche soumise sans espace de rédaction :)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Théoriquement, pour valider une association à une table (donc, pour la section de news ici), on peut utiliser les propriétés: validates_associated (validation de l'appartenance à la liste) et validates_presence_of (validation de la présence de la valeur) ensemble.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. J'ai ajouté "validates_associated" et j'ai changé le système de "prévisualisation" pour ne prévisualiser que si le contenu est valide. La capture d'écran d'erreur que j'ai posté plus haut était due au fait que l'on essaie de faire la preview d'une news sans section.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On peut envoyer en Anonyme en modération une dépêche avec un lien sans langue définie.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On peut injecter des langues inconnues sur un lien de dépêche en Anonyme (et ensuite le site essaie d'afficher une image inexistante).
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. En rédaction, on peut générer des 500 en envoyant des identifiants de section invalide pour la dépêche en cours. |
||
| %p | ||
| = form.label :wiki_body, "Contenu de la dépêche" | ||
| = form.text_area :wiki_body, required: 'required', spellcheck: 'true', class: 'markItUp' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Je n'ai pas eu le temps de testé, mais j'imagine qu'il y aura le même problème que pour la section de
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Encore un 500 si on soumet avec un id de catégorie inconnu. ActiveRecord::InvalidForeignKey (Mysql2::Error: Cannot add or update a child row: a foreign key constraint fails ( |
||
| - if @tracker.new_record? | ||
| %p.pot_de_miel | ||
| = form.label :pot_de_miel, "Ne pas remplir ce champ" | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.