Jump to >


class FakeHTTPRequest(user, local_site_name=None)[source]

Bases: django.http.request.HttpRequest

A fake HttpRequest implementation.

The WebAPI serialization methods use HttpRequest.build_absolute_uri to generate all the links, but none of the various signals that generate webhook events have the request plumbed through. Since we don’t actually need a valid request, this impersonates it enough to get valid results from build_absolute_uri.

__init__(user, local_site_name=None)[source]

Initialize a FakeHTTPRequest.

  • user (django.contrib.auth.models.User) – The user who initiated the request.
  • local_site_name (unicode, optional) – The local site name (if the request was carried out against a local site).
class CustomPayloadParser(*args, **kwargs)[source]

Bases: django.template.base.Parser

A custom template parser that blocks certain tags.

This extends Django’s Parser class for template parsing, and removes some built-in tags, in order to prevent mailicious use.

BLACKLISTED_TAGS = (u'block', u'debug', u'extends', u'include', u'load', u'ssi')[source]
__init__(*args, **kwargs)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

render_custom_content(body, context_data={})[source]

Renders custom content for the payload using Django templating.

This will take the custom payload content template provided by the user and render it using a stripped down version of Django’s templating system.

In order to keep the payload safe, we use a limited Context along with a custom Parser that blocks certain template tags. This gives us tags like {% for %} and {% if %}, but blacklists tags like {% load %} and {% include %}.

normalize_webhook_payload(payload, request)[source]

Normalize a payload for a WebHook, returning a safe, primitive version.

This will take a payload containing various data types and model references and turn it into a payload built out of specific, whitelisted types (strings, bools, ints, dicts, lists, and datetimes). This payload is safe to include in custom templates without worrying about access to dangerous functions, and is easy to serialize.


The normalized payload.

Return type:



TypeError – An unsupported data type was found in the payload. This is an issue with the caller.

dispatch_webhook_event(request, webhook_targets, event, payload)[source]

Dispatch the given event and payload to the given WebHook targets.

  • request (django.http.HttpRequest) – The HTTP request from the client.
  • webhook_targets (list of reviewboard.notifications.models.WebHookTarget) – The list of WebHook targets containing endpoint URLs to dispatch to.
  • event (unicode) – The name of the event being dispatched.
  • payload (dict) – The payload data to encode for the WebHook payload.

ValueError – There was an error with the payload format. Details are in the log and the exception message.

review_request_closed_cb(user, review_request, close_type, **kwargs)[source]
review_request_published_cb(user, review_request, changedesc, **kwargs)[source]
review_request_reopened_cb(user, review_request, **kwargs)[source]
review_published_cb(user, review, **kwargs)[source]
reply_published_cb(user, reply, **kwargs)[source]