summaryrefslogtreecommitdiffstats
path: root/app/models/repository.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/repository.rb')
-rw-r--r--app/models/repository.rb13
1 files changed, 12 insertions, 1 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index c81979a26..9a6891a90 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -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