summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-06-24 09:47:13 +0000
committerDouwe Maan <douwe@gitlab.com>2015-06-24 09:47:13 +0000
commit43b444f40a1ae5b28ad3673a667e3539e28c5d68 (patch)
tree4c2d93b99583d4c72c7479eb49cf6e5b8328f253 /app
parentffe974020e994e3070e197ec62ba3f62935d9782 (diff)
parente9b65a3e05ca3bf4ea42f547f42a133802037b7e (diff)
downloadgitlab-ce-43b444f40a1ae5b28ad3673a667e3539e28c5d68.tar.gz
Merge branch 'rs-issue-1850' into 'master'
Only look up Commit authors/committers by email - Removes looking up authors/committers by name - Renames `User.find_for_commit` to `User.find_by_any_email` Closes #1850 See merge request !878
Diffstat (limited to 'app')
-rw-r--r--app/models/commit.rb4
-rw-r--r--app/models/user.rb12
2 files changed, 6 insertions, 10 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 9d721661629..aff329d71fa 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -157,11 +157,11 @@ class Commit
end
def author
- User.find_for_commit(author_email, author_name)
+ @author ||= User.find_by_any_email(author_email)
end
def committer
- User.find_for_commit(committer_email, committer_name)
+ @committer ||= User.find_by_any_email(committer_email)
end
def notes
diff --git a/app/models/user.rb b/app/models/user.rb
index f1bcecc13b3..dc84f5141d8 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -225,7 +225,8 @@ class User < ActiveRecord::Base
end
end
- def find_for_commit(email, name)
+ # Find a User by their primary email or any associated secondary email
+ def find_by_any_email(email)
user_table = arel_table
email_table = Email.arel_table
@@ -237,13 +238,8 @@ class User < ActiveRecord::Base
join(email_table, Arel::Nodes::OuterJoin).
# ON "users"."id" = "emails"."user_id"
on(user_table[:id].eq(email_table[:user_id])).
- # WHERE ("user"."email" = '<email>' OR "user"."name" = '<name>')
- # OR "emails"."email" = '<email>'
- where(
- user_table[:email].eq(email).
- or(user_table[:name].eq(name)).
- or(email_table[:email].eq(email))
- )
+ # WHERE ("user"."email" = '<email>' OR "emails"."email" = '<email>')
+ where(user_table[:email].eq(email).or(email_table[:email].eq(email)))
find_by_sql(query.to_sql).first
end