changeset 1764:39b49c999efb beta

fixes issue #320. - added mapping of commit users into rhodecode users
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 08 Dec 2011 01:23:11 +0200
parents d09c52be40e0
children eb5099dbf0e6
files rhodecode/lib/helpers.py rhodecode/templates/changelog/changelog.html rhodecode/templates/files/files_annotate.html rhodecode/templates/files/files_browser.html rhodecode/templates/files/files_source.html
diffstat 5 files changed, 42 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/lib/helpers.py	Thu Dec 08 01:17:37 2011 +0200
+++ b/rhodecode/lib/helpers.py	Thu Dec 08 01:23:11 2011 +0200
@@ -38,7 +38,6 @@
 from rhodecode.lib.annotate import annotate_highlight
 from rhodecode.lib.utils import repo_name_slug
 from rhodecode.lib import str2bool, safe_unicode, safe_str, get_changeset_safe
-
 from rhodecode.lib.markup_renderer import MarkupRenderer
 
 def _reset(name, value=None, id=NotGiven, type="reset", **attrs):
@@ -288,15 +287,50 @@
 #==============================================================================
 from vcs.utils import author_name, author_email
 from rhodecode.lib import credentials_filter, age as _age
+from rhodecode.model.db import User
 
 age = lambda  x:_age(x)
 capitalize = lambda x: x.capitalize()
 email = author_email
-email_or_none = lambda x: email(x) if email(x) != x else None
 person = lambda x: author_name(x)
 short_id = lambda x: x[:12]
 hide_credentials = lambda x: ''.join(credentials_filter(x))
 
+
+def email_or_none(x):
+    if email(x) != '':
+        return email(x)
+
+    # See if it contains a username we can get an email from
+    user = User.get_by_username(author_name(x), case_insensitive=True,
+                                cache=True)
+    if user is not None:
+        return user.email
+
+    # No valid email, not a valid user in the system, none!
+    return None
+
+def person(x):
+    # Valid email in the attribute passed, see if they're in the system
+
+    # attr to return from fetched user
+    person_getter = lambda usr: usr.username
+
+    if email(x) != '':
+        user = User.get_by_email(email(x), case_insensitive=True, cache=True)
+        if user is not None:
+            return person_getter(user)
+        return email(x)
+
+    # Maybe it's a username?
+    user = User.get_by_username(author_name(x), case_insensitive=True,
+                                cache=True)
+    if user is not None:
+        return person_getter(user)
+
+    # Still nothing?  Just pass back the author name then
+    return author_name(x)
+
 def bool2icon(value):
     """Returns True/False values represented as small html image of true/false
     icons
--- a/rhodecode/templates/changelog/changelog.html	Thu Dec 08 01:17:37 2011 +0200
+++ b/rhodecode/templates/changelog/changelog.html	Thu Dec 08 01:23:11 2011 +0200
@@ -54,8 +54,7 @@
 								<div class="gravatar">
 									<img alt="gravatar" src="${h.gravatar_url(h.email(cs.author),16)}"/>
 								</div>
-								<div title="${h.email_or_none(cs.author)}" class="user">${h.person(cs.author)}</div>
-								##<span><a href="mailto:${h.email_or_none(cs.author)}">${h.email_or_none(cs.author)}</a></span><br/>
+								<div title="${cs.author}" class="user">${h.person(cs.author)}</div>
 							</div>
 							<div class="message">${h.link_to(h.wrap_paragraphs(cs.message),h.url('changeset_home',repo_name=c.repo_name,revision=cs.raw_id))}</div>
 						</div>	
--- a/rhodecode/templates/files/files_annotate.html	Thu Dec 08 01:17:37 2011 +0200
+++ b/rhodecode/templates/files/files_annotate.html	Thu Dec 08 01:23:11 2011 +0200
@@ -64,7 +64,7 @@
                         <div class="gravatar">
                             <img alt="gravatar" src="${h.gravatar_url(h.email(c.cs.author),16)}"/>
                         </div>
-                        <div title="${h.email_or_none(c.cs.author)}" class="user">${h.person(c.cs.author)}</div>
+                        <div title="${c.cs.author}" class="user">${h.person(c.cs.author)}</div>
                     </div>
                     <div class="commit">${c.file.last_changeset.message}</div>
                 </div>
--- a/rhodecode/templates/files/files_browser.html	Thu Dec 08 01:17:37 2011 +0200
+++ b/rhodecode/templates/files/files_browser.html	Thu Dec 08 01:23:11 2011 +0200
@@ -96,7 +96,9 @@
 		             </td>
 		             <td>
 		             	%if node.is_file():
-		             		${node.last_changeset.author}
+		             		<span title="${node.last_changeset.author}">
+                            ${h.person(node.last_changeset.author)}
+                            </span>
 		             	%endif                    
 		             </td>
 				</tr>
--- a/rhodecode/templates/files/files_source.html	Thu Dec 08 01:17:37 2011 +0200
+++ b/rhodecode/templates/files/files_source.html	Thu Dec 08 01:23:11 2011 +0200
@@ -35,7 +35,7 @@
             <div class="gravatar">
                 <img alt="gravatar" src="${h.gravatar_url(h.email(c.changeset.author),16)}"/>
             </div>
-            <div title="${h.email_or_none(c.changeset.author)}" class="user">${h.person(c.changeset.author)}</div>
+            <div title="${c.changeset.author}" class="user">${h.person(c.changeset.author)}</div>
         </div>
 		<div class="commit">${c.file.last_changeset.message}</div>
 	</div>