Exemplo n.º 1
0
def manage_project_keys(request, organization, project):
    result = plugins.first('has_perm', request.user, 'edit_project', project)
    if result is False and not request.user.is_superuser:
        return HttpResponseRedirect(reverse('sentry'))

    key_list = list(ProjectKey.objects.filter(
        project=project,
    ).select_related('user_added').order_by('-id'))

    for key in key_list:
        key.project = project
        key.can_remove = can_remove_project_key(request.user, key),
        key.can_edit = can_edit_project_key(request.user, key),

    context = csrf(request)
    context.update({
        'team': project.team,
        'organization': organization,
        'page': 'keys',
        'project': project,
        'key_list': key_list,
        'can_add_key': can_add_project_key(request.user, project),
    })

    return render_to_response('sentry/projects/keys.html', context, request)
Exemplo n.º 2
0
def enable_project_key(request, organization, project, key_id):
    try:
        key = ProjectKey.objects.get(id=key_id)
    except ProjectKey.DoesNotExist:
        return HttpResponseRedirect(
            reverse('sentry-manage-project-keys',
                    args=[project.organization.slug, project.slug]))

    # we require removal permission for this
    if not can_edit_project_key(request.user, key):
        return HttpResponseRedirect(
            reverse('sentry-manage-project-keys',
                    args=[project.organization.slug, project.slug]))

    key.update(status=ProjectKeyStatus.ACTIVE)

    AuditLogEntry.objects.create(
        organization=organization,
        actor=request.user,
        ip_address=request.META['REMOTE_ADDR'],
        target_object=key.id,
        event=AuditLogEntryEvent.PROJECTKEY_ENABLE,
        data=key.get_audit_log_data(),
    )

    messages.add_message(
        request, messages.SUCCESS,
        _('The API key (%s) was enabled.') % (key.public_key, ))

    return HttpResponseRedirect(
        reverse('sentry-manage-project-keys',
                args=[project.organization.slug, project.slug]))
Exemplo n.º 3
0
def enable_project_key(request, organization, project, key_id):
    try:
        key = ProjectKey.objects.get(id=key_id)
    except ProjectKey.DoesNotExist:
        return HttpResponseRedirect(reverse('sentry-manage-project-keys', args=[project.organization.slug, project.slug]))

    # we require removal permission for this
    if not can_edit_project_key(request.user, key):
        return HttpResponseRedirect(reverse('sentry-manage-project-keys', args=[project.organization.slug, project.slug]))

    key.update(status=ProjectKeyStatus.ACTIVE)

    AuditLogEntry.objects.create(
        organization=organization,
        actor=request.user,
        ip_address=request.META['REMOTE_ADDR'],
        target_object=key.id,
        event=AuditLogEntryEvent.PROJECTKEY_ENABLE,
        data=key.get_audit_log_data(),
    )

    messages.add_message(
        request, messages.SUCCESS,
        _('The API key (%s) was enabled.') % (key.public_key,))

    return HttpResponseRedirect(reverse('sentry-manage-project-keys', args=[project.organization.slug, project.slug]))
Exemplo n.º 4
0
def edit_project_key(request, team, project, key_id):
    if not can_edit_project_key(request.user, project):
        return HttpResponseRedirect(reverse('sentry-manage-project-keys', args=[project.team.slug, project.slug]))

    try:
        key = ProjectKey.objects.get(
            id=key_id,
            project=project,
        )
    except ProjectKey.DoesNotExist():
        return HttpResponseRedirect(reverse('sentry-manage-project-keys', args=[project.team.slug, project.slug]))

    form = EditProjectKeyForm(request.POST or None, instance=key)
    if form.is_valid():
        form.save()

        messages.add_message(
            request, messages.SUCCESS, _('Changes to your API key were saved.'))
        return HttpResponseRedirect(reverse('sentry-manage-project-keys', args=[project.team.slug, project.slug]))

    context = {
        'team': team,
        'project': project,
        'page': 'keys',
        'key': key,
        'form': form,
    }

    return render_to_response('sentry/projects/edit_key.html', context, request)
Exemplo n.º 5
0
def manage_project_keys(request, organization, project):
    result = plugins.first('has_perm', request.user, 'edit_project', project)
    if result is False and not request.user.is_superuser:
        return HttpResponseRedirect(reverse('sentry'))

    key_list = list(
        ProjectKey.objects.filter(project=project, ).select_related(
            'user', 'user_added').order_by('-id'))

    for key in key_list:
        key.project = project
        key.can_remove = can_remove_project_key(request.user, key),
        key.can_edit = can_edit_project_key(request.user, key),

    context = csrf(request)
    context.update({
        'team': project.team,
        'organization': organization,
        'page': 'keys',
        'project': project,
        'key_list': key_list,
        'can_add_key': can_add_project_key(request.user, project),
    })

    return render_to_response('sentry/projects/keys.html', context, request)
Exemplo n.º 6
0
def manage_project_keys(request, organization, project):
    result = plugins.first("has_perm", request.user, "edit_project", project)
    if result is False and not request.user.is_superuser:
        return HttpResponseRedirect(reverse("sentry"))

    key_list = list(ProjectKey.objects.filter(project=project).order_by("-id"))

    for key in key_list:
        key.project = project
        key.can_remove = (can_remove_project_key(request.user, key),)
        key.can_edit = (can_edit_project_key(request.user, key),)

    context = csrf(request)
    context.update(
        {
            "team": project.team,
            "organization": organization,
            "page": "keys",
            "project": project,
            "key_list": key_list,
            "can_add_key": can_add_project_key(request.user, project),
        }
    )

    return render_to_response("sentry/projects/keys.html", context, request)
Exemplo n.º 7
0
def edit_project_key(request, organization, project, key_id):
    try:
        key = ProjectKey.objects.get(
            id=key_id,
            project=project,
        )
    except ProjectKey.DoesNotExist():
        return HttpResponseRedirect(
            reverse('sentry-manage-project-keys',
                    args=[project.organization.slug, project.slug]))

    if not can_edit_project_key(request.user, key):
        return HttpResponseRedirect(
            reverse('sentry-manage-project-keys',
                    args=[project.organization.slug, project.slug]))

    form = EditProjectKeyForm(request.POST or None, instance=key)
    if form.is_valid():
        key = form.save()

        AuditLogEntry.objects.create(
            organization=organization,
            actor=request.user,
            ip_address=request.META['REMOTE_ADDR'],
            target_object=key.id,
            event=AuditLogEntryEvent.PROJECTKEY_EDIT,
            data=key.get_audit_log_data(),
        )

        messages.add_message(
            request, messages.SUCCESS,
            _('Changes to the API key (%s) were saved.') % (key.public_key, ))
        return HttpResponseRedirect(
            reverse('sentry-manage-project-keys',
                    args=[project.organization.slug, project.slug]))

    context = {
        'organization': organization,
        'team': project.team,
        'project': project,
        'page': 'keys',
        'key': key,
        'form': form,
    }

    return render_to_response('sentry/projects/edit_key.html', context,
                              request)
Exemplo n.º 8
0
def edit_project_key(request, organization, project, key_id):
    try:
        key = ProjectKey.objects.get(id=key_id, project=project)
    except ProjectKey.DoesNotExist():
        return HttpResponseRedirect(
            reverse("sentry-manage-project-keys", args=[project.organization.slug, project.slug])
        )

    if not can_edit_project_key(request.user, key):
        return HttpResponseRedirect(
            reverse("sentry-manage-project-keys", args=[project.organization.slug, project.slug])
        )

    form = EditProjectKeyForm(request.POST or None, instance=key)
    if form.is_valid():
        key = form.save()

        AuditLogEntry.objects.create(
            organization=organization,
            actor=request.user,
            ip_address=request.META["REMOTE_ADDR"],
            target_object=key.id,
            event=AuditLogEntryEvent.PROJECTKEY_EDIT,
            data=key.get_audit_log_data(),
        )

        messages.add_message(
            request, messages.SUCCESS, _("Changes to the API key (%s) were saved.") % (key.public_key,)
        )
        return HttpResponseRedirect(
            reverse("sentry-manage-project-keys", args=[project.organization.slug, project.slug])
        )

    context = {
        "organization": organization,
        "team": project.team,
        "project": project,
        "page": "keys",
        "key": key,
        "form": form,
    }

    return render_to_response("sentry/projects/edit_key.html", context, request)
Exemplo n.º 9
0
def manage_project_keys(request, organization, project):
    key_list = list(
        ProjectKey.objects.filter(project=project, ).order_by('-id'))

    for key in key_list:
        key.project = project
        key.can_remove = can_remove_project_key(request.user, key),
        key.can_edit = can_edit_project_key(request.user, key),

    context = csrf(request)
    context.update({
        'team': project.team,
        'organization': organization,
        'page': 'keys',
        'project': project,
        'key_list': key_list,
        'can_add_key': can_add_project_key(request.user, project),
    })

    return render_to_response('sentry/projects/keys.html', context, request)
Exemplo n.º 10
0
def manage_project_keys(request, organization, project):
    key_list = list(ProjectKey.objects.filter(project=project).order_by("-id"))

    for key in key_list:
        key.project = project
        key.can_remove = (can_remove_project_key(request.user, key),)
        key.can_edit = (can_edit_project_key(request.user, key),)

    context = csrf(request)
    context.update(
        {
            "team": project.team,
            "organization": organization,
            "page": "keys",
            "project": project,
            "key_list": key_list,
            "can_add_key": can_add_project_key(request.user, project),
        }
    )

    return render_to_response("sentry/projects/keys.html", context, request)
Exemplo n.º 11
0
def edit_project_key(request, organization, project, key_id):
    if not can_edit_project_key(request.user, project):
        return HttpResponseRedirect(
            reverse('sentry-manage-project-keys',
                    args=[project.organization.slug, project.slug]))

    try:
        key = ProjectKey.objects.get(
            id=key_id,
            project=project,
        )
    except ProjectKey.DoesNotExist():
        return HttpResponseRedirect(
            reverse('sentry-manage-project-keys',
                    args=[project.organization.slug, project.slug]))

    form = EditProjectKeyForm(request.POST or None, instance=key)
    if form.is_valid():
        form.save()

        messages.add_message(request, messages.SUCCESS,
                             _('Changes to your API key were saved.'))
        return HttpResponseRedirect(
            reverse('sentry-manage-project-keys',
                    args=[project.organization.slug, project.slug]))

    context = {
        'organization': organization,
        'team': project.team,
        'project': project,
        'page': 'keys',
        'key': key,
        'form': form,
    }

    return render_to_response('sentry/projects/edit_key.html', context,
                              request)