def add_slack_btn(request): code = _get_validated_code(request, "slack") if code is None: return HttpResponseBadRequest() result = requests.post( "https://slack.com/api/oauth.access", { "client_id": settings.SLACK_CLIENT_ID, "client_secret": settings.SLACK_CLIENT_SECRET, "code": code }) doc = result.json() if doc.get("ok"): channel = Channel() channel.user = request.team.user channel.kind = "slack" channel.value = result.text channel.save() channel.assign_all_checks() messages.success(request, "The Slack integration has been added!") else: s = doc.get("error") messages.warning(request, "Error message from slack: %s" % s) return redirect("hc-channels")
def _make_user(email, with_project=True): username = str(uuid.uuid4())[:30] user = User(username=username, email=email) user.set_unusable_password() user.save() project = None if with_project: project = Project(owner=user) project.badge_key = user.username project.save() check = Check(project=project) check.name = "My First Check" check.save() channel = Channel(project=project) channel.kind = "email" channel.value = email channel.email_verified = True channel.save() channel.checks.add(check) # Ensure a profile gets created profile = Profile.objects.for_user(user) profile.current_project = project profile.save() return user
def _make_user(email, with_project=True): # Generate username from email in a deterministic way. # Since the database has an uniqueness constraint on username, # this makes sure that emails also are unique. username = str(uuid.uuid3(NAMESPACE_HC, email)) user = User(username=username, email=email) user.set_unusable_password() user.save() project = None if with_project: project = Project(owner=user) project.badge_key = user.username project.save() check = Check(project=project) check.name = "My First Check" check.save() channel = Channel(project=project) channel.kind = "email" channel.value = email channel.email_verified = True channel.save() channel.checks.add(check) # Ensure a profile gets created profile = Profile.objects.for_user(user) profile.current_project = project profile.save() return user
def add_slack_btn(request): code = request.GET.get("code", "") if len(code) < 8: return HttpResponseBadRequest() result = requests.post("https://slack.com/api/oauth.access", { "client_id": settings.SLACK_CLIENT_ID, "client_secret": settings.SLACK_CLIENT_SECRET, "code": code }) doc = result.json() if doc.get("ok"): channel = Channel() channel.user = request.team.user channel.kind = "slack" channel.value = result.text channel.save() channel.assign_all_checks() messages.success(request, "The Slack integration has been added!") else: s = doc.get("error") messages.warning(request, "Error message from slack: %s" % s) return redirect("hc-channels")
def _make_user(email): username = str(uuid.uuid4())[:30] user = User(username=username, email=email) user.save() channel = Channel() channel.user = user channel.kind = "email" channel.value = email channel.email_verified = True channel.save() return user
def handle(self, *args, **options): for user in User.objects.all(): q = Channel.objects.filter(user=user) q = q.filter(kind="email", email_verified=True, value=user.email) if q.count() > 0: continue print("Creating default channel for %s" % user.email) channel = Channel(user=user) channel.kind = "email" channel.value = user.email channel.email_verified = True channel.save() channel.checks.add(*Check.objects.filter(user=user))
def _make_user(email): username = str(uuid.uuid4())[:30] user = User(username=username, email=email) user.set_unusable_password() user.save() # Ensure a profile gets created Profile.objects.for_user(user) channel = Channel() channel.user = user channel.kind = "email" channel.value = email channel.email_verified = True channel.save() return user
def _make_user(email): username = str(uuid.uuid4())[:30] user = User(username=username, email=email) user.set_unusable_password() user.save() profile = Profile(user=user) profile.save() channel = Channel() channel.user = user channel.kind = "email" channel.value = email channel.email_verified = True channel.save() return user
def add_pd(request, state=None): if settings.PD_VENDOR_KEY is None: raise Http404("pagerduty integration is not available") if state and request.user.is_authenticated(): if "pd" not in request.session: return HttpResponseBadRequest() session_state = request.session.pop("pd") if session_state != state: return HttpResponseBadRequest() if request.GET.get("error") == "cancelled": messages.warning(request, "PagerDuty setup was cancelled") return redirect("hc-channels") channel = Channel() channel.user = request.team.user channel.kind = "pd" channel.value = json.dumps({ "service_key": request.GET.get("service_key"), "account": request.GET.get("account") }) channel.save() channel.assign_all_checks() messages.success(request, "The PagerDuty integration has been added!") return redirect("hc-channels") state = _prepare_state(request, "pd") callback = settings.SITE_ROOT + reverse("hc-add-pd-state", args=[state]) connect_url = "https://connect.pagerduty.com/connect?" + urlencode( { "vendor": settings.PD_VENDOR_KEY, "callback": callback }) ctx = {"page": "channels", "connect_url": connect_url} return render(request, "integrations/add_pd.html", ctx)
def add_pd(request, state=None): if settings.PD_VENDOR_KEY is None: raise Http404("pagerduty integration is not available") if state and request.user.is_authenticated(): if "pd" not in request.session: return HttpResponseBadRequest() session_state = request.session.pop("pd") if session_state != state: return HttpResponseBadRequest() if request.GET.get("error") == "cancelled": messages.warning(request, "PagerDuty setup was cancelled") return redirect("hc-channels") channel = Channel() channel.user = request.team.user channel.kind = "pd" channel.value = json.dumps({ "service_key": request.GET.get("service_key"), "account": request.GET.get("account") }) channel.save() channel.assign_all_checks() messages.success(request, "The PagerDuty integration has been added!") return redirect("hc-channels") state = _prepare_state(request, "pd") callback = settings.SITE_ROOT + reverse("hc-add-pd-state", args=[state]) connect_url = "https://connect.pagerduty.com/connect?" + urlencode({ "vendor": settings.PD_VENDOR_KEY, "callback": callback }) ctx = {"page": "channels", "connect_url": connect_url} return render(request, "integrations/add_pd.html", ctx)