events: make the System URL extraction safer.

Prevents any possible errors inside events.
This commit is contained in:
Marcin Kuzminski 2017-02-13 17:08:28 +01:00
parent 886cc7d28b
commit dc8777ebe2
3 changed files with 17 additions and 2 deletions

View file

@ -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 = '<no server_url available>'
if self.request:
from rhodecode.lib import helpers as h
return h.url('home', qualified=True)
return '<no server_url available>'
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 = {

View file

@ -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):
"""

View file

@ -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 RhodecodeEvent
from rhodecode.events.interfaces import (
IUserRegistered, IUserPreCreate, IUserPreUpdate)
log = logging.getLogger(__name__)
@implementer(IUserRegistered)
class UserRegistered(RhodecodeEvent):