Makes repository url read-only after saving.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9878 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-06-20 18:45:51 +00:00
parent 37cbbcea71
commit 26e75568cf
4 changed files with 15 additions and 12 deletions

View File

@ -159,7 +159,7 @@ module RepositoriesHelper
def subversion_field_tags(form, repository) def subversion_field_tags(form, repository)
content_tag('p', form.text_field(:url, :size => 60, :required => true, content_tag('p', form.text_field(:url, :size => 60, :required => true,
:disabled => (repository && !repository.root_url.blank?)) + :disabled => !repository.safe_attribute?('url')) +
'<br />'.html_safe + '<br />'.html_safe +
'(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') + '(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') +
content_tag('p', form.text_field(:login, :size => 30)) + content_tag('p', form.text_field(:login, :size => 30)) +
@ -174,7 +174,7 @@ module RepositoriesHelper
content_tag('p', form.text_field( content_tag('p', form.text_field(
:url, :label => l(:field_path_to_repository), :url, :label => l(:field_path_to_repository),
:size => 60, :required => true, :size => 60, :required => true,
:disabled => (repository && !repository.new_record?))) + :disabled => !repository.safe_attribute?('url'))) +
content_tag('p', form.select( content_tag('p', form.select(
:log_encoding, [nil] + Setting::ENCODINGS, :log_encoding, [nil] + Setting::ENCODINGS,
:label => l(:field_commit_logs_encoding), :required => true)) :label => l(:field_commit_logs_encoding), :required => true))
@ -184,7 +184,7 @@ module RepositoriesHelper
content_tag('p', form.text_field( content_tag('p', form.text_field(
:url, :label => l(:field_path_to_repository), :url, :label => l(:field_path_to_repository),
:size => 60, :required => true, :size => 60, :required => true,
:disabled => (repository && !repository.root_url.blank?) :disabled => !repository.safe_attribute?('url')
) + ) +
'<br />'.html_safe + l(:text_mercurial_repository_note)) + '<br />'.html_safe + l(:text_mercurial_repository_note)) +
content_tag('p', form.select( content_tag('p', form.select(
@ -198,7 +198,7 @@ module RepositoriesHelper
content_tag('p', form.text_field( content_tag('p', form.text_field(
:url, :label => l(:field_path_to_repository), :url, :label => l(:field_path_to_repository),
:size => 60, :required => true, :size => 60, :required => true,
:disabled => (repository && !repository.root_url.blank?) :disabled => !repository.safe_attribute?('url')
) + ) +
'<br />'.html_safe + '<br />'.html_safe +
l(:text_git_repository_note)) + l(:text_git_repository_note)) +
@ -218,12 +218,12 @@ module RepositoriesHelper
:root_url, :root_url,
:label => l(:field_cvsroot), :label => l(:field_cvsroot),
:size => 60, :required => true, :size => 60, :required => true,
:disabled => !repository.new_record?)) + :disabled => !repository.safe_attribute?('root_url'))) +
content_tag('p', form.text_field( content_tag('p', form.text_field(
:url, :url,
:label => l(:field_cvs_module), :label => l(:field_cvs_module),
:size => 30, :required => true, :size => 30, :required => true,
:disabled => !repository.new_record?)) + :disabled => !repository.safe_attribute?('url'))) +
content_tag('p', form.select( content_tag('p', form.select(
:log_encoding, [nil] + Setting::ENCODINGS, :log_encoding, [nil] + Setting::ENCODINGS,
:label => l(:field_commit_logs_encoding), :required => true)) + :label => l(:field_commit_logs_encoding), :required => true)) +
@ -238,7 +238,7 @@ module RepositoriesHelper
content_tag('p', form.text_field( content_tag('p', form.text_field(
:url, :label => l(:field_path_to_repository), :url, :label => l(:field_path_to_repository),
:size => 60, :required => true, :size => 60, :required => true,
:disabled => (repository && !repository.new_record?))) + :disabled => !repository.safe_attribute?('url'))) +
content_tag('p', form.select( content_tag('p', form.select(
:log_encoding, [nil] + Setting::ENCODINGS, :log_encoding, [nil] + Setting::ENCODINGS,
:label => l(:field_commit_logs_encoding), :required => true)) :label => l(:field_commit_logs_encoding), :required => true))
@ -248,7 +248,7 @@ module RepositoriesHelper
content_tag('p', form.text_field( content_tag('p', form.text_field(
:url, :label => l(:field_root_directory), :url, :label => l(:field_root_directory),
:size => 60, :required => true, :size => 60, :required => true,
:disabled => (repository && !repository.root_url.blank?))) + :disabled => !repository.safe_attribute?('url'))) +
content_tag('p', form.select( content_tag('p', form.select(
:path_encoding, [nil] + Setting::ENCODINGS, :path_encoding, [nil] + Setting::ENCODINGS,
:label => l(:field_scm_path_encoding) :label => l(:field_scm_path_encoding)

View File

@ -44,13 +44,15 @@ class Repository < ActiveRecord::Base
validate :repo_create_validation, :on => :create validate :repo_create_validation, :on => :create
safe_attributes 'identifier', safe_attributes 'identifier',
'url',
'login', 'login',
'password', 'password',
'path_encoding', 'path_encoding',
'log_encoding', 'log_encoding',
'is_default' 'is_default'
safe_attributes 'url',
:if => lambda {|repository, user| repository.new_record?}
def repo_create_validation def repo_create_validation
unless Setting.enabled_scm.include?(self.class.name.demodulize) unless Setting.enabled_scm.include?(self.class.name.demodulize)
errors.add(:type, :invalid) errors.add(:type, :invalid)

View File

@ -21,7 +21,8 @@ require 'digest/sha1'
class Repository::Cvs < Repository class Repository::Cvs < Repository
validates_presence_of :url, :root_url, :log_encoding validates_presence_of :url, :root_url, :log_encoding
safe_attributes 'root_url' safe_attributes 'root_url',
:if => lambda {|repository, user| repository.new_record?}
def self.human_attribute_name(attribute_key_name, *args) def self.human_attribute_name(attribute_key_name, *args)
attr_name = attribute_key_name.to_s attr_name = attribute_key_name.to_s

View File

@ -40,7 +40,7 @@ class RepositoriesControllerTest < ActionController::TestCase
assert_template 'new' assert_template 'new'
assert_kind_of Repository::Subversion, assigns(:repository) assert_kind_of Repository::Subversion, assigns(:repository)
assert assigns(:repository).new_record? assert assigns(:repository).new_record?
assert_tag 'input', :attributes => {:name => 'repository[url]'} assert_tag 'input', :attributes => {:name => 'repository[url]', :disabled => nil}
end end
def test_new_should_propose_enabled_scm_only def test_new_should_propose_enabled_scm_only
@ -91,7 +91,7 @@ class RepositoriesControllerTest < ActionController::TestCase
assert_response :success assert_response :success
assert_template 'edit' assert_template 'edit'
assert_equal Repository.find(11), assigns(:repository) assert_equal Repository.find(11), assigns(:repository)
assert_tag 'input', :attributes => {:name => 'repository[url]', :value => 'svn://localhost/test'} assert_tag 'input', :attributes => {:name => 'repository[url]', :value => 'svn://localhost/test', :disabled => 'disabled'}
end end
def test_update def test_update