From: Jean-Philippe Lang Date: Mon, 2 Apr 2007 18:44:35 +0000 (+0000) Subject: Added some attributes length validations. X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=791077c240f74dd4e228fc5b8ac3d7a0c0d41f3a;p=redminele%2Fredmine.git Added some attributes length validations. Also added some information about attribute length constraints on forms. git-svn-id: http://redmine.rubyforge.org/svn/trunk@400 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/project.rb b/app/models/project.rb index 2419e720..60a37676 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -35,8 +35,10 @@ class Project < ActiveRecord::Base validates_uniqueness_of :name, :identifier validates_associated :custom_values, :on => :update validates_associated :repository, :wiki + validates_length_of :name, :maximum => 30 validates_format_of :name, :with => /^[\w\s\'\-]*$/i - validates_length_of :identifier, :maximum => 12 + validates_length_of :description, :maximum => 255 + validates_length_of :identifier, :in => 3..12 validates_format_of :identifier, :with => /^[a-z0-9\-]*$/ def identifier=(identifier) diff --git a/app/models/user.rb b/app/models/user.rb index 869be920..08220bea 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -33,9 +33,12 @@ class User < ActiveRecord::Base validates_presence_of :login, :firstname, :lastname, :mail validates_uniqueness_of :login, :mail # Login must contain lettres, numbers, underscores only - validates_format_of :firstname, :lastname, :with => /^[\w\s\'\-]*$/i validates_format_of :login, :with => /^[a-z0-9_\-@\.]+$/i + validates_length_of :login, :maximum => 30 + validates_format_of :firstname, :lastname, :with => /^[\w\s\'\-]*$/i + validates_length_of :firstname, :lastname, :maximum => 30 validates_format_of :mail, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i + validates_length_of :mail, :maximum => 60 # Password length between 4 and 12 validates_length_of :password, :in => 4..12, :allow_nil => true validates_confirmation_of :password, :allow_nil => true diff --git a/app/views/account/password_recovery.rhtml b/app/views/account/password_recovery.rhtml index 89b10529..c3c451e5 100644 --- a/app/views/account/password_recovery.rhtml +++ b/app/views/account/password_recovery.rhtml @@ -9,7 +9,8 @@ <% form_tag({:token => @token.value}, :class => "tabular") do %>

- <%= password_field_tag 'new_password', nil, :size => 25 %>

+ <%= password_field_tag 'new_password', nil, :size => 25 %>
+ <%= l(:text_length_between, 4, 12) %>

<%= password_field_tag 'new_password_confirmation', nil, :size => 25 %>

diff --git a/app/views/my/account.rhtml b/app/views/my/account.rhtml index 8a1468cd..24f0ef55 100644 --- a/app/views/my/account.rhtml +++ b/app/views/my/account.rhtml @@ -35,7 +35,8 @@ <%= password_field_tag 'password', nil, :size => 25 %>

- <%= password_field_tag 'new_password', nil, :size => 25 %>

+ <%= password_field_tag 'new_password', nil, :size => 25 %>
+ <%= l(:text_length_between, 4, 12) %>

<%= password_field_tag 'new_password_confirmation', nil, :size => 25 %>

diff --git a/app/views/projects/_form.rhtml b/app/views/projects/_form.rhtml index 184370b9..03a757d7 100644 --- a/app/views/projects/_form.rhtml +++ b/app/views/projects/_form.rhtml @@ -2,14 +2,14 @@
-

<%= f.text_field :name, :required => true %>

+

<%= f.text_field :name, :required => true %>
<%= l(:text_caracters_maximum, 30) %>

<% if admin_loggedin? and !@root_projects.empty? %>

<%= f.select :parent_id, (@root_projects.collect {|p| [p.name, p.id]}), { :include_blank => true } %>

<% end %> -

<%= f.text_area :description, :required => true, :cols => 60, :rows => 3 %>

-

<%= f.text_field :identifier, :required => true, :size => 15, :disabled => @project.identifier_frozen? %>
<%= l(:text_project_identifier_info) unless @project.identifier_frozen? %>

+

<%= f.text_area :description, :required => true, :cols => 60, :rows => 3 %>
<%= l(:text_caracters_maximum, 255) %>

+

<%= f.text_field :identifier, :required => true, :size => 15, :disabled => @project.identifier_frozen? %>
<%= l(:text_length_between, 3, 12) %> <%= l(:text_project_identifier_info) unless @project.identifier_frozen? %>

<%= f.text_field :homepage, :size => 40 %>

<%= f.check_box :is_public %>

diff --git a/app/views/users/_form.rhtml b/app/views/users/_form.rhtml index 18c84925..43540e67 100644 --- a/app/views/users/_form.rhtml +++ b/app/views/users/_form.rhtml @@ -23,7 +23,8 @@

<%= f.select :auth_source_id, [[l(:label_internal), ""]] + @auth_sources.collect { |a| [a.name, a.id] } %>

<% end %>

-<%= password_field_tag 'password', nil, :size => 25 %>

+<%= password_field_tag 'password', nil, :size => 25 %>
+<%= l(:text_length_between, 4, 12) %>

<%= password_field_tag 'password_confirmation', nil, :size => 25 %>

diff --git a/lang/de.yml b/lang/de.yml index 39b3ea1f..c08b4af4 100644 --- a/lang/de.yml +++ b/lang/de.yml @@ -397,7 +397,9 @@ text_journal_deleted: gelöscht text_tip_task_begin_day: Aufgabe, die an diesem Tag beginnt text_tip_task_end_day: Aufgabe, die an diesem Tag beendet text_tip_task_begin_end_day: Aufgabe, die an diesem Tag beginnt und beendet -text_project_identifier_info: '12 characters maximum. Letters (a-z), numbers (0-9) and dashes allowed.
Once saved, the identifier can not be changed.' +text_project_identifier_info: 'Lower case letters (a-z), numbers and dashes allowed.
Once saved, the identifier can not be changed.' +text_caracters_maximum: %d characters maximum. +text_length_between: Length between %d and %d characters. default_role_manager: Manager default_role_developper: Developer diff --git a/lang/en.yml b/lang/en.yml index 4f0cbe9f..4ce8bcb2 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -397,7 +397,9 @@ text_journal_deleted: deleted text_tip_task_begin_day: task beginning this day text_tip_task_end_day: task ending this day text_tip_task_begin_end_day: task beginning and ending this day -text_project_identifier_info: '12 characters maximum. Letters (a-z), numbers (0-9) and dashes allowed.
Once saved, the identifier can not be changed.' +text_project_identifier_info: 'Lower case letters (a-z), numbers and dashes allowed.
Once saved, the identifier can not be changed.' +text_caracters_maximum: %d characters maximum. +text_length_between: Length between %d and %d characters. default_role_manager: Manager default_role_developper: Developer diff --git a/lang/es.yml b/lang/es.yml index 7b05f370..a2014845 100644 --- a/lang/es.yml +++ b/lang/es.yml @@ -397,7 +397,9 @@ text_journal_deleted: suprimido text_tip_task_begin_day: tarea que comienza este día text_tip_task_end_day: tarea que termina este día text_tip_task_begin_end_day: tarea que comienza y termina este día -text_project_identifier_info: '12 characters maximum. Letters (a-z), numbers (0-9) and dashes allowed.
Once saved, the identifier can not be changed.' +text_project_identifier_info: 'Lower case letters (a-z), numbers and dashes allowed.
Once saved, the identifier can not be changed.' +text_caracters_maximum: %d characters maximum. +text_length_between: Length between %d and %d characters. default_role_manager: Manager default_role_developper: Desarrollador diff --git a/lang/fr.yml b/lang/fr.yml index 564b5fe7..8b52ac5d 100644 --- a/lang/fr.yml +++ b/lang/fr.yml @@ -397,7 +397,9 @@ text_journal_deleted: supprimé text_tip_task_begin_day: tâche commençant ce jour text_tip_task_end_day: tâche finissant ce jour text_tip_task_begin_end_day: tâche commençant et finissant ce jour -text_project_identifier_info: '12 caractères maximum. Lettres (a-z), chiffres (0-9) et tirets autorisés.
Un fois sauvegardé, l''identifiant ne pourra plus être modifié.' +text_project_identifier_info: 'Lettres minuscules (a-z), chiffres et tirets autorisés.
Un fois sauvegardé, l''identifiant ne pourra plus être modifié.' +text_caracters_maximum: %d caractères maximum. +text_length_between: Longueur comprise entre %d et %d caractères. default_role_manager: Manager default_role_developper: Développeur diff --git a/lang/it.yml b/lang/it.yml index fc2d405a..daaed6b7 100644 --- a/lang/it.yml +++ b/lang/it.yml @@ -397,7 +397,9 @@ text_journal_deleted: deleted text_tip_task_begin_day: task beginning this day text_tip_task_end_day: task ending this day text_tip_task_begin_end_day: task beginning and ending this day -text_project_identifier_info: '12 characters maximum. Letters (a-z), numbers (0-9) and dashes allowed.
Once saved, the identifier can not be changed.' +text_project_identifier_info: 'Lower case letters (a-z), numbers and dashes allowed.
Once saved, the identifier can not be changed.' +text_caracters_maximum: %d characters maximum. +text_length_between: Length between %d and %d characters. default_role_manager: Manager default_role_developper: Sviluppatore diff --git a/lang/ja.yml b/lang/ja.yml index db4335c3..bbeb6d45 100644 --- a/lang/ja.yml +++ b/lang/ja.yml @@ -398,7 +398,9 @@ text_journal_deleted: 削除 text_tip_task_begin_day: この日に開始するタスク text_tip_task_end_day: この日に終了するタスク text_tip_task_begin_end_day: この日のうちに開始して終了するタスク -text_project_identifier_info: '12 characters maximum. Letters (a-z), numbers (0-9) and dashes allowed.
Once saved, the identifier can not be changed.' +text_project_identifier_info: 'Lower case letters (a-z), numbers and dashes allowed.
Once saved, the identifier can not be changed.' +text_caracters_maximum: %d characters maximum. +text_length_between: Length between %d and %d characters. default_role_manager: 管理者 default_role_developper: 開発者 diff --git a/lang/zh.yml b/lang/zh.yml index a0508d34..5ffcb159 100644 --- a/lang/zh.yml +++ b/lang/zh.yml @@ -400,7 +400,9 @@ text_journal_deleted: 已删除 text_tip_task_begin_day: 开始于此 text_tip_task_end_day: 在此结束 text_tip_task_begin_end_day: 开始并结束于此 -text_project_identifier_info: '12 characters maximum. Letters (a-z), numbers (0-9) and dashes allowed.
Once saved, the identifier can not be changed.' +text_project_identifier_info: 'Lower case letters (a-z), numbers and dashes allowed.
Once saved, the identifier can not be changed.' +text_caracters_maximum: %d characters maximum. +text_length_between: Length between %d and %d characters. default_role_manager: 管理员 default_role_developper: 开发人员