Changeset - 819eb7f8a555
[Not reviewed]
beta
0 5 0
Marcin Kuzminski - 13 years ago 2012-09-13 20:07:43
marcin@python-works.com
Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
to alternative_gravatar_url
5 files changed with 32 insertions and 0 deletions:
0 comments (0 inline, 0 general)
development.ini
Show inline comments
 
@@ -69,6 +69,8 @@ use_gravatar = true
 
## {email}        user email
 
## {md5email}     md5 hash of the user email (like at gravatar.com)
 
## {size}         size of the image that is expected from the server application
 
## {scheme}       http/https from RhodeCode server
 
## {netloc}       network location from RhodeCode server
 
#alternative_gravatar_url = http://myavatarserver.com/getbyemail/{email}/{size}
 
#alternative_gravatar_url = http://myavatarserver.com/getbymd5/{md5email}?s={size}
 

	
production.ini
Show inline comments
 
@@ -69,6 +69,8 @@ use_gravatar = true
 
## {email}        user email
 
## {md5email}     md5 hash of the user email (like at gravatar.com)
 
## {size}         size of the image that is expected from the server application
 
## {scheme}       http/https from RhodeCode server
 
## {netloc}       network location from RhodeCode server
 
#alternative_gravatar_url = http://myavatarserver.com/getbyemail/{email}/{size}
 
#alternative_gravatar_url = http://myavatarserver.com/getbymd5/{md5email}?s={size}
 

	
rhodecode/config/deployment.ini_tmpl
Show inline comments
 
@@ -69,6 +69,8 @@ use_gravatar = true
 
## {email}        user email
 
## {md5email}     md5 hash of the user email (like at gravatar.com)
 
## {size}         size of the image that is expected from the server application
 
## {scheme}       http/https from RhodeCode server
 
## {netloc}       network location from RhodeCode server
 
#alternative_gravatar_url = http://myavatarserver.com/getbyemail/{email}/{size}
 
#alternative_gravatar_url = http://myavatarserver.com/getbymd5/{md5email}?s={size}
 

	
rhodecode/lib/helpers.py
Show inline comments
 
@@ -10,6 +10,7 @@ import urllib
 
import math
 
import logging
 
import re
 
import urlparse
 

	
 
from datetime import datetime
 
from pygments.formatters.html import HtmlFormatter
 
@@ -711,11 +712,15 @@ HasRepoPermissionAny, HasRepoPermissionA
 
#==============================================================================
 

	
 
def gravatar_url(email_address, size=30):
 
    from pylons import url  ## doh, we need to re-import url to mock it later
 
    if(str2bool(config['app_conf'].get('use_gravatar')) and
 
       config['app_conf'].get('alternative_gravatar_url')):
 
        tmpl = config['app_conf'].get('alternative_gravatar_url', '')
 
        parsed_url = urlparse.urlparse(url.current(qualified=True))
 
        tmpl = tmpl.replace('{email}', email_address)\
 
                   .replace('{md5email}', hashlib.md5(email_address.lower()).hexdigest())\
 
                   .replace('{netloc}', parsed_url.netloc)\
 
                   .replace('{scheme}', parsed_url.scheme)\
 
                   .replace('{size}', str(size))
 
        return tmpl
 

	
rhodecode/tests/test_libs.py
Show inline comments
 
@@ -159,6 +159,20 @@ class TestLibs(unittest.TestCase):
 
            config['app_conf']['use_gravatar'] = True
 
            config['app_conf'].update(kwargs)
 
            return config
 

	
 
        class fake_url():
 
            @classmethod
 
            def current(cls, *args, **kwargs):
 
                return 'https://server.com'
 

	
 
        with mock.patch('pylons.url', fake_url):
 
            fake = fake_conf(alternative_gravatar_url='http://test.com/{email}')
 
            with mock.patch('pylons.config', fake):
 
                    from pylons import url
 
                    assert url.current() == 'http://server.com'
 
                    grav = gravatar_url(email_address='test@foo.com', size=24)
 
                    assert grav == 'http://test.com/test@foo.com'
 

	
 
        fake = fake_conf(alternative_gravatar_url='http://test.com/{email}')
 
        with mock.patch('pylons.config', fake):
 
            grav = gravatar_url(email_address='test@foo.com', size=24)
 
@@ -175,3 +189,10 @@ class TestLibs(unittest.TestCase):
 
            em = 'test@foo.com'
 
            grav = gravatar_url(email_address=em, size=24)
 
            assert grav == 'http://test.com/%s/%s' % (_md5(em), 24)
 

	
 
            fake = fake_conf(alternative_gravatar_url='{scheme}://{netloc}/{md5email}/{size}')
 
            with mock.patch('pylons.config', fake):
 
                em = 'test@foo.com'
 
                grav = gravatar_url(email_address=em, size=24)
 
                assert grav == 'https://server.com/%s/%s' % (_md5(em), 24)
 

	
0 comments (0 inline, 0 general)