From b4868a897284940a3e5e8e6ebcc246f21fb17fbe Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sun, 6 Nov 2011 22:38:08 +0200 Subject: [PATCH] Improved commit author detection --- app/models/project.rb | 5 +++++ app/views/projects/_tree_item.html.haml | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index de68f451..a5b6224b 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -50,6 +50,11 @@ class Project < ActiveRecord::Base code end + def team_member_by_name_or_email(email = nil, name = nil) + user = users.where("email like ? or name like ?", email, name).first + users_projects.find_by_user_id(user.id) if user + end + def common_notes notes.where(:noteable_type => ["", nil]) end diff --git a/app/views/projects/_tree_item.html.haml b/app/views/projects/_tree_item.html.haml index d15c379b..273d0272 100644 --- a/app/views/projects/_tree_item.html.haml +++ b/app/views/projects/_tree_item.html.haml @@ -13,6 +13,6 @@ ago %td.commit = link_to truncate(content_commit.safe_message, :length => fixed_mode? ? 40 : 80), project_commit_path(@project, content_commit), :class => "tree-commit-link" - - user = @project.users.find_by_email(content_commit.author_email) - - if user - = link_to "[#{user.name}]", project_team_member_path(@project, @project.users_projects.find_by_user_id(user.id)) + - tm = @project.team_member_by_name_or_email(content_commit.author_email, content_commit.author_name) + - if tm + = link_to "[#{tm.user_name}]", project_team_member_path(@project, tm)