Esempio n. 1
0
    def get_context(self) -> MutableMapping[str, Any]:
        environment = self.event.get_tag("environment")
        enhanced_privacy = self.organization.flags.enhanced_privacy
        context = {
            "project_label": self.project.get_full_name(),
            "group": self.group,
            "event": self.event,
            "link": get_link(self.group, environment),
            "rules": get_rules(self.rules, self.organization, self.project),
            "has_integrations": has_integrations(self.organization,
                                                 self.project),
            "enhanced_privacy": enhanced_privacy,
            "commits": get_commits(self.project, self.event),
            "environment": environment,
            "slack_link": get_integration_link(self.organization, "slack"),
            "has_alert_integration": has_alert_integration(self.project),
        }

        # if the organization has enabled enhanced privacy controls we don't send
        # data which may show PII or source code
        if not enhanced_privacy:
            context.update({
                "tags": self.event.tags,
                "interfaces": get_interface_list(self.event)
            })

        return context
Esempio n. 2
0
    def get(self, request: Request, project) -> Response:
        """
        Retrieve a Project
        ``````````````````

        Return details on an individual project.

        :pparam string organization_slug: the slug of the organization the
                                          project belongs to.
        :pparam string project_slug: the slug of the project to retrieve.
        :auth: required
        """
        data = serialize(project, request.user, DetailedProjectSerializer())

        # TODO: should switch to expand and move logic into the serializer
        include = set(filter(bool, request.GET.get("include", "").split(",")))
        if "stats" in include:
            data["stats"] = {"unresolved": self._get_unresolved_count(project)}

        expand = request.GET.getlist("expand", [])
        if "hasAlertIntegration" in expand:
            data["hasAlertIntegrationInstalled"] = has_alert_integration(
                project)

        return Response(data)
Esempio n. 3
0
 def get_context(self) -> MutableMapping[str, Any]:
     return {
         **get_digest_as_context(self.digest),
         "has_alert_integration": has_alert_integration(self.project),
         "project": self.project,
         "slack_link": get_integration_link(self.organization, "slack"),
     }
Esempio n. 4
0
 def get_context(self) -> MutableMapping[str, Any]:
     start, end, counts = get_digest_metadata(self.digest)
     group = next(iter(counts))
     return {
         "counts": counts,
         "digest": self.digest,
         "end": end,
         "group": group,
         "has_alert_integration": has_alert_integration(self.project),
         "project": self.project,
         "slack_link": get_integration_link(self.organization, "slack"),
         "start": start,
     }
Esempio n. 5
0
 def get_context(self) -> MutableMapping[str, Any]:
     alert_status_page_enabled = features.has(
         "organizations:alert-rule-status-page", self.project.organization)
     rules_details = {
         rule.id: rule
         for rule in get_rules(list(self.digest.keys()),
                               self.project.organization, self.project)
     }
     return {
         **get_digest_as_context(self.digest),
         "has_alert_integration":
         has_alert_integration(self.project),
         "project":
         self.project,
         "slack_link":
         get_integration_link(self.organization, "slack"),
         "alert_status_page_enabled":
         alert_status_page_enabled,
         "rules_details":
         rules_details,
     }
Esempio n. 6
0
    def notify_digest(
        self,
        project: Project,
        digest: Any,
        target_type: ActionTargetType,
        target_identifier: Optional[int] = None,
    ) -> None:
        metrics.incr("mail_adapter.notify_digest")

        users = get_send_to(project, target_type,
                            target_identifier).get(ExternalProviders.EMAIL)
        if not users:
            return
        user_ids = {user.id for user in users}

        logger.info(
            "mail.adapter.notify_digest",
            extra={
                "project_id": project.id,
                "target_type": target_type.value,
                "target_identifier": target_identifier,
                "user_ids": user_ids,
            },
        )
        org = project.organization
        for user_id, digest in get_personalized_digests(
                target_type, project.id, digest, user_ids):
            start, end, counts = get_digest_metadata(digest)

            # If there is only one group in this digest (regardless of how many
            # rules it appears in), we should just render this using the single
            # notification template. If there is more than one record for a group,
            # just choose the most recent one.
            if len(counts) == 1:
                group = next(iter(counts))
                record = max(
                    itertools.chain.from_iterable(
                        groups.get(group, []) for groups in digest.values()),
                    key=lambda record: record.timestamp,
                )
                notification = Notification(record.value.event,
                                            rules=record.value.rules)
                return self.notify(notification, target_type,
                                   target_identifier)

            context = {
                "start": start,
                "end": end,
                "project": project,
                "digest": digest,
                "counts": counts,
                "slack_link": get_integration_link(org, "slack"),
                "has_alert_integration": has_alert_integration(project),
            }

            headers = {
                "X-Sentry-Project": project.slug,
                "X-SMTPAPI": json.dumps({"category": "digest_email"}),
            }

            group = next(iter(counts))
            subject = self.get_digest_subject(group, counts, start)

            self.add_unsubscribe_link(context, user_id, project,
                                      "alert_digest")
            self._send_mail(
                subject=subject,
                template="sentry/emails/digests/body.txt",
                html_template="sentry/emails/digests/body.html",
                project=project,
                reference=project,
                headers=headers,
                type="notify.digest",
                context=context,
                send_to=[user_id],
            )