doortts doortts 2017-03-24
avatar: Show Gravatar for fallback
@3379a7fc536dcd4a2c785aaf3aa171defb213509
app/assets/stylesheets/less/_page.less
--- app/assets/stylesheets/less/_page.less
+++ app/assets/stylesheets/less/_page.less
@@ -4592,7 +4592,6 @@
         background-position:center;
         .background-size(cover);
         .border-radius(4px);
-        .box-shadow(inset 0px 0px 10px rgba(0,0,0,.15));
     }
 
     .whoami {
app/models/User.java
--- app/models/User.java
+++ app/models/User.java
@@ -6,7 +6,10 @@
  **/
 package models;
 
-import com.avaje.ebean.*;
+import com.avaje.ebean.Ebean;
+import com.avaje.ebean.ExpressionList;
+import com.avaje.ebean.Page;
+import com.avaje.ebean.RawSqlBuilder;
 import controllers.UserApp;
 import models.enumeration.ResourceType;
 import models.enumeration.RoleType;
@@ -27,12 +30,12 @@
 import play.db.ebean.Transactional;
 import play.i18n.Messages;
 import utils.CacheStore;
+import utils.GravatarUtil;
 import utils.JodaDateUtil;
 import utils.ReservedWordsValidator;
 
 import javax.annotation.Nonnull;
 import javax.persistence.*;
-import javax.persistence.OrderBy;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
@@ -671,7 +674,17 @@
     public String avatarUrl() {
         Long avatarId = avatarId();
         if (avatarId == null) {
-            return UserApp.DEFAULT_AVATAR_URL;
+            return GravatarUtil.getAvatar(email, 64);
+        }
+        else {
+            return controllers.routes.AttachmentApp.getFile(avatarId).url();
+        }
+    }
+
+    public String avatarUrl(int size) {
+        Long avatarId = avatarId();
+        if (avatarId == null) {
+            return GravatarUtil.getAvatar(email, size);
         }
         else {
             return controllers.routes.AttachmentApp.getFile(avatarId).url();
app/utils/GravatarUtil.java
--- app/utils/GravatarUtil.java
+++ app/utils/GravatarUtil.java
@@ -28,7 +28,7 @@
 public class GravatarUtil {
 
     public static final String DEFAULT_GRAVATAR_URL = "https://ko.gravatar.com/userimage/53495145/0eaeeb47c620542ad089f17377298af6.png";
-    public static final int DEFAULT_SIZE = 80;
+    public static final int DEFAULT_SIZE = 64;
 
     public static String getAvatar(String email) {
         return getAvatar(email, DEFAULT_SIZE);
app/utils/TemplateHelper.scala
--- app/utils/TemplateHelper.scala
+++ app/utils/TemplateHelper.scala
@@ -109,7 +109,7 @@
     Messages.get(_key, count.toString)
   }
 
-  def urlToPicture(email: String, size: Int = 34) = {
+  def urlToPicture(email: String, size: Int = 64) = {
     GravatarUtil.getAvatar(email, size)
   }
 
@@ -162,8 +162,16 @@
     }
   }
 
-  def getUserAvatar(user: models.User, avatarSize:String = "small") = {
-    user.refresh();
+  def getUserAvatarUrl(user: models.User, avatarSize: Int): String = {
+    if (user.avatarUrl == UserApp.DEFAULT_AVATAR_URL) {
+      urlToPicture(user.email, avatarSize)
+    } else {
+      user.avatarUrl
+    }
+  }
+
+  def getUserAvatar(user: models.User, avatarSize:String = "small"): String = {
+    user.refresh()
     var userInfoURL = routes.UserApp.userInfo(user.loginId).toString()
 
     "<a href=\"" + userInfoURL + "\" class=\"usf-group\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"" + user.name + "\"><img src=\"" + user.avatarUrl + "\" class=\"avatar-wrap " + avatarSize + "\"></a>"
app/views/board/partial_comments.scala.html
--- app/views/board/partial_comments.scala.html
+++ app/views/board/partial_comments.scala.html
@@ -40,7 +40,7 @@
     <li class="comment @isAuthorComment(comment.authorLoginId)" id="comment-@comment.id">
         <div class="comment-avatar">
             <a href="@routes.UserApp.userInfo(comment.authorLoginId)" class="avatar-wrap" data-toggle="tooltip" data-placement="top" title="@comment.authorName">
-                <img src="@User.findByLoginId(comment.authorLoginId).avatarUrl" width="32" height="32" alt="@comment.authorLoginId">
+                <img src="@User.findByLoginId(comment.authorLoginId).avatarUrl(64)" width="32" height="32" alt="@comment.authorLoginId">
             </a>
         </div>
         <div class="media-body">
@@ -48,7 +48,7 @@
                 <span class="comment_author pull-left">
                     <span class="resp-comment-avatar">
                         <a href="@userInfo(comment.authorLoginId)" class="avatar-wrap" data-toggle="tooltip" data-placement="top" title="@comment.authorName">
-                            <img src="@User.findByLoginId(comment.authorLoginId).avatarUrl" width="32" height="32" alt="@comment.authorLoginId">
+                            <img src="@User.findByLoginId(comment.authorLoginId).avatarUrl(64)" width="32" height="32" alt="@comment.authorLoginId">
                         </a>
                     </span>
                     <a href="@routes.UserApp.userInfo(comment.authorLoginId)" data-toggle="tooltip" data-placement="top" title="@comment.authorName">
app/views/board/partial_list.scala.html
--- app/views/board/partial_list.scala.html
+++ app/views/board/partial_list.scala.html
@@ -25,11 +25,7 @@
 @defining(User.findByLoginId(post.authorLoginId)){ user =>
 <li class="post-item">
     <a href="@routes.UserApp.userInfo(user.loginId)" class="avatar-wrap mlarge hide-in-mobile" data-toggle="tooltip" data-placement="bottom" title="@user.loginId">
-        @if(user.avatarUrl == UserApp.DEFAULT_AVATAR_URL){
-            <img src="@urlToPicture(user.email, 32)">
-        } else {
-            <img src="@user.avatarUrl" alt="@user.name" width="32" height="32"/>
-        }
+        <img src="@user.avatarUrl(64)" alt="@user.name" width="32" height="32"/>
     </a>
     <div class="title-wrap">
         @if(post.notice){
app/views/board/view.scala.html
--- app/views/board/view.scala.html
+++ app/views/board/view.scala.html
@@ -52,7 +52,7 @@
                 <div class="author-info">
                         <a href="@userInfo(post.authorLoginId)" class="usf-group">
                             <span class="avatar-wrap smaller">
-                                <img src="@User.findByLoginId(post.authorLoginId).avatarUrl" width="20" height="20">
+                                <img src="@User.findByLoginId(post.authorLoginId).avatarUrl(32)" width="20" height="20">
                             </span>
                             @if(post.authorLoginId != null){
                                 <strong class="name">@post.authorName</strong>
app/views/common/usermenu.scala.html
--- app/views/common/usermenu.scala.html
+++ app/views/common/usermenu.scala.html
@@ -85,7 +85,7 @@
         <li class="gnb-usermenu-dropdown" id="sidebar-open-btn">
             <a href="javascript:void(0);" class="gnb-dropdown-toggle">
                 <span class="avatar-wrap smaller">
-                    <img src="@UserApp.currentUser().avatarUrl" />
+                    <img src="@UserApp.currentUser().avatarUrl(32)" />
                 </span>
                 <span class="caret-text">@UserApp.currentUser().name</span>
                 <span class="caret"></span>
app/views/issue/partial_comments.scala.html
--- app/views/issue/partial_comments.scala.html
+++ app/views/issue/partial_comments.scala.html
@@ -14,7 +14,7 @@
 
 @avatarByLoginId(loginId: String, loginName: String) = {
     <a href="@userInfo(loginId)" class="usf-group" data-toggle="tooltip" data-placement="top" title="@loginName">
-        <img src="@User.findByLoginId(loginId).avatarUrl" class="avatar-wrap small">
+        <img src="@getUserAvatarUrl(User.findByLoginId(loginId), 32)" class="avatar-wrap small">
     </a>
 }
 
@@ -67,7 +67,7 @@
     <li class="comment @isAuthorComment(comment.authorLoginId)" id="comment-@comment.id">
         <div class="comment-avatar">
             <a href="@userInfo(comment.authorLoginId)" class="avatar-wrap" data-toggle="tooltip" data-placement="top" title="@comment.authorName">
-                <img src="@User.findByLoginId(comment.authorLoginId).avatarUrl" width="32" height="32" alt="@comment.authorLoginId">
+                <img src="@User.findByLoginId(comment.authorLoginId).avatarUrl(64)" width="32" height="32" alt="@comment.authorLoginId">
             </a>
         </div>
         <div class="media-body">
@@ -75,7 +75,7 @@
                 <span class="comment_author pull-left">
                     <span class="resp-comment-avatar">
                         <a href="@userInfo(comment.authorLoginId)" class="avatar-wrap" data-toggle="tooltip" data-placement="top" title="@comment.authorName">
-                            <img src="@User.findByLoginId(comment.authorLoginId).avatarUrl" width="32" height="32" alt="@comment.authorLoginId">
+                            <img src="@User.findByLoginId(comment.authorLoginId).avatarUrl(64)" width="32" height="32" alt="@comment.authorLoginId">
                         </a>
                     </span>
                     <a href="@userInfo(comment.authorLoginId)" data-toggle="tooltip" data-placement="top" title="@comment.authorName">
app/views/issue/partial_list.scala.html
--- app/views/issue/partial_list.scala.html
+++ app/views/issue/partial_list.scala.html
@@ -28,11 +28,7 @@
             }
             <label for="issue-@issue.id" class="issue-item-row">
                 <a href="@routes.UserApp.userInfo(user.loginId)" class="avatar-wrap mlarge hide-in-mobile" data-toggle="tooltip" data-placement="top" title="@user.loginId">
-                    @if(user.avatarUrl == UserApp.DEFAULT_AVATAR_URL){
-                        <img src="@urlToPicture(user.email, 32)">
-                    } else {
-                        <img src="@user.avatarUrl" alt="@user.name" width="32" height="32"/>
-                    }
+                        <img src="@User.findByLoginId(issue.authorLoginId).avatarUrl(64)" alt="@user.name" width="32" height="32"/>
                 </a>
                 <div class="title-wrap">
                     <a href="@routes.IssueApp.issue(project.owner, project.name, issue.getNumber)" class="title">
app/views/issue/partial_massupdate.scala.html
--- app/views/issue/partial_massupdate.scala.html
+++ app/views/issue/partial_massupdate.scala.html
@@ -1,24 +1,12 @@
 @**
-* Yobi, Project Hosting SW
+* Yona, 21st Century Project Hosting SW
 *
-* Copyright 2013 NAVER Corp.
-* http://yobi.io
-*
-* @author Suwon Chae
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*   http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+* Copyright Yona & Yobi Authors & NAVER Corp.
+* https://yona.io
 **@
-@(project:Project, param:models.support.SearchCondition)
+@import models.support.SearchCondition
+@import utils.TemplateHelper._
+@(project:Project, param:SearchCondition)
 
 @labelList(project:Project) = {
     @IssueLabel.findByProject(project).groupBy(_.category).map {
@@ -85,7 +73,7 @@
                     <li data-value="@user.id">
                         <a class="usf-group">
                             <span class="avatar-wrap smaller">
-                                <img src="@user.avatarUrl" width="20" height="20">
+                                <img src="@user.avatarUrl(32)" width="20" height="20">
                             </span>
                             <strong class="name">@user.name</strong>
                             <span class="loginid"> <strong>@{"@"}</strong>@user.loginId</span>
app/views/issue/view.scala.html
--- app/views/issue/view.scala.html
+++ app/views/issue/view.scala.html
@@ -123,7 +123,7 @@
                 <div class="author-info">
                         <a href="@userInfo(issue.authorLoginId)" class="usf-group">
                             <span class="avatar-wrap smaller">
-                                <img src="@User.findByLoginId(issue.authorLoginId).avatarUrl" width="20" height="20">
+                                <img src="@User.findByLoginId(issue.authorLoginId).avatarUrl(32)" width="20" height="20">
                             </span>
                             @if(issue.authorLoginId != null){
                                 <strong class="name">@issue.authorName</strong>
app/views/user/edit.scala.html
--- app/views/user/edit.scala.html
+++ app/views/user/edit.scala.html
@@ -59,7 +59,7 @@
 
           <div class="avatar-frm">
             <div class="avatar-wrap xlarge">
-              <img src="@user.avatarUrl" style="width:128px; max-width:none;" />
+              <img src="@user.avatarUrl(256)" style="width:128px; max-width:none;" />
             </div>
             <div class="upload-progress avatar" style="display:none;"><div class="bar orange"></div></div>
             <div class="btn-wrap mt10 center-txt">
app/views/user/edit_emails.scala.html
--- app/views/user/edit_emails.scala.html
+++ app/views/user/edit_emails.scala.html
@@ -49,7 +49,7 @@
     <table class="table mt20">
       <tr>
         <td>
-          <img src="@getAvatar(user.email, 40)" width="40" height="40">
+          <img src="@user.avatarUrl(80)" width="40" height="40">
           <strong class="ml10">@user.email</strong>
           <span class="label-head vmiddle ml10">@Messages("emails.main.email")</span>
         </td>
app/views/user/view.scala.html
--- app/views/user/view.scala.html
+++ app/views/user/view.scala.html
@@ -36,7 +36,7 @@
     <div class="page-wrap">
         <section class="user-box">
             <div class="user-info-box">
-                <div class="whoami-wrap" style="background-image:url('@user.avatarUrl')"></div>
+                <div class="whoami-wrap" style="background-image:url('@user.avatarUrl(256)')"></div>
                 <div class="whoami usf-group">
                     <span class="name">@user.name</span>
                     <span class="loginid">@{"@"}@user.loginId</span>
Add a comment
List