Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
class OrganizationOption(Model):
"""
Organization options apply only to an instance of a organization.
Options which are specific to a plugin should namespace
their key. e.g. key='myplugin:optname'
key: onboarding:complete
value: { updated: datetime }
"""
__core__ = True
organization = FlexibleForeignKey("sentry.Organization")
key = models.CharField(max_length=64)
value = EncryptedPickledObjectField()
objects = OrganizationOptionManager()
class Meta:
app_label = "sentry"
db_table = "sentry_organizationoptions"
unique_together = (("organization", "key"),)
__repr__ = sane_repr("organization_id", "key", "value")
from structlog import get_logger
from uuid import uuid4
from sentry import roles
from sentry.db.models import (
BaseModel, BoundedAutoField, BoundedPositiveIntegerField, FlexibleForeignKey, Model, sane_repr
)
from sentry.utils.http import absolute_uri
class OrganizationMemberTeam(BaseModel):
__core__ = True
id = BoundedAutoField(primary_key=True)
team = FlexibleForeignKey('sentry.Team')
organizationmember = FlexibleForeignKey('sentry.OrganizationMember')
# an inactive membership simply removes the team from the default list
# but still allows them to re-join without request
is_active = models.BooleanField(default=True)
class Meta:
app_label = 'sentry'
db_table = 'sentry_organizationmember_teams'
unique_together = (('team', 'organizationmember'), )
__repr__ = sane_repr('team_id', 'organizationmember_id')
def get_audit_log_data(self):
return {
'team_slug': self.team.slug,
'member_id': self.organizationmember_id,
'email': self.organizationmember.get_email(),
status = BoundedPositiveIntegerField(
default=ObjectStatus.VISIBLE, choices=ObjectStatus.as_choices()
)
class Meta:
app_label = "sentry"
db_table = "sentry_organizationintegration"
unique_together = (("organization", "integration"),)
# TODO(epurkhiser): This is deprecated and will be removed soon. Do not use
# Project Integrations.
class ProjectIntegration(Model):
__core__ = False
project = FlexibleForeignKey("sentry.Project")
integration = FlexibleForeignKey("sentry.Integration")
config = EncryptedJsonField(default=dict)
class Meta:
app_label = "sentry"
db_table = "sentry_projectintegration"
unique_together = (("project", "integration"),)
class Integration(Model):
__core__ = False
organizations = models.ManyToManyField(
"sentry.Organization", related_name="integrations", through=OrganizationIntegration
)
projects = models.ManyToManyField(
triggered_incidents = models.ManyToManyField(
"sentry.Incident", related_name="triggers", through=IncidentTrigger
)
date_added = models.DateTimeField(default=timezone.now)
class Meta:
app_label = "sentry"
db_table = "sentry_alertruletrigger"
unique_together = (("alert_rule", "label"),)
class AlertRuleTriggerExclusion(Model):
__core__ = True
alert_rule_trigger = FlexibleForeignKey("sentry.AlertRuleTrigger", related_name="exclusions")
query_subscription = FlexibleForeignKey("sentry.QuerySubscription")
date_added = models.DateTimeField(default=timezone.now)
class Meta:
app_label = "sentry"
db_table = "sentry_alertruletriggerexclusion"
unique_together = (("alert_rule_trigger", "query_subscription"),)
class AlertRuleTriggerAction(Model):
"""
This model represents an action that occurs when a trigger is fired. This is
typically some sort of notification.
"""
__core__ = True
from __future__ import absolute_import
from django.db import models, router, connections
from django.utils import timezone
from sentry.db.models import Model, BoundedBigIntegerField, FlexibleForeignKey, sane_repr
class EventTag(Model):
__core__ = False
project_id = BoundedBigIntegerField()
group_id = BoundedBigIntegerField()
event_id = BoundedBigIntegerField()
key = FlexibleForeignKey("tagstore.TagKey", db_column="key_id")
value = FlexibleForeignKey("tagstore.TagValue", db_column="value_id")
date_added = models.DateTimeField(default=timezone.now, db_index=True)
class Meta:
app_label = "tagstore"
unique_together = (("project_id", "event_id", "key", "value"),)
index_together = (("project_id", "key", "value"), ("group_id", "key", "value"))
__repr__ = sane_repr("event_id", "key_id", "value_id")
def delete(self):
using = router.db_for_read(EventTag)
cursor = connections[using].cursor()
cursor.execute(
"""
DELETE FROM tagstore_eventtag
WHERE project_id = %s
sync_group_assignee_outbound(group, None, assign=False)
class GroupAssignee(Model):
"""
Identifies an assignment relationship between a user/team and an
aggregated event (Group).
"""
__core__ = False
objects = GroupAssigneeManager()
project = FlexibleForeignKey("sentry.Project", related_name="assignee_set")
group = FlexibleForeignKey("sentry.Group", related_name="assignee_set", unique=True)
user = FlexibleForeignKey(
settings.AUTH_USER_MODEL, related_name="sentry_assignee_set", null=True
)
team = FlexibleForeignKey("sentry.Team", related_name="sentry_assignee_set", null=True)
date_added = models.DateTimeField(default=timezone.now)
class Meta:
app_label = "sentry"
db_table = "sentry_groupasignee"
unique_together = [("project", "group")]
__repr__ = sane_repr("group_id", "user_id", "team_id")
def save(self, *args, **kwargs):
assert not (self.user_id is not None and self.team_id is not None) and not (
self.user_id is None and self.team_id is None
), "Must have Team or User, not both"
from sentry.db.models import BaseManager, FlexibleForeignKey
from . import AvatarBase
class UserAvatar(AvatarBase):
"""
A UserAvatar associates a User with their avatar photo File
and contains their preferences for avatar type.
"""
AVATAR_TYPES = ((0, "letter_avatar"), (1, "upload"), (2, "gravatar"))
FILE_TYPE = "avatar.file"
user = FlexibleForeignKey("sentry.User", unique=True, related_name="avatar")
avatar_type = models.PositiveSmallIntegerField(default=0, choices=AVATAR_TYPES)
objects = BaseManager(cache_fields=["user"])
class Meta:
app_label = "sentry"
db_table = "sentry_useravatar"
def get_cache_key(self, size):
return "avatar:%s:%s" % (self.user_id, size)
from datetime import timedelta
from django.db import models
from django.utils import timezone
from sentry.utils.cache import cache
from sentry.db.models import BoundedPositiveIntegerField, FlexibleForeignKey, Model, sane_repr
class ReleaseEnvironment(Model):
__core__ = False
organization = FlexibleForeignKey("sentry.Organization", db_index=True, db_constraint=False)
# DEPRECATED
project_id = BoundedPositiveIntegerField(null=True)
release = FlexibleForeignKey("sentry.Release", db_index=True, db_constraint=False)
environment = FlexibleForeignKey("sentry.Environment", db_index=True, db_constraint=False)
first_seen = models.DateTimeField(default=timezone.now)
last_seen = models.DateTimeField(default=timezone.now, db_index=True)
class Meta:
app_label = "sentry"
db_table = "sentry_environmentrelease"
unique_together = (("organization", "release", "environment"),)
__repr__ = sane_repr("organization_id", "release_id", "environment_id")
@classmethod
def get_cache_key(cls, organization_id, release_id, environment_id):
return u"releaseenv:2:{}:{}:{}".format(organization_id, release_id, environment_id)
@classmethod
def get_or_create(cls, project, release, environment, datetime, **kwargs):
"""
return {"data": [{"time": time, "count": count} for time, count in self.values]}
class IncidentActivityType(Enum):
CREATED = 0
DETECTED = 1
STATUS_CHANGE = 2
COMMENT = 3
class IncidentActivity(Model):
__core__ = True
incident = FlexibleForeignKey("sentry.Incident")
user = FlexibleForeignKey("sentry.User", null=True)
type = models.IntegerField()
value = models.TextField(null=True)
previous_value = models.TextField(null=True)
comment = models.TextField(null=True)
event_stats_snapshot = FlexibleForeignKey("sentry.TimeSeriesSnapshot", null=True)
date_added = models.DateTimeField(default=timezone.now)
class Meta:
app_label = "sentry"
db_table = "sentry_incidentactivity"
class IncidentSubscription(Model):
__core__ = True
incident = FlexibleForeignKey("sentry.Incident", db_index=False)
class UserOption(Model):
"""
User options apply only to a user, and optionally a project OR an organization.
Options which are specific to a plugin should namespace
their key. e.g. key='myplugin:optname'
Keeping user feature state
key: "feature:assignment"
value: { updated: datetime, state: bool }
"""
__core__ = True
user = FlexibleForeignKey(settings.AUTH_USER_MODEL)
project = FlexibleForeignKey("sentry.Project", null=True)
organization = FlexibleForeignKey("sentry.Organization", null=True)
key = models.CharField(max_length=64)
value = EncryptedPickledObjectField()
objects = UserOptionManager()
class Meta:
app_label = "sentry"
db_table = "sentry_useroption"
unique_together = (("user", "project", "key"), ("user", "organization", "key"))
__repr__ = sane_repr("user_id", "project_id", "organization_id", "key", "value")