Exemplo n.º 1
0
def create_new_team_project(request, team):
    from sentry.web.forms.projects import NewProjectAdminForm, NewProjectForm

    if not can_create_projects(request.user, team):
        return missing_perm(request, Permissions.ADD_PROJECT, team=team)

    if request.user.is_superuser:
        form_cls = NewProjectAdminForm
        initial = {
            'owner': request.user.username,
        }
    else:
        form_cls = NewProjectForm
        initial = {}

    form = form_cls(request.POST or None, initial=initial)
    if form.is_valid():
        project = form.save(commit=False)
        project.team = team
        project.save()

        create_sample_event(project)

        if project.platform not in (None, 'other'):
            return HttpResponseRedirect(reverse('sentry-docs-client', args=[project.team.slug, project.slug, project.platform]))
        return HttpResponseRedirect(reverse('sentry-get-started', args=[project.team.slug, project.slug]))

    context = csrf(request)
    context.update({
        'form': form,
        'page': 'projects',
        'SUBSECTION': 'new_project',
    })

    return render_with_team_context(team, 'sentry/teams/projects/new.html', context, request)
Exemplo n.º 2
0
    def post(self, request, team):
        """
        Create a New Project
        ````````````````````

        Create a new project 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 create a new project
                                  for.
        :param string name: the name for the new project.
        :param string slug: optionally a slug for the new project.  If it's
                            not provided a slug is generated from the name.
        :auth: required
        """
        serializer = ProjectSerializer(data=request.DATA)

        if serializer.is_valid():
            result = serializer.object

            try:
                with transaction.atomic():
                    project = Project.objects.create(
                        name=result['name'],
                        slug=result.get('slug'),
                        organization=team.organization,
                        team=team,
                        platform=result.get('platform'))
            except IntegrityError:
                return Response(
                    {'detail': 'A project with this slug already exists.'},
                    status=409,
                )

            # XXX: create sample event?

            self.create_audit_entry(
                request=request,
                organization=team.organization,
                target_object=project.id,
                event=AuditLogEntryEvent.PROJECT_ADD,
                data=project.get_audit_log_data(),
            )

            project_created.send(project=project,
                                 user=request.user,
                                 sender=self)

            create_sample_event(project, platform='javascript')

            return Response(serialize(project, request.user), status=201)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 3
0
    def post(self, request, team):
        """
        Create a New Project
        ````````````````````

        Create a new project 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 create a new project
                                  for.
        :param string name: the name for the new project.
        :param string slug: optionally a slug for the new project.  If it's
                            not provided a slug is generated from the name.
        :auth: required
        """
        serializer = ProjectSerializer(data=request.DATA)

        if serializer.is_valid():
            result = serializer.object

            try:
                with transaction.atomic():
                    project = Project.objects.create(
                        name=result['name'],
                        slug=result.get('slug'),
                        organization=team.organization,
                        team=team,
                        platform=result.get('platform')
                    )
            except IntegrityError:
                return Response(
                    {'detail': 'A project with this slug already exists.'},
                    status=409,
                )

            # XXX: create sample event?

            self.create_audit_entry(
                request=request,
                organization=team.organization,
                target_object=project.id,
                event=AuditLogEntryEvent.PROJECT_ADD,
                data=project.get_audit_log_data(),
            )

            project_created.send(project=project, user=request.user, sender=self)

            create_sample_event(project, platform='javascript')

            return Response(serialize(project, request.user), status=201)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 4
0
    def handle(self, **options):
        from django.conf import settings

        from sentry.models import Project
        from sentry.utils.samples import create_sample_event

        if not options["project"]:
            project = Project.objects.get(id=settings.SENTRY_PROJECT)
        else:
            if options["project"].isdigit():
                project = Project.objects.get(id=options["project"])
            elif "/" in options["project"]:
                t_slug, p_slug = options["project"].split("/", 1)
                project = Project.objects.get(slug=p_slug, teams__slug=t_slug)
            else:
                raise CommandError(
                    "Project must be specified as team-slug/project-slug or a project id"
                )

        platform = options["platform"]
        event = create_sample_event(project, platform)
        if not event:
            raise CommandError(f"Unable to create an event for platform {platform!r}")

        self.stdout.write(f"Event created: {event.group.get_absolute_url()}")
Exemplo n.º 5
0
 def test_one_issue(self):
     event = create_sample_event(
         project=self.project,
         platform='python',
         event_id='d964fdbd649a4cf8bfc35d18082b6b0e',
         timestamp=1452683305,
     )
     event.group.update(
         first_seen=datetime(2018, 1, 12, 3, 8, 25, tzinfo=timezone.utc),
         last_seen=datetime(2018, 1, 13, 3, 8, 25, tzinfo=timezone.utc),
     )
     GroupAssignee.objects.create(
         user=self.user,
         group=event.group,
         project=self.project,
     )
     self.project.update(first_event=timezone.now())
     self.browser.get(self.path)
     # dashboard is a bit complex to load since it has many subcomponents
     # so we bank on the core container and the activity container being
     # enough of a check
     self.browser.wait_until('.organization-home')
     self.browser.wait_until('.dashboard-barchart')
     self.browser.wait_until_not('.loading-indicator')
     assert not self.browser.element_exists('.awaiting-events')
     self.browser.snapshot('org dash one issue')
Exemplo n.º 6
0
 def create_event(self, project, release, platform='python', raw=True):
     from sentry.utils.samples import create_sample_event
     event = create_sample_event(
         project=project, platform=platform, release=release.version, raw=raw
     )
     create_sample_time_series(event)
     return event
Exemplo n.º 7
0
 def create_event(self, project, release, platform='python', raw=True):
     from sentry.utils.samples import create_sample_event
     event = create_sample_event(
         project=project, platform=platform, release=release.version, raw=raw
     )
     create_sample_time_series(event)
     return event
Exemplo n.º 8
0
    def handle(self, **options):
        from django.conf import settings
        from sentry.constants import PLATFORM_LIST
        from sentry.models import Project
        from sentry.utils.samples import create_sample_event

        if not options['project']:
            project = Project.objects.get(id=settings.SENTRY_PROJECT)
        else:
            if options['project'].isdigit():
                project = Project.objects.get(id=options['project'])
            elif '/' in options['project']:
                t_slug, p_slug = options['project'].split('/', 1)
                project = Project.objects.get(slug=p_slug, team__slug=t_slug)
            else:
                raise CommandError('Project must be specified as team-slug/project-slug or a project id')

        if options['platform'] not in PLATFORM_LIST:
            raise CommandError('Invalid platform. Must specify one of: %s' % ', '.join(PLATFORM_LIST))

        platform = options['platform'] or project.platform
        event = create_sample_event(project, platform)
        if not event:
            raise CommandError('Unable to create an event for platform %r' % (str(platform),))

        self.stdout.write('Event created: %s' % (event.group.get_absolute_url(),))
Exemplo n.º 9
0
 def test_one_issue(self):
     event = create_sample_event(
         project=self.project,
         platform='python',
         event_id='d964fdbd649a4cf8bfc35d18082b6b0e',
         timestamp=1452683305,
     )
     event.group.update(
         first_seen=datetime(2018, 1, 12, 3, 8, 25, tzinfo=timezone.utc),
         last_seen=datetime(2018, 1, 13, 3, 8, 25, tzinfo=timezone.utc),
     )
     GroupAssignee.objects.create(
         user=self.user,
         group=event.group,
         project=self.project,
     )
     OrganizationOnboardingTask.objects.create_or_update(
         organization_id=self.project.organization_id,
         task=OnboardingTask.FIRST_EVENT,
         status=OnboardingTaskStatus.COMPLETE,
     )
     self.project.update(first_event=timezone.now())
     self.browser.get(self.path)
     self.browser.wait_until_not('.loading-indicator')
     self.browser.wait_until('[data-test-id] figure')
     self.browser.snapshot('org dash one issue')
Exemplo n.º 10
0
 def test_one_issue(self):
     event = create_sample_event(
         project=self.project,
         platform='python',
         event_id='d964fdbd649a4cf8bfc35d18082b6b0e',
         timestamp=1452683305,
     )
     event.group.update(
         first_seen=datetime(2018, 1, 12, 3, 8, 25, tzinfo=timezone.utc),
         last_seen=datetime(2018, 1, 13, 3, 8, 25, tzinfo=timezone.utc),
     )
     GroupAssignee.objects.create(
         user=self.user,
         group=event.group,
         project=self.project,
     )
     OrganizationOnboardingTask.objects.create_or_update(
         organization_id=self.project.organization_id,
         task=OnboardingTask.FIRST_EVENT,
         status=OnboardingTaskStatus.COMPLETE,
     )
     self.project.update(first_event=timezone.now())
     self.browser.get(self.path)
     self.browser.wait_until_not('.loading-indicator')
     self.browser.wait_until('[data-test-id] figure')
     self.browser.snapshot('org dash one issue')
Exemplo n.º 11
0
    def handle(self, **options):
        from django.conf import settings
        from sentry.models import Project
        from sentry.utils.samples import create_sample_event

        if not options['project']:
            project = Project.objects.get(id=settings.SENTRY_PROJECT)
        else:
            if options['project'].isdigit():
                project = Project.objects.get(id=options['project'])
            elif '/' in options['project']:
                t_slug, p_slug = options['project'].split('/', 1)
                project = Project.objects.get(slug=p_slug, team__slug=t_slug)
            else:
                raise CommandError(
                    'Project must be specified as team-slug/project-slug or a project id'
                )

        platform = options['platform']
        event = create_sample_event(project, platform)
        if not event:
            raise CommandError('Unable to create an event for platform %r' %
                               (platform, ))

        self.stdout.write('Event created: %s' %
                          (event.group.get_absolute_url(), ))
Exemplo n.º 12
0
 def test_one_issue(self):
     event = create_sample_event(
         project=self.project,
         platform='python',
         event_id='d964fdbd649a4cf8bfc35d18082b6b0e',
         timestamp=1452683305,
     )
     event.group.update(
         first_seen=datetime(2018, 1, 12, 3, 8, 25, tzinfo=timezone.utc),
         last_seen=datetime(2018, 1, 13, 3, 8, 25, tzinfo=timezone.utc),
     )
     GroupAssignee.objects.create(
         user=self.user,
         group=event.group,
         project=self.project,
     )
     self.project.update(first_event=timezone.now())
     self.browser.get(self.path)
     # dashboard is a bit complex to load since it has many subcomponents
     # so we bank on the core container and the activity container being
     # enough of a check
     self.browser.wait_until('.organization-home')
     self.browser.wait_until('.dashboard-barchart')
     self.browser.wait_until_not('.loading-indicator')
     assert not self.browser.element_exists('.awaiting-events')
     self.browser.snapshot('org dash one issue')
Exemplo n.º 13
0
 def test_configuration(self, project):
     from sentry.utils.samples import create_sample_event
     event = create_sample_event(project, default='python')
     return self.post_process(event.group,
                              event,
                              is_new=True,
                              is_sample=False)
    def get(self, request):
        org = Organization(id=1, slug="organization", name="My Company")
        project = Project(id=1, organization=org, slug="project", name="My Project")

        event = create_sample_event(
            project=project, platform="python", event_id="595", timestamp=1452683305
        )

        group = event.group
        link = absolute_uri(
            f"/{project.organization.slug}/{project.slug}/issues/{group.id}/feedback/"
        )

        return MailPreview(
            html_template="sentry/emails/activity/new-user-feedback.html",
            text_template="sentry/emails/activity/new-user-feedback.txt",
            context={
                "group": group,
                "report": {
                    "name": "Homer Simpson",
                    "email": "*****@*****.**",
                    "comments": "I hit a bug.\n\nI went to https://example.com, hit the any key, and then it stopped working. DOH!",
                },
                "link": link,
                "reason": "are subscribed to this issue",
                "enhanced_privacy": False,
            },
        ).render(request)
Exemplo n.º 15
0
    def post(self, request, project):
        event = create_sample_event(
            project, platform=project.platform, default='javascript',
        )

        data = serialize(event, request.user)

        return Response(data)
Exemplo n.º 16
0
    def post(self, request, project):
        event = create_sample_event(project,
                                    platform=project.platform,
                                    default="javascript")

        data = serialize(event, request.user)

        return Response(data)
Exemplo n.º 17
0
    def save(self, actor, team, ip_address):
        project = super(AddProjectForm, self).save(commit=False)
        project.team = team
        project.organization = team.organization
        project.save()

        AuditLogEntry.objects.create(
            organization=project.organization,
            actor=actor,
            ip_address=ip_address,
            target_object=project.id,
            event=AuditLogEntryEvent.PROJECT_ADD,
            data=project.get_audit_log_data(),
        )

        create_sample_event(project, platform='javascript')

        return project
Exemplo n.º 18
0
    def save(self, actor, team, ip_address):
        project = super(AddProjectForm, self).save(commit=False)
        project.team = team
        project.organization = team.organization
        project.save()

        AuditLogEntry.objects.create(
            organization=project.organization,
            actor=actor,
            ip_address=ip_address,
            target_object=project.id,
            event=AuditLogEntryEvent.PROJECT_ADD,
            data=project.get_audit_log_data(),
        )

        create_sample_event(project, platform='javascript')

        return project
Exemplo n.º 19
0
    def post(self, request, project):
        event = create_sample_event(project,
                                    platform=project.platform,
                                    default="javascript")
        add_group_to_inbox(event.group, GroupInboxReason.NEW)

        data = serialize(event, request.user)

        return Response(data)
Exemplo n.º 20
0
def create_new_team_project(request, team):
    from sentry.web.forms.projects import NewProjectAdminForm, NewProjectForm

    if not can_create_projects(request.user, team):
        return missing_perm(request, Permissions.ADD_PROJECT, team=team)

    if request.user.has_perm('sentry.can_add_project'):
        form_cls = NewProjectAdminForm
        initial = {
            'owner': request.user.username,
        }
    else:
        form_cls = NewProjectForm
        initial = {}

    form = form_cls(request.POST or None, initial=initial)
    if form.is_valid():
        project = form.save(commit=False)
        project.team = team
        if not project.owner:
            project.owner = request.user
        project.save()

        create_sample_event(project)

        if project.platform not in (None, 'other'):
            return HttpResponseRedirect(
                reverse(
                    'sentry-docs-client',
                    args=[project.team.slug, project.slug, project.platform]))
        return HttpResponseRedirect(
            reverse('sentry-get-started',
                    args=[project.team.slug, project.slug]))

    context = csrf(request)
    context.update({
        'form': form,
        'page': 'projects',
        'SUBSECTION': 'new_project',
    })

    return render_with_team_context(team, 'sentry/teams/projects/new.html',
                                    context, request)
Exemplo n.º 21
0
 def create_sample_event(self, platform):
     event = create_sample_event(
         project=self.project,
         platform=platform,
         event_id='d964fdbd649a4cf8bfc35d18082b6b0e',
         timestamp=1452683305,
     )
     event.group.update(
         first_seen=datetime(2015, 8, 13, 3, 8, 25, tzinfo=timezone.utc),
         last_seen=datetime(2016, 1, 13, 3, 8, 25, tzinfo=timezone.utc),
     )
     return event
Exemplo n.º 22
0
 def create_sample_event(self, platform, default=None, sample_name=None):
     event = create_sample_event(
         project=self.project,
         platform=platform,
         default=default,
         sample_name=sample_name,
         event_id='d964fdbd649a4cf8bfc35d18082b6b0e')
     event.group.update(
         first_seen=datetime(2015, 8, 13, 3, 8, 25, tzinfo=timezone.utc),
         last_seen=datetime(2016, 1, 13, 3, 8, 25, tzinfo=timezone.utc),
     )
     return event
Exemplo n.º 23
0
 def create_sample_event(self, platform):
     event = create_sample_event(
         project=self.project,
         platform=platform,
         event_id='d964fdbd649a4cf8bfc35d18082b6b0e',
         timestamp=1452683305,
     )
     event.group.update(
         first_seen=datetime(2015, 8, 13, 3, 8, 25, tzinfo=timezone.utc),
         last_seen=datetime(2016, 1, 13, 3, 8, 25, tzinfo=timezone.utc),
     )
     return event
Exemplo n.º 24
0
 def gen_event(self, browser_name):
     return create_sample_event(
         project=self.project,
         platform="python",
         contexts={
             "browser": {
                 "name": browser_name
             },
             "client_os": {
                 "name": ""
             }
         },
     )
Exemplo n.º 25
0
 def create_sample_event(self, platform, default=None, sample_name=None):
     event = create_sample_event(
         project=self.project,
         platform=platform,
         default=default,
         sample_name=sample_name,
         event_id='d964fdbd649a4cf8bfc35d18082b6b0e'
     )
     event.group.update(
         first_seen=datetime(2015, 8, 13, 3, 8, 25, tzinfo=timezone.utc),
         last_seen=datetime(2016, 1, 13, 3, 8, 25, tzinfo=timezone.utc),
     )
     return event
Exemplo n.º 26
0
 def send_notification_helper(self):
     self.initialized_plugin.set_option('receivers', '123', self.project)
     self.initialized_plugin.set_option('api_token', 'api:token', self.project)
     self.initialized_plugin.set_option(
         'message_template',
         '*[Sentry]* {project_name} {tag[level]}: {title}\n{message}\n{url}',
         self.project,
     )
     event = create_sample_event(self.project, platform='python')
     notification = Notification(event=event)
     with patch('requests.sessions.Session.request') as request:
         self.initialized_plugin.notify(notification)
         return request
Exemplo n.º 27
0
def populate_event_on_project(project: Project, file_path: str,
                              dist_function: Callable[[int], int]) -> None:
    with open(file_path) as f:
        error_json = json.load(f)

    # clear out these fields if they exist
    fields_to_delete = ["datetime", "location", "title", "event_id", "project"]
    for field in fields_to_delete:
        if field in error_json:
            del error_json[field]

    for day in range(MAX_DAYS):
        for hour in range(24):
            base = dist_function(hour)
            # determine the number of events we want in this hour
            num_events = int(
                (BASE_OFFSET + SCALE_FACTOR * base) * random.uniform(0.6, 1.0))
            for i in range(num_events):
                # pick the minutes randomly (which means events will received be out of order)
                minute = random.randint(0, 60)
                timestamp = timezone.now() - timedelta(
                    days=day, hours=hour, minutes=minute)
                local_error = error_json.copy()
                local_error.update(
                    project=project,
                    platform=project.platform,
                    timestamp=timestamp,
                    user=generate_user(),
                )
                # snuba might fail but what can we do ¯\_(ツ)_/¯
                # TODO: make a batched update version of create_sample_event
                try:
                    create_sample_event(**local_error, )
                except SnubaError:
                    logger.info("populate_event_on_project.snuba_error")
                    pass
    def get(self, request):
        org = Organization(
            id=1,
            slug='organization',
            name='My Company',
        )
        project = Project(
            id=1,
            organization=org,
            slug='project',
            name='My Project',
        )

        event = create_sample_event(
            project=project,
            platform='python',
            event_id='595',
            timestamp=1452683305,
        )

        group = event.group
        link = absolute_uri(u'/{}/{}/issues/{}/feedback/'.format(
            project.organization.slug,
            project.slug,
            group.id,
        ))

        return MailPreview(
            html_template='sentry/emails/activity/new-user-feedback.html',
            text_template='sentry/emails/activity/new-user-feedback.txt',
            context={
                'group': group,
                'report': {
                    'name':
                    'Homer Simpson',
                    'email':
                    '*****@*****.**',
                    'comments':
                    'I hit a bug.\n\nI went to https://example.com, hit the any key, and then it stopped working. DOH!',
                },
                'link': link,
                'reason': 'are subscribed to this issue',
                'enhanced_privacy': False,
            },
        ).render(request)
Exemplo n.º 29
0
 def test_complex_send_notification(self):
     self.initialized_plugin.set_option('receivers', '123', self.project)
     self.initialized_plugin.set_option('api_token', 'api:token', self.project)
     event = create_sample_event(self.project, platform='python')
     notification = Notification(event=event)
     with patch('requests.sessions.Session.request') as request:
         self.initialized_plugin.notify(notification)
         assert request.call_args_list == [
             call(
                 allow_redirects=False,
                 method='POST',
                 headers={'Content-Type': 'application/json'},
                 url=u'https://api.telegram.org/botapi:token/sendMessage',
                 json={'text': '*[Sentry]* Bar error\nhttp://testserver/baz/bar/issues/1/', 'parse_mode': 'Markdown', 'chat_id': '123'},
                 timeout=30,
                 verify=True,
             ),
         ]
Exemplo n.º 30
0
    def get(self, request):
        org = Organization(
            id=1,
            slug='organization',
            name='My Company',
        )
        project = Project(
            id=1,
            organization=org,
            slug='project',
            name='My Project',
        )

        event = create_sample_event(
            project=project,
            platform='python',
            event_id='595',
            timestamp=1452683305,
        )

        group = event.group
        link = absolute_uri(u'/{}/{}/issues/{}/feedback/'.format(
            project.organization.slug,
            project.slug,
            group.id,
        ))

        return MailPreview(
            html_template='sentry/emails/activity/new-user-feedback.html',
            text_template='sentry/emails/activity/new-user-feedback.txt',
            context={
                'group': group,
                'report': {
                    'name': 'Homer Simpson',
                    'email': '*****@*****.**',
                    'comments': 'I hit a bug.\n\nI went to https://example.com, hit the any key, and then it stopped working. DOH!',
                },
                'link': link,
                'reason': 'are subscribed to this issue',
                'enhanced_privacy': False,
            },
        ).render(request)
Exemplo n.º 31
0
 def test_one_issue(self):
     event = create_sample_event(
         project=self.project,
         platform='python',
         event_id='d964fdbd649a4cf8bfc35d18082b6b0e',
         timestamp=1452683305,
     )
     event.group.update(
         first_seen=datetime(2018, 1, 12, 3, 8, 25, tzinfo=timezone.utc),
         last_seen=datetime(2018, 1, 13, 3, 8, 25, tzinfo=timezone.utc),
     )
     GroupAssignee.objects.create(
         user=self.user,
         group=event.group,
         project=self.project,
     )
     self.project.update(first_event=timezone.now())
     self.browser.get(self.path)
     self.browser.wait_until_not('.loading-indicator')
     self.browser.snapshot('org dash one issue')
Exemplo n.º 32
0
 def test_configuration(self, project):
     from sentry.utils.samples import create_sample_event
     event = create_sample_event(project, default='python')
     return self.notify_users(event.group, event, fail_silently=False)
Exemplo n.º 33
0
 def test_configuration(self, project):
     from sentry.utils.samples import create_sample_event
     event = create_sample_event(project, default='python')
     return self.notify_users(event.group, event, fail_silently=False)
Exemplo n.º 34
0
def populate_python_project(project):
    create_sample_event(
        project=project,
        platform="python",
        user=generate_user(),
    )
Exemplo n.º 35
0
def populate_react_project(project):
    create_sample_event(
        project=project,
        platform="javascript-react",
        user=generate_user(),
    )
Exemplo n.º 36
0
 def test_configuration(self, project):
     from sentry.utils.samples import create_sample_event
     event = create_sample_event(project, platform='python')
     notification = Notification(event=event)
     return self.notify(notification)
Exemplo n.º 37
0
 def test_configuration(self, project):
     from sentry.utils.samples import create_sample_event
     event = create_sample_event(project, platform='python')
     notification = Notification(event=event)
     return self.notify(notification)
Exemplo n.º 38
0
 def test_configuration(self, project):
     from sentry.utils.samples import create_sample_event
     event = create_sample_event(project, default='python')
     return self.post_process(event.group, event, is_new=True, is_sample=False)