# HG changeset patch # User Marcin Kuzminski # Date 2017-02-13 16:08:28 # Node ID 5c92e9f4a7c8c77f96ac7f299998bc268f8ced46 # Parent 8b2e03e1440379c86a42fde666a26ec24bc6a199 events: make the System URL extraction safer. Prevents any possible errors inside events. diff --git a/rhodecode/events/base.py b/rhodecode/events/base.py --- a/rhodecode/events/base.py +++ b/rhodecode/events/base.py @@ -15,6 +15,7 @@ # This program is dual-licensed. If you wish to learn more about the # RhodeCode Enterprise Edition, including its added features, Support services, # and proprietary license terms, please see https://rhodecode.com/licenses/ +import logging from datetime import datetime from pyramid.threadlocal import get_current_request @@ -26,6 +27,8 @@ SYSTEM_USER = AttributeDict(dict( username='__SYSTEM__' )) +log = logging.getLogger(__name__) + class RhodecodeEvent(object): """ @@ -66,10 +69,16 @@ class RhodecodeEvent(object): @property def server_url(self): + default = '' if self.request: from rhodecode.lib import helpers as h - return h.url('home', qualified=True) - return '' + try: + return h.url('home', qualified=True) + except Exception: + log.exception('Failed to fetch URL for server') + return default + + return default def as_dict(self): data = { diff --git a/rhodecode/events/pullrequest.py b/rhodecode/events/pullrequest.py --- a/rhodecode/events/pullrequest.py +++ b/rhodecode/events/pullrequest.py @@ -16,11 +16,14 @@ # RhodeCode Enterprise Edition, including its added features, Support services, # and proprietary license terms, please see https://rhodecode.com/licenses/ +import logging from rhodecode.translation import lazy_ugettext from rhodecode.events.repo import ( RepoEvent, _commits_as_dict, _issues_as_dict) +log = logging.getLogger(__name__) + class PullRequestEvent(RepoEvent): """ diff --git a/rhodecode/events/user.py b/rhodecode/events/user.py --- a/rhodecode/events/user.py +++ b/rhodecode/events/user.py @@ -15,6 +15,7 @@ # This program is dual-licensed. If you wish to learn more about the # RhodeCode Enterprise Edition, including its added features, Support services, # and proprietary license terms, please see https://rhodecode.com/licenses/ +import logging from zope.interface import implementer @@ -23,6 +24,8 @@ from rhodecode.events.base import Rhodec from rhodecode.events.interfaces import ( IUserRegistered, IUserPreCreate, IUserPreUpdate) +log = logging.getLogger(__name__) + @implementer(IUserRegistered) class UserRegistered(RhodecodeEvent):