def handle(self, request, organization, team, project, key_id): try: key = ProjectKey.objects.get( id=key_id, project=project, ) except ProjectKey.DoesNotExist(): return self.redirect( reverse('sentry-manage-project-keys', args=[project.organization.slug, project.slug])) data = key.get_audit_log_data() key.delete() AuditLogEntry.objects.create( organization=organization, actor=request.user, ip_address=request.META['REMOTE_ADDR'], target_object=key.id, event=AuditLogEntryEvent.PROJECTKEY_REMOVE, data=data, ) messages.add_message( request, messages.SUCCESS, _('The API key (%s) was revoked.') % (key.public_key, )) return self.redirect( reverse('sentry-manage-project-keys', args=[project.organization.slug, project.slug]))
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)
def handle(self, request, organization, team, project, key_id): try: key = ProjectKey.objects.get( id=key_id, project=project, ) except ProjectKey.DoesNotExist(): return self.redirect( 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() self.create_audit_entry( request, organization=organization, 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 self.redirect( reverse('sentry-manage-project-keys', args=[project.organization.slug, project.slug])) context = { 'page': 'keys', 'key': key, 'form': form, } return self.respond('sentry/projects/edit_key.html', context)
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)