Keesun Baik 2014-04-09
History: fixed to use 'findByCommitterEmail'
@b5f9354d0cba510ae335f7729efbeb113575819c
app/models/User.java
--- app/models/User.java
+++ app/models/User.java
@@ -213,22 +213,28 @@
     }
 
     /**
-     * email로 사용자를 조회한다.
      *
-     * 사용자가 없으면 {@link #anonymous}객체에 email을 할당하고 반환한다.
+     * Find a user by email account.
+     * - find a user with a given email account or who has the email account  as one of sub email accounts.
+     * - If no user matched up with the given email account, then return the {@link #anonymous}
+     * after setting the email account to the object.
      *
      * @param email
      * @return
      */
     public static User findByEmail(String email) {
         User user = find.where().eq("email", email).findUnique();
-        if (user == null) {
-            anonymous.email = email;
-            return anonymous;
-        }
-        else {
+        if (user != null) {
             return user;
         }
+
+        Email subEmail = Email.findByEmail(email, true);
+        if (subEmail != null) {
+            return subEmail.user;
+        }
+
+        anonymous.email = email;
+        return anonymous;
     }
 
     /**
@@ -569,26 +575,6 @@
     public void removeEmail(Email email) {
         emails.remove(email);
         email.delete();
-    }
-
-    /**
-     * {@code committerEmail}에 해당하는 User를 찾아 반환한다.
-     *
-     * @param committerEmail
-     * @return
-     */
-    public static User findByCommitterEmail(String committerEmail) {
-        User user = find.where().eq("email", committerEmail).findUnique();
-        if (user != null) {
-            return user;
-        }
-
-        Email email = Email.findByEmail(committerEmail, true);
-        if (email != null) {
-            return email.user;
-        }
-
-        return anonymous;
     }
 
     public void visits(Project project) {
app/playRepository/GitBranch.java
--- app/playRepository/GitBranch.java
+++ app/playRepository/GitBranch.java
@@ -44,7 +44,7 @@
         this.name = name;
         this.shortName = StringUtils.removeStart(name, Constants.R_HEADS);
         this.headCommit = headCommit;
-        this.user = User.findByCommitterEmail(headCommit.getCommitterEmail());
+        this.user = User.findByEmail(headCommit.getCommitterEmail());
     }
 
     public String getName() {
app/playRepository/GitRepository.java
--- app/playRepository/GitRepository.java
+++ app/playRepository/GitRepository.java
@@ -1152,7 +1152,7 @@
         if (personIdent == null) {
             return User.anonymous;
         }
-        return User.findByCommitterEmail(personIdent.getEmailAddress());
+        return User.findByEmail(personIdent.getEmailAddress());
     }
 
     /**
Add a comment
List