##// END OF EJS Templates
Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}...
marcink -
r2836:819eb7f8 beta
parent child Browse files
Show More
@@ -69,6 +69,8 b' use_gravatar = true'
69 ## {email} user email
69 ## {email} user email
70 ## {md5email} md5 hash of the user email (like at gravatar.com)
70 ## {md5email} md5 hash of the user email (like at gravatar.com)
71 ## {size} size of the image that is expected from the server application
71 ## {size} size of the image that is expected from the server application
72 ## {scheme} http/https from RhodeCode server
73 ## {netloc} network location from RhodeCode server
72 #alternative_gravatar_url = http://myavatarserver.com/getbyemail/{email}/{size}
74 #alternative_gravatar_url = http://myavatarserver.com/getbyemail/{email}/{size}
73 #alternative_gravatar_url = http://myavatarserver.com/getbymd5/{md5email}?s={size}
75 #alternative_gravatar_url = http://myavatarserver.com/getbymd5/{md5email}?s={size}
74
76
@@ -69,6 +69,8 b' use_gravatar = true'
69 ## {email} user email
69 ## {email} user email
70 ## {md5email} md5 hash of the user email (like at gravatar.com)
70 ## {md5email} md5 hash of the user email (like at gravatar.com)
71 ## {size} size of the image that is expected from the server application
71 ## {size} size of the image that is expected from the server application
72 ## {scheme} http/https from RhodeCode server
73 ## {netloc} network location from RhodeCode server
72 #alternative_gravatar_url = http://myavatarserver.com/getbyemail/{email}/{size}
74 #alternative_gravatar_url = http://myavatarserver.com/getbyemail/{email}/{size}
73 #alternative_gravatar_url = http://myavatarserver.com/getbymd5/{md5email}?s={size}
75 #alternative_gravatar_url = http://myavatarserver.com/getbymd5/{md5email}?s={size}
74
76
@@ -69,6 +69,8 b' use_gravatar = true'
69 ## {email} user email
69 ## {email} user email
70 ## {md5email} md5 hash of the user email (like at gravatar.com)
70 ## {md5email} md5 hash of the user email (like at gravatar.com)
71 ## {size} size of the image that is expected from the server application
71 ## {size} size of the image that is expected from the server application
72 ## {scheme} http/https from RhodeCode server
73 ## {netloc} network location from RhodeCode server
72 #alternative_gravatar_url = http://myavatarserver.com/getbyemail/{email}/{size}
74 #alternative_gravatar_url = http://myavatarserver.com/getbyemail/{email}/{size}
73 #alternative_gravatar_url = http://myavatarserver.com/getbymd5/{md5email}?s={size}
75 #alternative_gravatar_url = http://myavatarserver.com/getbymd5/{md5email}?s={size}
74
76
@@ -10,6 +10,7 b' import urllib'
10 import math
10 import math
11 import logging
11 import logging
12 import re
12 import re
13 import urlparse
13
14
14 from datetime import datetime
15 from datetime import datetime
15 from pygments.formatters.html import HtmlFormatter
16 from pygments.formatters.html import HtmlFormatter
@@ -711,11 +712,15 b' HasRepoPermissionAny, HasRepoPermissionA'
711 #==============================================================================
712 #==============================================================================
712
713
713 def gravatar_url(email_address, size=30):
714 def gravatar_url(email_address, size=30):
715 from pylons import url ## doh, we need to re-import url to mock it later
714 if(str2bool(config['app_conf'].get('use_gravatar')) and
716 if(str2bool(config['app_conf'].get('use_gravatar')) and
715 config['app_conf'].get('alternative_gravatar_url')):
717 config['app_conf'].get('alternative_gravatar_url')):
716 tmpl = config['app_conf'].get('alternative_gravatar_url', '')
718 tmpl = config['app_conf'].get('alternative_gravatar_url', '')
719 parsed_url = urlparse.urlparse(url.current(qualified=True))
717 tmpl = tmpl.replace('{email}', email_address)\
720 tmpl = tmpl.replace('{email}', email_address)\
718 .replace('{md5email}', hashlib.md5(email_address.lower()).hexdigest())\
721 .replace('{md5email}', hashlib.md5(email_address.lower()).hexdigest()) \
722 .replace('{netloc}', parsed_url.netloc)\
723 .replace('{scheme}', parsed_url.scheme)\
719 .replace('{size}', str(size))
724 .replace('{size}', str(size))
720 return tmpl
725 return tmpl
721
726
@@ -159,19 +159,40 b' class TestLibs(unittest.TestCase):'
159 config['app_conf']['use_gravatar'] = True
159 config['app_conf']['use_gravatar'] = True
160 config['app_conf'].update(kwargs)
160 config['app_conf'].update(kwargs)
161 return config
161 return config
162 fake = fake_conf(alternative_gravatar_url='http://test.com/{email}')
162
163 with mock.patch('pylons.config', fake):
163 class fake_url():
164 grav = gravatar_url(email_address='test@foo.com', size=24)
164 @classmethod
165 assert grav == 'http://test.com/test@foo.com'
165 def current(cls, *args, **kwargs):
166 return 'https://server.com'
167
168 with mock.patch('pylons.url', fake_url):
169 fake = fake_conf(alternative_gravatar_url='http://test.com/{email}')
170 with mock.patch('pylons.config', fake):
171 from pylons import url
172 assert url.current() == 'http://server.com'
173 grav = gravatar_url(email_address='test@foo.com', size=24)
174 assert grav == 'http://test.com/test@foo.com'
175
176 fake = fake_conf(alternative_gravatar_url='http://test.com/{email}')
177 with mock.patch('pylons.config', fake):
178 grav = gravatar_url(email_address='test@foo.com', size=24)
179 assert grav == 'http://test.com/test@foo.com'
166
180
167 fake = fake_conf(alternative_gravatar_url='http://test.com/{md5email}')
181 fake = fake_conf(alternative_gravatar_url='http://test.com/{md5email}')
168 with mock.patch('pylons.config', fake):
182 with mock.patch('pylons.config', fake):
169 em = 'test@foo.com'
183 em = 'test@foo.com'
170 grav = gravatar_url(email_address=em, size=24)
184 grav = gravatar_url(email_address=em, size=24)
171 assert grav == 'http://test.com/%s' % (_md5(em))
185 assert grav == 'http://test.com/%s' % (_md5(em))
172
186
173 fake = fake_conf(alternative_gravatar_url='http://test.com/{md5email}/{size}')
187 fake = fake_conf(alternative_gravatar_url='http://test.com/{md5email}/{size}')
174 with mock.patch('pylons.config', fake):
188 with mock.patch('pylons.config', fake):
175 em = 'test@foo.com'
189 em = 'test@foo.com'
176 grav = gravatar_url(email_address=em, size=24)
190 grav = gravatar_url(email_address=em, size=24)
177 assert grav == 'http://test.com/%s/%s' % (_md5(em), 24)
191 assert grav == 'http://test.com/%s/%s' % (_md5(em), 24)
192
193 fake = fake_conf(alternative_gravatar_url='{scheme}://{netloc}/{md5email}/{size}')
194 with mock.patch('pylons.config', fake):
195 em = 'test@foo.com'
196 grav = gravatar_url(email_address=em, size=24)
197 assert grav == 'https://server.com/%s/%s' % (_md5(em), 24)
198
General Comments 0
You need to be logged in to leave comments. Login now