def manage_project(request, project): result = plugins.first('has_perm', request.user, 'edit_project', project) if result is False and not request.user.has_perm('sentry.can_change_project'): return HttpResponseRedirect(reverse('sentry')) # XXX: We probably shouldnt allow changing the team unless they're the project owner team_list = Team.objects.get_for_user(project.owner or request.user, MEMBER_OWNER) if request.user.has_perm('sentry.can_change_project'): form_cls = EditProjectAdminForm else: form_cls = EditProjectForm form = form_cls(request, team_list, request.POST or None, instance=project, initial={ 'origins': '\n'.join(get_option('sentry:origins', project) or []), 'owner': project.owner, }) if form.is_valid(): project = form.save() set_option('sentry:origins', form.cleaned_data.get('origins') or [], project) return HttpResponseRedirect(request.path + '?success=1') context = csrf(request) context.update({ 'can_remove_project': can_remove_project(request.user, project), 'page': 'details', 'form': form, 'project': project, 'TEAM_LIST': team_list.values(), 'SECTION': 'settings', }) return render_to_response('sentry/projects/manage.html', context, request)
def post(self, request, organization, team, project): if not can_remove_project(request.user, project): return HttpResponseRedirect(reverse('sentry')) form = self.get_form(request) if form.is_valid(): if project.status != STATUS_HIDDEN: project.update(status=STATUS_HIDDEN) delete_project.delay(object_id=project.id) AuditLogEntry.objects.create( organization=organization, actor=request.user, ip_address=request.META['REMOTE_ADDR'], target_object=project.id, event=AuditLogEntryEvent.PROJECT_REMOVE, data=project.get_audit_log_data(), ) messages.add_message( request, messages.SUCCESS, _('Deletion has been queued and will happen automatically.')) return HttpResponseRedirect(reverse('sentry-organization-home', args=[team.organization.id])) context = { 'form': form, } return self.respond('sentry/projects/remove.html', context)
def post(self, request, organization, team, project): if not can_remove_project(request.user, project): return HttpResponseRedirect(reverse('sentry')) form = self.get_form(request) if form.is_valid(): if project.status == ProjectStatus.VISIBLE: project.update(status=ProjectStatus.PENDING_DELETION) delete_project.delay(object_id=project.id) AuditLogEntry.objects.create( organization=organization, actor=request.user, ip_address=request.META['REMOTE_ADDR'], target_object=project.id, event=AuditLogEntryEvent.PROJECT_REMOVE, data=project.get_audit_log_data(), ) messages.add_message( request, messages.SUCCESS, _(u'The project %r was scheduled for deletion.') % (project.name.encode('utf-8'), )) return HttpResponseRedirect( reverse('sentry-organization-home', args=[team.organization.id])) context = { 'form': form, } return self.respond('sentry/projects/remove.html', context)
def manage_project(request, project): result = plugins.first('has_perm', request.user, 'edit_project', project) if result is False and not request.user.has_perm('sentry.can_change_project'): return HttpResponseRedirect(reverse('sentry')) team_list = get_team_list(request.user) form = EditProjectForm(request, team_list, request.POST or None, instance=project) if form.is_valid(): project = form.save() return HttpResponseRedirect(request.path + '?success=1') member_list = [(tm, tm.user) for tm in project.team.member_set.select_related('user')] try: key = ProjectKey.objects.get(user=request.user, project=project) except ProjectKey.DoesNotExist: key = None # superuser context = csrf(request) context.update({ 'can_remove_project': can_remove_project(request.user, project), 'page': 'details', 'key': key, 'form': form, 'project': project, 'member_list': member_list, 'TEAM_LIST': team_list.values(), }) return render_to_response('sentry/projects/manage.html', context, request)
def post(self, request, organization, team, project): if not can_remove_project(request.user, project): return HttpResponseRedirect(reverse('sentry')) form = self.get_form(request) if form.is_valid(): if project.status == ProjectStatus.VISIBLE: project.update(status=ProjectStatus.PENDING_DELETION) delete_project.delay(object_id=project.id) AuditLogEntry.objects.create( organization=organization, actor=request.user, ip_address=request.META['REMOTE_ADDR'], target_object=project.id, event=AuditLogEntryEvent.PROJECT_REMOVE, data=project.get_audit_log_data(), ) messages.add_message( request, messages.SUCCESS, _(u'The project %r was scheduled for deletion.') % (project.name.encode('utf-8'),)) return HttpResponseRedirect(reverse('sentry-organization-home', args=[team.organization.id])) context = { 'form': form, } return self.respond('sentry/projects/remove.html', context)
def remove_project(request, project): if not can_remove_project(request.user, project): return HttpResponseRedirect(reverse("sentry")) project_list = filter(lambda x: x != project, get_project_list(request.user).itervalues()) form = RemoveProjectForm(request.user, project_list, request.POST or None) if form.is_valid(): removal_type = form.cleaned_data["removal_type"] if removal_type == "1": project.delete() elif removal_type == "2": new_project = form.cleaned_data["project"] project.merge_to(new_project) elif removal_type == "3": project.update(status=1) else: raise ValueError(removal_type) return HttpResponseRedirect(reverse("sentry-project-list")) context = csrf(request) context.update({"form": form, "project": project}) return render_to_response("sentry/projects/remove.html", context, request)
def remove_project(request, team, project): if not can_remove_project(request.user, project): return HttpResponseRedirect(reverse("sentry")) project_list = filter(lambda x: x != project, Project.objects.get_for_user(request.user)) form = RemoveProjectForm(request.user, project_list, request.POST or None) if form.is_valid(): removal_type = form.cleaned_data["removal_type"] if removal_type == "1": project.delete() elif removal_type == "2": new_project = form.cleaned_data["project"] project.merge_to(new_project) elif removal_type == "3": project.update(status=1) else: raise ValueError(removal_type) return HttpResponseRedirect(reverse("sentry-manage-team-projects", args=[project.team.slug])) context = csrf(request) context.update({"team": team, "form": form, "project": project, "SECTION": "team", "SUBSECTION": "projects"}) return render_to_response("sentry/projects/remove.html", context, request)
def remove_project(request, team, project): if not can_remove_project(request.user, project): return HttpResponseRedirect(reverse('sentry')) project_list = filter(lambda x: x != project, Project.objects.get_for_user(request.user)) form = RemoveProjectForm(request.user, project_list, request.POST or None) if form.is_valid(): removal_type = form.cleaned_data['removal_type'] if removal_type == '1': project.delete() elif removal_type == '2': new_project = form.cleaned_data['project'] project.merge_to(new_project) elif removal_type == '3': project.update(status=1) else: raise ValueError(removal_type) return HttpResponseRedirect(reverse('sentry-manage-team-projects', args=[project.team.slug])) context = csrf(request) context.update({ 'team': team, 'form': form, 'project': project, 'SECTION': 'team', 'SUBSECTION': 'projects' }) return render_to_response('sentry/projects/remove.html', context, request)
def remove_project(request, team, project): if not can_remove_project(request.user, project): return HttpResponseRedirect(reverse('sentry')) form = RemoveProjectForm(request.user, request.POST or None) if form.is_valid(): if project.status != STATUS_HIDDEN: project.update(status=STATUS_HIDDEN) delete_project.delay(object_id=project.id) messages.add_message( request, messages.SUCCESS, _('Deletion has been queued and will happen automatically.')) return HttpResponseRedirect( reverse('sentry-manage-team-projects', args=[project.team.slug])) context = csrf(request) context.update({ 'team': team, 'form': form, 'project': project, }) return render_to_response('sentry/projects/remove.html', context, request)
def manage_project(request, team, project): result = plugins.first('has_perm', request.user, 'edit_project', project) if result is False and not request.user.has_perm('sentry.can_change_project'): return HttpResponseRedirect(reverse('sentry')) team_list = Team.objects.get_for_user(project.owner or request.user, MEMBER_OWNER) form = EditProjectForm(request, team_list, request.POST or None, instance=project, initial={ 'origins': '\n'.join(project.get_option('sentry:origins', None) or []), 'owner': project.owner, 'resolve_age': int(project.get_option('sentry:resolve_age', 0)), }) if form.is_valid(): project = form.save() project.update_option('sentry:origins', form.cleaned_data.get('origins') or []) project.update_option('sentry:resolve_age', form.cleaned_data.get('resolve_age')) messages.add_message( request, messages.SUCCESS, _('Changes to your project were saved.')) return HttpResponseRedirect(reverse('sentry-manage-project', args=[team.slug, project.slug])) context = csrf(request) context.update({ 'team': team, 'can_remove_project': can_remove_project(request.user, project), 'page': 'details', 'form': form, 'project': project, 'SECTION': 'team', 'SUBSECTION': 'projects' }) return render_to_response('sentry/projects/manage.html', context, request)
def remove_project(request, project): if not can_remove_project(request.user, project): return HttpResponseRedirect(reverse('sentry')) project_list = filter(lambda x: x != project, get_project_list(request.user).itervalues()) form = RemoveProjectForm(request.user, project_list, request.POST or None) if form.is_valid(): removal_type = form.cleaned_data['removal_type'] if removal_type == '1': project.delete() elif removal_type == '2': new_project = form.cleaned_data['project'] project.merge_to(new_project) elif removal_type == '3': project.update(status=1) else: raise ValueError(removal_type) return HttpResponseRedirect(reverse('sentry-project-list')) context = csrf(request) context.update({ 'form': form, 'project': project, }) return render_to_response('sentry/projects/remove.html', context, request)
def remove_project(request, team, project): if not can_remove_project(request.user, project): return HttpResponseRedirect(reverse('sentry')) form = RemoveProjectForm(request.user, request.POST or None) if form.is_valid(): if project.status != STATUS_HIDDEN: project.update(status=STATUS_HIDDEN) delete_project.delay(object_id=project.id) messages.add_message( request, messages.SUCCESS, _('Deletion has been queued and will happen automatically.')) return HttpResponseRedirect(reverse('sentry-manage-team-projects', args=[project.team.slug])) context = csrf(request) context.update({ 'team': team, 'form': form, 'project': project, }) return render_to_response('sentry/projects/remove.html', context, request)
def get_default_context(self, request, **kwargs): context = super(ProjectSettingsView, self).get_default_context(request, **kwargs) context.update({ 'can_remove_project': can_remove_project(request.user, kwargs['project']), }) return context
def manage_project(request, project): result = plugins.first('has_perm', request.user, 'edit_project', project) if result is False and not request.user.has_perm( 'sentry.can_change_project'): return HttpResponseRedirect(reverse('sentry')) # XXX: We probably shouldnt allow changing the team unless they're the project owner team_list = Team.objects.get_for_user(project.owner or request.user, MEMBER_OWNER) if request.user.has_perm('sentry.can_change_project'): form_cls = EditProjectAdminForm else: form_cls = EditProjectForm form = form_cls(request, team_list, request.POST or None, instance=project, initial={ 'origins': '\n'.join(get_option('sentry:origins', project) or []), 'owner': project.owner, }) if form.is_valid(): project = form.save() set_option('sentry:origins', form.cleaned_data.get('origins') or [], project) return HttpResponseRedirect(request.path + '?success=1') if not project.team: member_list = [] else: member_list = [(tm, tm.user) for tm in project.team.member_set.select_related('user') ] context = csrf(request) context.update({ 'can_remove_project': can_remove_project(request.user, project), 'page': 'details', 'form': form, 'project': project, 'member_list': member_list, 'TEAM_LIST': team_list.values(), }) return render_to_response('sentry/projects/manage.html', context, request)
def get(self, request, organization, team, project): if not can_remove_project(request.user, project): return HttpResponseRedirect(reverse('sentry')) form = self.get_form(request) context = { 'form': form, } return self.respond('sentry/projects/remove.html', context)
def manage_project(request, team, project): result = plugins.first("has_perm", request.user, "edit_project", project) if result is False and not request.user.has_perm("sentry.can_change_project"): return HttpResponseRedirect(reverse("sentry")) # XXX: We probably shouldn't allow changing the team unless they're the project owner team_list = Team.objects.get_for_user(project.owner or request.user, MEMBER_OWNER) can_admin_project = request.user == project.owner or request.user.has_perm("sentry.can_change_project") if can_admin_project: form_cls = EditProjectAdminForm else: form_cls = EditProjectForm form = form_cls( request, team_list, request.POST or None, instance=project, initial={ "origins": "\n".join(project.get_option("sentry:origins", None) or []), "owner": project.owner, "resolve_age": int(project.get_option("sentry:resolve_age", 0)), }, ) if form.is_valid(): project = form.save() project.update_option("sentry:origins", form.cleaned_data.get("origins") or []) project.update_option("sentry:resolve_age", form.cleaned_data.get("resolve_age")) messages.add_message(request, messages.SUCCESS, _("Changes to your project were saved.")) return HttpResponseRedirect(reverse("sentry-manage-project", args=[team.slug, project.slug])) context = csrf(request) context.update( { "team": team, "can_remove_project": can_remove_project(request.user, project), "page": "details", "form": form, "project": project, "SECTION": "team", "SUBSECTION": "projects", } ) return render_to_response("sentry/projects/manage.html", context, request)
def client_help(request, project): try: key = ProjectKey.objects.get(user=request.user, project=project) except ProjectKey.DoesNotExist: key = None # superuser context = { "can_remove_project": can_remove_project(request.user, project), "page": "client_help", "project": project, "key": key, } if key: context.update({"dsn": key.get_dsn(), "dsn_public": key.get_dsn(public=True)}) return render_to_response("sentry/projects/client_help.html", context, request)
def client_help(request, project): try: key = ProjectKey.objects.get(user=request.user, project=project) except ProjectKey.DoesNotExist: key = None # superuser context = { 'can_remove_project': can_remove_project(request.user, project), 'page': 'client_help', 'project': project, 'key': key, } if key: context.update({ 'dsn': key.get_dsn(), 'dsn_public': key.get_dsn(public=True), }) return render_to_response('sentry/projects/client_help.html', context, request)
def manage_project(request, project): result = plugins.first("has_perm", request.user, "edit_project", project) if result is False and not request.user.has_perm("sentry.can_change_project"): return HttpResponseRedirect(reverse("sentry")) team_list = Team.objects.get_for_user(request.user, MEMBER_OWNER) if request.user.has_perm("sentry.can_change_project"): form_cls = EditProjectAdminForm else: form_cls = EditProjectForm form = form_cls( request, team_list, request.POST or None, instance=project, initial={"origins": "\n".join(get_option("sentry:origins", project) or []), "owner": project.owner}, ) if form.is_valid(): project = form.save() set_option("sentry:origins", form.cleaned_data.get("origins") or [], project) return HttpResponseRedirect(request.path + "?success=1") if not project.team: member_list = [] else: member_list = [(tm, tm.user) for tm in project.team.member_set.select_related("user")] context = csrf(request) context.update( { "can_remove_project": can_remove_project(request.user, project), "page": "details", "form": form, "project": project, "member_list": member_list, "TEAM_LIST": team_list.values(), } ) return render_to_response("sentry/projects/manage.html", context, request)
def manage_project(request, team, project): result = plugins.first('has_perm', request.user, 'edit_project', project) if result is False and not request.user.has_perm('sentry.can_change_project'): return HttpResponseRedirect(reverse('sentry')) # XXX: We probably shouldnt allow changing the team unless they're the project owner team_list = Team.objects.get_for_user(project.owner or request.user, MEMBER_OWNER) can_admin_project = request.user == project.owner or request.user.has_perm('sentry.can_change_project') if can_admin_project: form_cls = EditProjectAdminForm else: form_cls = EditProjectForm form = form_cls(request, team_list, request.POST or None, instance=project, initial={ 'origins': '\n'.join(get_option('sentry:origins', project) or []), 'owner': project.owner, }) if form.is_valid(): project = form.save() set_option('sentry:origins', form.cleaned_data.get('origins') or [], project) messages.add_message(request, messages.SUCCESS, _('Changes to your project were saved.')) return HttpResponseRedirect(reverse('sentry-manage-project', args=[team.slug, project.slug])) context = csrf(request) context.update({ 'team': team, 'can_remove_project': can_remove_project(request.user, project), 'page': 'details', 'form': form, 'project': project, 'SECTION': 'team', 'SUBSECTION': 'projects' }) return render_to_response('sentry/projects/manage.html', context, request)
def post(self, request, organization, team, project): if not can_remove_project(request.user, project): return HttpResponseRedirect(reverse('sentry')) form = self.get_form(request) if form.is_valid(): client.delete('/projects/{}/{}/'.format(organization.slug, project.slug), request.user, is_sudo=True) messages.add_message( request, messages.SUCCESS, _(u'The project %r was scheduled for deletion.') % (project.name.encode('utf-8'),)) return HttpResponseRedirect(reverse('sentry-organization-home', args=[team.organization.slug])) context = { 'form': form, } return self.respond('sentry/projects/remove.html', context)
def remove_project(request, team, project): if not can_remove_project(request.user, project): return HttpResponseRedirect(reverse('sentry')) project_list = filter(lambda x: x != project, Project.objects.get_for_user(request.user)) form = RemoveProjectForm(request.user, project_list, request.POST or None) if form.is_valid(): removal_type = form.cleaned_data['removal_type'] if removal_type == '1': from sentry.tasks.deletion import delete_project delete_project.delay(object_id=project.id) project.update(status=STATUS_HIDDEN) messages.add_message( request, messages.SUCCESS, _('Deletion has been queued and should occur shortly.')) elif removal_type == '2': new_project = form.cleaned_data['project'] project.merge_to(new_project) elif removal_type == '3': project.update(status=STATUS_HIDDEN) else: raise ValueError(removal_type) return HttpResponseRedirect( reverse('sentry-manage-team-projects', args=[project.team.slug])) context = csrf(request) context.update({ 'team': team, 'form': form, 'project': project, }) return render_to_response('sentry/projects/remove.html', context, request)
def manage_project(request, project): result = plugins.first('has_perm', request.user, 'edit_project', project) if result is False and not request.user.has_perm('sentry.can_change_project'): return HttpResponseRedirect(reverse('sentry')) team_list = Team.objects.get_for_user(request.user, MEMBER_OWNER) if request.user.has_perm('sentry.can_change_project'): form_cls = EditProjectAdminForm else: form_cls = EditProjectForm form = form_cls(request, team_list, request.POST or None, instance=project, initial={ 'origins': '\n'.join(get_option('sentry:origins', project) or []), 'owner': project.owner, }) if form.is_valid(): project = form.save() set_option('sentry:origins', form.cleaned_data.get('origins') or [], project) return HttpResponseRedirect(request.path + '?success=1') if not project.team: member_list = [] else: member_list = [(tm, tm.user) for tm in project.team.member_set.select_related('user')] context = csrf(request) context.update({ 'can_remove_project': can_remove_project(request.user, project), 'page': 'details', 'form': form, 'project': project, 'member_list': member_list, 'TEAM_LIST': team_list.values(), }) return render_to_response('sentry/projects/manage.html', context, request)
def manage_project(request, project): result = plugins.first('has_perm', request.user, 'edit_project', project) if result is False and not request.user.has_perm( 'sentry.can_change_project'): return HttpResponseRedirect(reverse('sentry')) team_list = get_team_list(request.user) form = EditProjectForm(request, team_list, request.POST or None, instance=project) if form.is_valid(): project = form.save() return HttpResponseRedirect(request.path + '?success=1') member_list = [(tm, tm.user) for tm in project.team.member_set.select_related('user')] context = csrf(request) context.update({ 'can_remove_project': can_remove_project(request.user, project), 'page': 'details', 'form': form, 'project': project, 'member_list': member_list, 'TEAM_LIST': team_list.values(), }) return render_to_response('sentry/projects/manage.html', context, request)
def remove_project(request, team, project): if not can_remove_project(request.user, project): return HttpResponseRedirect(reverse('sentry')) project_list = filter(lambda x: x != project, Project.objects.get_for_user(request.user)) form = RemoveProjectForm(request.user, project_list, request.POST or None) if form.is_valid(): removal_type = form.cleaned_data['removal_type'] if removal_type == '1': from sentry.tasks.deletion import delete_project delete_project.delay(object_id=project.id) project.update(status=STATUS_HIDDEN) messages.add_message( request, messages.SUCCESS, _('Deletion has been queued and should occur shortly.')) elif removal_type == '2': new_project = form.cleaned_data['project'] project.merge_to(new_project) elif removal_type == '3': project.update(status=STATUS_HIDDEN) else: raise ValueError(removal_type) return HttpResponseRedirect(reverse('sentry-manage-team-projects', args=[project.team.slug])) context = csrf(request) context.update({ 'team': team, 'form': form, 'project': project, }) return render_to_response('sentry/projects/remove.html', context, request)
""" sentry.templatetags.sentry_permissions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :copyright: (c) 2010-2014 by the Sentry Team, see AUTHORS for more details. :license: BSD, see LICENSE for more details. """ from __future__ import absolute_import from django import template from sentry.permissions import ( can_create_organizations, can_create_teams, can_create_projects, can_remove_project, can_manage_project, can_manage_team, can_manage_org ) register = template.Library() # TODO: Django doesn't seem to introspect function args correctly for filters # so we can't just register.filter(can_add_team_member) register.filter('can_create_organizations')(lambda a: can_create_organizations(a)) register.filter('can_create_teams')(lambda a, b: can_create_teams(a, b)) register.filter('can_create_projects')(lambda a, b: can_create_projects(a, b)) register.filter('can_manage_team')(lambda a, b: can_manage_team(a, b)) register.filter('can_manage_project')(lambda a, b: can_manage_project(a, b)) register.filter('can_manage_org')(lambda a, b: can_manage_org(a, b)) register.filter('can_remove_project')(lambda a, b: can_remove_project(a, b))
""" sentry.templatetags.sentry_permissions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :copyright: (c) 2010-2014 by the Sentry Team, see AUTHORS for more details. :license: BSD, see LICENSE for more details. """ from __future__ import absolute_import from django import template from sentry.permissions import (can_create_organizations, can_create_teams, can_create_projects, can_remove_project, can_manage_project, can_manage_team, can_manage_org) register = template.Library() # TODO: Django doesn't seem to introspect function args correctly for filters # so we can't just register.filter(can_add_team_member) register.filter('can_create_organizations')( lambda a: can_create_organizations(a)) register.filter('can_create_teams')(lambda a, b: can_create_teams(a, b)) register.filter('can_create_projects')(lambda a, b: can_create_projects(a, b)) register.filter('can_manage_team')(lambda a, b: can_manage_team(a, b)) register.filter('can_manage_project')(lambda a, b: can_manage_project(a, b)) register.filter('can_manage_org')(lambda a, b: can_manage_org(a, b)) register.filter('can_remove_project')(lambda a, b: can_remove_project(a, b))