Repository Identifier should be frozen (#11109).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10081 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-07-26 17:41:47 +00:00
parent 04f9a321b1
commit 87f284dcb6
50 changed files with 95 additions and 2 deletions

View File

@ -20,6 +20,9 @@ class ScmFetchError < Exception; end
class Repository < ActiveRecord::Base
include Redmine::Ciphering
include Redmine::SafeAttributes
# Maximum length for repository identifiers
IDENTIFIER_MAX_LENGTH = 255
belongs_to :project
has_many :changesets, :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC"
@ -34,7 +37,7 @@ class Repository < ActiveRecord::Base
before_destroy :clear_changesets
validates_length_of :password, :maximum => 255, :allow_nil => true
validates_length_of :identifier, :maximum => 255, :allow_blank => true
validates_length_of :identifier, :maximum => IDENTIFIER_MAX_LENGTH, :allow_blank => true
validates_presence_of :identifier, :unless => Proc.new { |r| r.is_default? || r.set_as_default? }
validates_uniqueness_of :identifier, :scope => :project_id, :allow_blank => true
validates_exclusion_of :identifier, :in => %w(show entry raw changes annotate diff show stats graph)
@ -114,6 +117,14 @@ class Repository < ActiveRecord::Base
end
end
def identifier=(identifier)
super unless identifier_frozen?
end
def identifier_frozen?
errors[:identifier].blank? && !(new_record? || identifier.blank?)
end
def identifier_param
if is_default?
nil

View File

@ -9,7 +9,10 @@
</p>
<p><%= f.check_box :is_default, :label => :field_repository_is_default %></p>
<p><%= f.text_field :identifier %></p>
<p><%= f.text_field :identifier, :disabled => @repository.identifier_frozen? %>
<% unless @repository.identifier_frozen? %>
<em class="info"><%= l(:text_length_between, :min => 1, :max => Repository::IDENTIFIER_MAX_LENGTH) %> <%= l(:text_repository_identifier_info).html_safe %></em>
<% end %></p>
<% button_disabled = true %>
<% if @repository %>

View File

@ -1056,3 +1056,4 @@ ar:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1054,3 +1054,4 @@ bg:
description_date_range_interval: Изберете диапазон чрез задаване на начална и крайна дати
description_date_from: Въведете начална дата
description_date_to: Въведете крайна дата
text_repository_identifier_info: 'Позволени са малки букви (a-z), цифри, тирета и _.<br />Промяна след създаването му не е възможна.'

View File

@ -1070,3 +1070,4 @@ bs:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1058,3 +1058,4 @@ ca:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1059,3 +1059,4 @@ cs:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1073,3 +1073,4 @@ da:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1074,3 +1074,4 @@ de:
label_fields_permissions: Fields permissions
label_readonly: Nur-Lese-Zugriff
label_required: Erforderlich
text_repository_identifier_info: 'Kleinbuchstaben (a-z), Ziffern, Binde- und Unterstriche erlaubt.<br />Einmal gespeichert, kann die Kennung nicht mehr geändert werden.'

View File

@ -1056,3 +1056,4 @@ el:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1058,3 +1058,4 @@ en-GB:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: 'Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.'

View File

@ -1053,3 +1053,4 @@ en:
description_date_range_interval: Choose range by selecting start and end date
description_date_from: Enter start date
description_date_to: Enter end date
text_repository_identifier_info: 'Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.'

View File

@ -1093,3 +1093,4 @@ es:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1069,3 +1069,4 @@ et:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: "Lubatud on ainult väikesed tähed (a-z), numbrid ja kriipsud.<br />Peale salvestamist ei saa tunnust enam muuta."

View File

@ -1059,3 +1059,4 @@ eu:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1058,3 +1058,4 @@ fa:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1077,3 +1077,4 @@ fi:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1070,3 +1070,4 @@ fr:
error_scm_annotate_big_text_file: Cette entrée ne peut pas être annotée car elle excède la taille maximale.
setting_repositories_encodings: Encodages des fichiers et des dépôts
label_search_for_watchers: Rechercher des observateurs
text_repository_identifier_info: 'Seuls les lettres minuscules (a-z), chiffres, tirets et underscore sont autorisés.<br />Un fois sauvegardé, l''identifiant ne pourra plus être modifié.'

View File

@ -1067,3 +1067,4 @@ gl:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1061,3 +1061,4 @@ he:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1059,3 +1059,4 @@ hr:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1075,3 +1075,4 @@
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1062,3 +1062,4 @@ id:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1057,3 +1057,4 @@ it:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1086,3 +1086,4 @@ ja:
label_fields_permissions: フィールドに対する権限
label_readonly: 読み取り専用
label_required: 必須
text_repository_identifier_info: アルファベット小文字(a-z)・数字・ハイフン・アンダースコアが使えます。<br />識別子は後で変更することはできません。

View File

@ -1106,3 +1106,4 @@ ko:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: "소문자(a-z),숫자,대쉬(-)와 밑줄(_)만 가능합니다.<br />식별자는 저장후에는 수정할 수 없습니다."

View File

@ -1116,3 +1116,4 @@ lt:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1050,3 +1050,4 @@ lv:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1056,3 +1056,4 @@ mk:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1058,3 +1058,4 @@ mn:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1038,3 +1038,4 @@ nl:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: 'Alleen kleine letter (a-z), cijfers, streepjes en liggende streepjes zijn toegestaan.<br />Eenmaal opgeslagen kan de identifier niet worden gewijzigd.'

View File

@ -1046,3 +1046,4 @@
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1073,3 +1073,4 @@ pl:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1078,3 +1078,4 @@ pt-BR:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1061,3 +1061,4 @@ pt:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1053,3 +1053,4 @@ ro:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1169,3 +1169,4 @@ ru:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Допускаются только строчные латинские буквы (a-z), цифры, тире и подчеркивания.<br />После сохранения идентификатор изменить нельзя.

View File

@ -1056,3 +1056,4 @@ sk:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1056,3 +1056,4 @@ sl:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1052,3 +1052,4 @@ sq:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: 'Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.'

View File

@ -1058,3 +1058,4 @@ sr-YU:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1057,3 +1057,4 @@ sr:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1094,3 +1094,4 @@ sv:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Ändast gemener (a-z), siffror, streck och understreck är tillåtna.<br />När identifieraren sparats kan den inte ändras.

View File

@ -1053,3 +1053,4 @@ th:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1075,3 +1075,4 @@ tr:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1051,3 +1051,4 @@ uk:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1107,3 +1107,4 @@ vi:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.

View File

@ -1137,3 +1137,4 @@
description_date_range_interval: 選擇起始與結束日期以設定範圍區間
description_date_from: 輸入起始日期
description_date_to: 輸入結束日期
text_repository_identifier_info: '僅允許使用小寫英文字母 (a-z), 阿拉伯數字, 虛線與底線。<br />一旦儲存之後, 代碼便無法再次被更改。'

View File

@ -1060,3 +1060,4 @@ zh:
label_fields_permissions: 字段权限
label_readonly: 只读
label_required: 必填
text_repository_identifier_info: 仅小写字母a-z、数字、破折号-和下划线_可以使用。<br />一旦保存,标识无法修改。

View File

@ -105,6 +105,38 @@ class RepositoryTest < ActiveSupport::TestCase
)
assert r.save
end
def test_identifier_should_not_be_frozen_for_a_new_repository
assert_equal false, Repository.new.identifier_frozen?
end
def test_identifier_should_not_be_frozen_for_a_saved_repository_with_blank_identifier
Repository.update_all(["identifier = ''"], "id = 10")
assert_equal false, Repository.find(10).identifier_frozen?
end
def test_identifier_should_be_frozen_for_a_saved_repository_with_valid_identifier
Repository.update_all(["identifier = 'abc123'"], "id = 10")
assert_equal true, Repository.find(10).identifier_frozen?
end
def test_identifier_should_not_accept_change_if_frozen
r = Repository.new(:identifier => 'foo')
r.stubs(:identifier_frozen?).returns(true)
r.identifier = 'bar'
assert_equal 'foo', r.identifier
end
def test_identifier_should_accept_change_if_not_frozen
r = Repository.new(:identifier => 'foo')
r.stubs(:identifier_frozen?).returns(false)
r.identifier = 'bar'
assert_equal 'bar', r.identifier
end
def test_destroy
repository = Repository.find(10)