Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
url = reverse('sentry-api-0-project-details', kwargs={
'organization_slug': project.organization.slug,
'project_slug': project.slug,
})
options = {
'sentry:origins': 'foo\nbar',
'sentry:resolve_age': 1,
'sentry:scrub_data': False,
'sentry:scrub_defaults': False,
'sentry:sensitive_fields': ['foo', 'bar']
}
resp = self.client.put(url, data={
'options': options
})
assert resp.status_code == 200, resp.content
project = Project.objects.get(id=project.id)
assert project.get_option('sentry:origins', []) == options['sentry:origins'].split('\n')
assert project.get_option('sentry:resolve_age', 0) == options['sentry:resolve_age']
assert project.get_option('sentry:scrub_data', True) == options['sentry:scrub_data']
assert project.get_option('sentry:scrub_defaults', True) == options['sentry:scrub_defaults']
assert project.get_option('sentry:sensitive_fields', []) == options['sentry:sensitive_fields']
def test_simple(self):
user, _ = User.objects.get_or_create(is_superuser=True, defaults={"username": "test"})
Organization.objects.all().delete()
Team.objects.filter(slug="sentry").delete()
Project.objects.filter(id=settings.SENTRY_PROJECT).delete()
config = apps.get_app_config("sentry")
create_default_projects(config)
project = Project.objects.get(id=settings.SENTRY_PROJECT)
assert project.public is False
assert project.name == "Internal"
assert project.slug == "internal"
team = project.teams.first()
assert team.slug == "sentry"
pk = ProjectKey.objects.get(project=project)
assert not pk.roles.api
assert pk.roles.store
# ensure that we dont hit an error here
create_default_projects(config)
def project_ids(self):
from sentry.models import Project
if not self.user_id:
return []
return list(Project.objects.filter(
team__in=self.team_ids,
).values_list('id', flat=True))
ReleaseProject,
ReleaseProjectEnvironment,
)
try:
with transaction.atomic():
self.update(organization=organization)
except IntegrityError:
# likely this means a team already exists, let's try to coerce to
# it instead of a blind transfer
new_team = Team.objects.get(organization=organization, slug=self.slug)
else:
new_team = self
project_ids = list(
Project.objects.filter(teams=self)
.exclude(organization=organization)
.values_list("id", flat=True)
)
# remove associations with releases from other org
ReleaseProject.objects.filter(project_id__in=project_ids).delete()
ReleaseProjectEnvironment.objects.filter(project_id__in=project_ids).delete()
Project.objects.filter(id__in=project_ids).update(organization=organization)
ProjectTeam.objects.filter(project_id__in=project_ids).update(team=new_team)
# remove any pending access requests from the old organization
if self != new_team:
OrganizationAccessRequest.objects.filter(team=self).delete()
)
.update(
next_checkin=self.get_next_scheduled_checkin(next_checkin_base),
status=MonitorStatus.ERROR,
last_checkin=last_checkin,
)
)
if not affected:
return False
event_manager = EventManager(
{
"logentry": {"message": "Monitor failure: %s" % (self.name,)},
"contexts": {"monitor": {"id": six.text_type(self.guid)}},
},
project=Project(id=self.project_id),
)
event_manager.normalize()
data = event_manager.get_data()
helper = ClientApiHelper(project_id=self.project_id)
helper.insert_data_to_database(data)
monitor_failed.send(monitor=self, sender=type(self))
return True
from sentry.event_manager import EventManager
from sentry.models import Project
helper = ClientApiHelper(
agent='raven-python/%s (sentry %s)' % (raven.VERSION, sentry.VERSION),
project_id=settings.SENTRY_PROJECT,
version=self.protocol_version,
)
try:
project = Project.objects.get_from_cache(id=settings.SENTRY_PROJECT)
except DatabaseError:
self.error_logger.error('Unable to fetch internal project',
exc_info=True)
return
except Project.DoesNotExist:
self.error_logger.error('Internal project (id=%s) does not exist',
settings.SENTRY_PROJECT)
return
helper.context.bind_project(project)
metrics.incr('events.total')
kwargs['project'] = project.id
try:
manager = EventManager(kwargs)
data = manager.normalize()
tsdb.incr_multi([
(tsdb.models.project_total_received, project.id),
(tsdb.models.organization_total_received, project.organization_id),
])
def get(self, request, team):
"""
List a Team's Projects
``````````````````````
Return a list of projects bound to a team.
:pparam string organization_slug: the slug of the organization the
team belongs to.
:pparam string team_slug: the slug of the team to list the projects of.
:auth: required
"""
if request.auth and hasattr(request.auth, "project"):
queryset = Project.objects.filter(id=request.auth.project.id)
else:
queryset = Project.objects.filter(teams=team, status=ProjectStatus.VISIBLE)
stats_period = request.GET.get("statsPeriod")
if stats_period not in (None, "", "24h", "14d", "30d"):
return Response(
{"error": {"params": {"stats_period": {"message": ERR_INVALID_STATS_PERIOD}}}},
status=400,
)
elif not stats_period:
# disable stats
stats_period = None
return self.paginate(
request=request,
queryset=queryset,
order_by="slug",
on_results=lambda x: serialize(
def clean_project(self):
project_id = self.cleaned_data['project']
return Project.objects.get_from_cache(id=project_id)
to_timestamp(datetime(2015, 6, 1, 0, 0, 0, tzinfo=timezone.utc)),
to_timestamp(datetime(2016, 7, 1, 0, 0, 0, tzinfo=timezone.utc)),
)
)
)
)
start, stop = interval = reports._to_interval(timestamp, duration)
organization = Organization(id=1, slug="example", name="Example")
projects = []
for i in xrange(0, random.randint(1, 8)):
name = " ".join(random.sample(loremipsum.words, random.randint(1, 4)))
projects.append(
Project(
id=i,
organization=organization,
slug=slugify(name),
name=name,
date_added=start - timedelta(days=random.randint(0, 120)),
)
)
def make_release_generator():
id_sequence = itertools.count(1)
while True:
dt = to_datetime(random.randint(timestamp - (30 * 24 * 60 * 60), timestamp))
p = random.choice(projects)
yield Release(
id=next(id_sequence),
project=p,
def get(self, request, team):
"""
List a Team's Projects
``````````````````````
Return a list of projects bound to a team.
:pparam string organization_slug: the slug of the organization the
team belongs to.
:pparam string team_slug: the slug of the team to list the projects of.
:auth: required
"""
if request.auth and hasattr(request.auth, "project"):
queryset = Project.objects.filter(id=request.auth.project.id)
else:
queryset = Project.objects.filter(teams=team, status=ProjectStatus.VISIBLE)
stats_period = request.GET.get("statsPeriod")
if stats_period not in (None, "", "24h", "14d", "30d"):
return Response(
{"error": {"params": {"stats_period": {"message": ERR_INVALID_STATS_PERIOD}}}},
status=400,
)
elif not stats_period:
# disable stats
stats_period = None
return self.paginate(
request=request,
queryset=queryset,