diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-11-10 18:59:06 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-11-10 18:59:06 +0000 |
commit | 79c33bbc838fd837e516fd60569dbcf7917bd534 (patch) | |
tree | 20695e6f03f08925d6be3c96846668d979b4b3b3 /app/models/changeset.rb | |
parent | f6b2be81b9cb09485a08e58fc73d9290fd544148 (diff) | |
download | redmine-79c33bbc838fd837e516fd60569dbcf7917bd534.tar.gz redmine-79c33bbc838fd837e516fd60569dbcf7917bd534.zip |
Maps repository users to Redmine users (#1383).
Users with same username or email are automatically mapped. Mapping can be manually adjusted in repository settings. Multiple usernames can be mapped to the same Redmine user.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2006 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/changeset.rb')
-rw-r--r-- | app/models/changeset.rb | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/app/models/changeset.rb b/app/models/changeset.rb index c4258c88b..dd38ce757 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -1,5 +1,5 @@ -# redMine - project management software -# Copyright (C) 2006-2007 Jean-Philippe Lang +# Redmine - project management software +# Copyright (C) 2006-2008 Jean-Philippe Lang # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -19,13 +19,13 @@ require 'iconv' class Changeset < ActiveRecord::Base belongs_to :repository + belongs_to :user has_many :changes, :dependent => :delete_all has_and_belongs_to_many :issues acts_as_event :title => Proc.new {|o| "#{l(:label_revision)} #{o.revision}" + (o.comments.blank? ? '' : (': ' + o.comments))}, :description => :comments, :datetime => :committed_on, - :author => :committer, :url => Proc.new {|o| {:controller => 'repositories', :action => 'revision', :id => o.repository.project_id, :rev => o.revision}} acts_as_searchable :columns => 'comments', @@ -57,6 +57,14 @@ class Changeset < ActiveRecord::Base repository.project end + def author + user || committer.to_s.split('<').first + end + + def before_create + self.user = repository.find_committer_user(committer) + end + def after_create scan_comment_for_issue_ids end @@ -96,12 +104,11 @@ class Changeset < ActiveRecord::Base issue.reload # don't change the status is the issue is closed next if issue.status.is_closed? - user = committer_user || User.anonymous csettext = "r#{self.revision}" if self.scmid && (! (csettext =~ /^r[0-9]+$/)) csettext = "commit:\"#{self.scmid}\"" end - journal = issue.init_journal(user, l(:text_status_changed_by_changeset, csettext)) + journal = issue.init_journal(user || User.anonymous, l(:text_status_changed_by_changeset, csettext)) issue.status = fix_status issue.done_ratio = done_ratio if done_ratio issue.save @@ -113,16 +120,6 @@ class Changeset < ActiveRecord::Base self.issues = referenced_issues.uniq end - - # Returns the Redmine User corresponding to the committer - def committer_user - if committer && committer.strip =~ /^([^<]+)(<(.*)>)?$/ - username, email = $1.strip, $3 - u = User.find_by_login(username) - u ||= User.find_by_mail(email) unless email.blank? - u - end - end # Returns the previous changeset def previous @@ -140,7 +137,8 @@ class Changeset < ActiveRecord::Base end private - + + def self.to_utf8(str) return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii encoding = Setting.commit_logs_encoding.to_s.strip |