|
|
@ -941,10 +941,12 @@ def add_pd(request, code): |
|
|
|
return render(request, "integrations/add_pd.html", ctx) |
|
|
|
|
|
|
|
|
|
|
|
def add_pdc(request, state=None): |
|
|
|
def add_pdc(request, code, state=None): |
|
|
|
if settings.PD_VENDOR_KEY is None: |
|
|
|
raise Http404("pagerduty integration is not available") |
|
|
|
|
|
|
|
project = _get_project_for_user(request, code) |
|
|
|
|
|
|
|
if state and request.user.is_authenticated: |
|
|
|
if "pd" not in request.session: |
|
|
|
return HttpResponseBadRequest() |
|
|
@ -954,11 +956,10 @@ def add_pdc(request, state=None): |
|
|
|
return HttpResponseBadRequest() |
|
|
|
|
|
|
|
if request.GET.get("error") == "cancelled": |
|
|
|
messages.warning(request, "PagerDuty setup was cancelled") |
|
|
|
return redirect("hc-channels") |
|
|
|
messages.warning(request, "PagerDuty setup was cancelled.") |
|
|
|
return redirect("hc-p-channels", project.code) |
|
|
|
|
|
|
|
channel = Channel(kind="pd", project=request.project) |
|
|
|
channel.user = request.project.owner |
|
|
|
channel = Channel(kind="pd", project=project) |
|
|
|
channel.value = json.dumps( |
|
|
|
{ |
|
|
|
"service_key": request.GET.get("service_key"), |
|
|
@ -968,15 +969,18 @@ def add_pdc(request, state=None): |
|
|
|
channel.save() |
|
|
|
channel.assign_all_checks() |
|
|
|
messages.success(request, "The PagerDuty integration has been added!") |
|
|
|
return redirect("hc-channels") |
|
|
|
return redirect("hc-p-channels", project.code) |
|
|
|
|
|
|
|
state = _prepare_state(request, "pd") |
|
|
|
callback = settings.SITE_ROOT + reverse("hc-add-pdc-state", args=[state]) |
|
|
|
state = token_urlsafe() |
|
|
|
callback = settings.SITE_ROOT + reverse( |
|
|
|
"hc-add-pdc-state", args=[project.code, state] |
|
|
|
) |
|
|
|
connect_url = "https://connect.pagerduty.com/connect?" + urlencode( |
|
|
|
{"vendor": settings.PD_VENDOR_KEY, "callback": callback} |
|
|
|
) |
|
|
|
|
|
|
|
ctx = {"page": "channels", "project": request.project, "connect_url": connect_url} |
|
|
|
ctx = {"page": "channels", "project": project, "connect_url": connect_url} |
|
|
|
request.session["pd"] = state |
|
|
|
return render(request, "integrations/add_pdc.html", ctx) |
|
|
|
|
|
|
|
|
|
|
|