Ejemplo n.º 1
0
    def validate(self, data):
        valid_scopes = ApiScopes()
        if data is None:
            raise ValidationError('Must provide scopes')

        for scope in data:
            if scope not in valid_scopes:
                raise ValidationError(u'{} not a valid scope'.format(scope))
Ejemplo n.º 2
0
    def validate(self, data):
        valid_scopes = ApiScopes()

        if not data:
            return

        for scope in data:
            if scope not in valid_scopes:
                raise ValidationError(u'{} not a valid scope'.format(scope))
Ejemplo n.º 3
0
    def to_internal_value(self, data):
        valid_scopes = ApiScopes()

        if data is None:
            return

        for scope in data:
            if scope not in valid_scopes:
                raise ValidationError(u"{} not a valid scope".format(scope))
        return data
Ejemplo n.º 4
0
class SentryApp(ParanoidModel):
    __core__ = True

    application = models.OneToOneField('sentry.ApiApplication',
                                       related_name='sentry_app')

    # Much of the OAuth system in place currently depends on a User existing.
    # This "proxy user" represents the SentryApp in those cases.
    proxy_user = models.OneToOneField('sentry.User', related_name='sentry_app')

    # The owner is an actual Sentry User who created the SentryApp. Used to
    # determine who can manage the SentryApp itself.
    owner = FlexibleForeignKey('sentry.User', related_name='owned_sentry_apps')

    # The set of OAuth scopes necessary for this integration to function.
    scopes = BitField(flags=ApiScopes().to_bitfield())
    scope_list = ArrayField(of=models.TextField())

    name = models.TextField()
    slug = models.CharField(max_length=64, unique=True)
    uuid = models.CharField(max_length=64,
                            default=lambda: six.binary_type(uuid.uuid4()))

    webhook_url = models.TextField()

    date_added = models.DateTimeField(default=timezone.now)
    date_updated = models.DateTimeField(default=timezone.now)

    class Meta:
        app_label = 'sentry'
        db_table = 'sentry_sentryapp'

    def save(self, *args, **kwargs):
        self._set_slug()
        return super(SentryApp, self).save(*args, **kwargs)

    def _set_slug(self):
        """
        Matches ``name``, but in lowercase, dash form.

        >>> self._set_slug('My Cool App')
        >>> self.slug
        my-cool-app
        """
        if not self.slug:
            self.slug = slugify(self.name)