Commit a5459c04 authored by jplang's avatar jplang

Repository Identifier should be frozen (#11109).

git-svn-id: https://svn.redmine.org/redmine/trunk@10081 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 6ab22175
......@@ -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
......
......@@ -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 %>
......
......@@ -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.
......@@ -1054,3 +1054,4 @@ bg:
description_date_range_interval: Изберете диапазон чрез задаване на начална и крайна дати
description_date_from: Въведете начална дата
description_date_to: Въведете крайна дата
text_repository_identifier_info: 'Позволени са малки букви (a-z), цифри, тирета и _.<br />Промяна след създаването му не е възможна.'
......@@ -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.
......@@ -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.
......@@ -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.
......@@ -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.
......@@ -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.'
......@@ -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.
......@@ -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.'
......@@ -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.'
......@@ -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.
......@@ -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."
......@@ -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.
......@@ -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.
......@@ -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.
......@@ -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é.'
......@@ -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.
......@@ -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.
......@@ -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.
......@@ -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.
......@@ -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.
......@@ -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.
......@@ -1086,3 +1086,4 @@ ja:
label_fields_permissions: フィールドに対する権限
label_readonly: 読み取り専用
label_required: 必須
text_repository_identifier_info: アルファベット小文字(a-z)・数字・ハイフン・アンダースコアが使えます。<br />識別子は後で変更することはできません。
......@@ -1106,3 +1106,4 @@ ko:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: "소문자(a-z),숫자,대쉬(-)와 밑줄(_)만 가능합니다.<br />식별자는 저장후에는 수정할 없습니다."
......@@ -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.
......@@ -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.
......@@ -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.
......@@ -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.
......@@ -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.'
......@@ -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.
......@@ -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.
......@@ -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.
......@@ -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.
......@@ -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.
......@@ -1169,3 +1169,4 @@ ru:
label_fields_permissions: Fields permissions
label_readonly: Read-only
label_required: Required
text_repository_identifier_info: Допускаются только строчные латинские буквы (a-z), цифры, тире и подчеркивания.<br />После сохранения идентификатор изменить нельзя.
......@@ -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.
......@@ -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.
......@@ -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.'
......@@ -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.
......@@ -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.
......@@ -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.
......@@ -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.
......@@ -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.
......@@ -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.
......@@ -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.
......@@ -1137,3 +1137,4 @@
description_date_range_interval: 選擇起始與結束日期以設定範圍區間
description_date_from: 輸入起始日期
description_date_to: 輸入結束日期
text_repository_identifier_info: '僅允許使用小寫英文字母 (a-z), 阿拉伯數字, 虛線與底線。<br />一旦儲存之後, 代碼便無法再次被更改。'
......@@ -1060,3 +1060,4 @@ zh:
label_fields_permissions: 字段权限
label_readonly: 只读
label_required: 必填
text_repository_identifier_info: 仅小写字母(a-z)、数字、破折号(-)和下划线(_)可以使用。<br />一旦保存,标识无法修改。
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment