def get_default_context(request, existing_context=None, team=None): from sentry.plugins import plugins context = { 'HAS_SEARCH': settings.USE_SEARCH, 'MESSAGES_PER_PAGE': settings.MESSAGES_PER_PAGE, 'URL_PREFIX': settings.URL_PREFIX, 'PLUGINS': plugins, } if request: context.update({ 'request': request, 'can_create_teams': can_create_teams(request.user), }) if team: context.update({ 'can_admin_team': Team.objects.get_for_user(request.user, MEMBER_OWNER), 'can_create_projects': can_create_projects(request.user, team=team), }) else: context['can_create_projects'] = can_create_projects(request.user) if not existing_context or 'PROJECT_LIST' not in existing_context: project_list = Project.objects.get_for_user(request.user, team=team) context['PROJECT_LIST'] = sorted(project_list, key=lambda x: x.name) if not existing_context or 'TEAM_LIST' not in existing_context: context['TEAM_LIST'] = sorted(Team.objects.get_for_user(request.user).values(), key=lambda x: x.name) return context
def get_default_context(request, existing_context=None): from sentry.plugins import plugins context = { 'HAS_SEARCH': settings.USE_SEARCH, 'MESSAGES_PER_PAGE': settings.MESSAGES_PER_PAGE, 'PROJECT_ID': str(settings.PROJECT), 'VIEWS': list(View.objects.all()), 'URL_PREFIX': settings.URL_PREFIX, 'PLUGINS': plugins, 'USE_JS_CLIENT': settings.USE_JS_CLIENT, } if request: context.update({ 'request': request, 'can_create_projects': can_create_projects(request.user), 'can_create_teams': can_create_teams(request.user), }) if not existing_context or 'PROJECT_LIST' not in existing_context: context['PROJECT_LIST'] = get_project_list(request.user).values() if not existing_context or 'TEAM_LIST' not in existing_context: context['TEAM_LIST'] = get_team_list(request.user).values() return context
def create_new_team_project(request, team): from sentry.web.forms.projects import NewProjectAdminForm, NewProjectForm if not can_create_projects(request.user, team): return HttpResponseRedirect(reverse('sentry')) 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() 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)
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() 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)
def get_default_context(request, existing_context=None): from sentry.plugins import plugins context = { 'COMPRESS_ENABLED': dj_settings.COMPRESS_ENABLED, 'COMPRESS_LESS': dj_settings.COMPRESS_ENABLED and dj_settings.LESS_BIN, 'HAS_SEARCH': settings.USE_SEARCH, 'MESSAGES_PER_PAGE': settings.MESSAGES_PER_PAGE, 'INTERNAL_PROJECT': get_internal_project(), 'PROJECT_ID': str(settings.PROJECT), 'URL_PREFIX': settings.URL_PREFIX, 'PLUGINS': plugins, 'USE_JS_CLIENT': settings.USE_JS_CLIENT, } if request: context.update({ 'request': request, 'can_create_projects': can_create_projects(request.user), 'can_create_teams': can_create_teams(request.user), }) if not existing_context or 'PROJECT_LIST' not in existing_context: context['PROJECT_LIST'] = get_project_list(request.user).values() if not existing_context or 'TEAM_LIST' not in existing_context: context['TEAM_LIST'] = Team.objects.get_for_user( request.user).values() return context
def create_new_team_project(request, team): from sentry.web.forms.projects import NewProjectAdminForm, NewProjectForm if not can_create_projects(request.user, team): return HttpResponseRedirect(reverse('sentry')) 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() return HttpResponseRedirect(reverse('sentry-manage-project', args=[project.slug])) context = csrf(request) context.update({ 'form': form, 'team': team, }) return render_to_response('sentry/teams/projects/new.html', context, request)
def new_project(request): from django.contrib.auth.models import User if not can_create_projects(request.user): return HttpResponseRedirect(reverse('sentry')) allow_create_teams = can_create_teams(request.user) team_list = Team.objects.get_for_user(request.user) if request.user.has_perm('sentry.can_add_project') and User.objects.all()[0:2] == 2: project_form_cls = NewProjectAdminForm project_initial = { 'owner': request.user.username, } else: project_form_cls = NewProjectForm project_initial = {} if len(team_list) > 0: select_team_form = SelectTeamForm(team_list, request.POST or None, prefix='st') elif not allow_create_teams: return render_to_response('sentry/projects/cannot_create_teams.html', {}, request) else: select_team_form = None if allow_create_teams: new_team_form = NewTeamForm(request.POST or None, prefix='nt') else: new_team_form = None project_form = project_form_cls(request.POST or None, initial=project_initial, prefix='prj') is_new_team = new_team_form and new_team_form.is_valid() if is_new_team or not select_team_form: team_form = new_team_form else: team_form = select_team_form if project_form.is_valid() and team_form.is_valid(): project = project_form.save(commit=False) if not project.owner: project.owner = request.user if is_new_team: team = new_team_form.save(commit=False) team.owner = project.owner team.save() else: team = select_team_form.cleaned_data['team'] project.team = team project.save() return HttpResponseRedirect(reverse('sentry-get-started', args=[project.slug])) return render_to_response('sentry/projects/new.html', { 'project_form': project_form, 'select_team_form': select_team_form, 'new_team_form': new_team_form, }, request)
def manage_team(request, team): result = plugins.first('has_perm', request.user, 'edit_team', team) if result is False and not request.user.has_perm('sentry.can_change_team'): return HttpResponseRedirect(reverse('sentry')) form = EditTeamForm(request.POST or None, instance=team) if form.is_valid(): team = form.save() return HttpResponseRedirect(request.path + '?success=1') member_list = [(pm, pm.user) for pm in team.member_set.select_related('user').order_by('user__username')] pending_member_list = [(pm, pm.email) for pm in team.pending_member_set.all().order_by('email')] project_list = list(team.project_set.all()) context = csrf(request) context.update({ 'can_add_project': can_create_projects(request.user, team), 'can_add_member': can_add_team_member(request.user, team), 'can_remove_team': can_remove_team(request.user, team), 'page': 'details', 'form': form, 'team': team, 'member_list': member_list, 'pending_member_list': pending_member_list, 'project_list': project_list, }) return render_to_response('sentry/teams/manage.html', context, request)
def manage_team(request, team): result = plugins.first('has_perm', request.user, 'edit_team', team) if result is False and not request.user.has_perm('sentry.can_change_team'): return HttpResponseRedirect(reverse('sentry')) form = EditTeamForm(request.POST or None, instance=team) if form.is_valid(): team = form.save() return HttpResponseRedirect(request.path + '?success=1') member_list = [(pm, pm.user) for pm in team.member_set.select_related( 'user').order_by('user__username')] pending_member_list = [ (pm, pm.email) for pm in team.pending_member_set.all().order_by('email') ] project_list = list(team.project_set.all()) context = csrf(request) context.update({ 'can_add_project': can_create_projects(request.user, team), 'can_add_member': can_add_team_member(request.user, team), 'can_remove_team': can_remove_team(request.user, team), 'page': 'details', 'form': form, 'team': team, 'member_list': member_list, 'pending_member_list': pending_member_list, 'project_list': project_list, }) return render_to_response('sentry/teams/manage.html', context, request)
def get_default_context(request, existing_context=None): from sentry.plugins import plugins context = { 'HAS_SEARCH': settings.USE_SEARCH, 'MESSAGES_PER_PAGE': settings.MESSAGES_PER_PAGE, 'PROJECT_ID': str(settings.PROJECT), 'VIEWS': list(View.objects.all()), 'URL_PREFIX': settings.URL_PREFIX, 'PLUGINS': plugins, 'USE_JS_CLIENT': settings.USE_JS_CLIENT, } if request: context.update({ 'request': request, 'can_create_projects': can_create_projects(request.user), 'can_create_teams': can_create_teams(request.user), }) if not existing_context or 'PROJECT_LIST' not in existing_context: context['PROJECT_LIST'] = get_project_list(request.user).values() if not existing_context or 'TEAM_LIST' not in existing_context: context['TEAM_LIST'] = get_team_list(request.user).values() return context
def get_default_context(request, existing_context=None, team=None): from sentry.plugins import plugins context = { "HAS_SEARCH": settings.USE_SEARCH, "MESSAGES_PER_PAGE": settings.MESSAGES_PER_PAGE, "INTERNAL_PROJECT": get_internal_project(), "PROJECT_ID": str(settings.PROJECT), "URL_PREFIX": settings.URL_PREFIX, "PLUGINS": plugins, "USE_JS_CLIENT": settings.USE_JS_CLIENT, } if request: context.update( { "request": request, "can_create_projects": can_create_projects(request.user), "can_create_teams": can_create_teams(request.user), } ) if team: context.update({"can_admin_team": Team.objects.get_for_user(request.user, MEMBER_OWNER)}) if not existing_context or "PROJECT_LIST" not in existing_context: project_list = Project.objects.get_for_user(request.user, team=team) context["PROJECT_LIST"] = sorted(project_list, key=lambda x: x.name) if not existing_context or "TEAM_LIST" not in existing_context: context["TEAM_LIST"] = sorted(Team.objects.get_for_user(request.user).values(), key=lambda x: x.name) return context
def create_new_team_project(request, team): from sentry.web.forms import NewProjectAdminForm, NewProjectForm if not can_create_projects(request.user, team): return HttpResponseRedirect(reverse('sentry')) 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() return HttpResponseRedirect(reverse('sentry-manage-project', args=[project.pk])) context = csrf(request) context.update({ 'form': form, 'team': team, }) return render_to_response('sentry/teams/projects/new.html', context, request)
def get_default_context(request, existing_context=None): from sentry.plugins import plugins context = { 'COMPRESS_ENABLED': dj_settings.COMPRESS_ENABLED, 'COMPRESS_LESS': dj_settings.COMPRESS_ENABLED and dj_settings.LESS_BIN, 'HAS_SEARCH': settings.USE_SEARCH, 'MESSAGES_PER_PAGE': settings.MESSAGES_PER_PAGE, 'INTERNAL_PROJECT': get_internal_project(), 'PROJECT_ID': str(settings.PROJECT), 'VIEWS': list(View.objects.all()), 'URL_PREFIX': settings.URL_PREFIX, 'PLUGINS': plugins, 'USE_JS_CLIENT': settings.USE_JS_CLIENT, } if request: context.update({ 'request': request, 'can_create_projects': can_create_projects(request.user), 'can_create_teams': can_create_teams(request.user), }) if not existing_context or 'PROJECT_LIST' not in existing_context: context['PROJECT_LIST'] = get_project_list(request.user).values() if not existing_context or 'TEAM_LIST' not in existing_context: context['TEAM_LIST'] = Team.objects.get_for_user(request.user).values() return context
def create_new_team_project(request, team): from sentry.web.forms.projects import NewProjectAdminForm, NewProjectForm if not can_create_projects(request.user, team): return HttpResponseRedirect(reverse("sentry")) 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() if project.platform not in (None, "other"): return HttpResponseRedirect(reverse("sentry-docs-client", args=[project.slug, project.platform])) return HttpResponseRedirect(reverse("sentry-get-started", args=[project.slug])) context = csrf(request) context.update({"form": form, "team": team, "page": "projects"}) return render_to_response("sentry/teams/projects/new.html", context, request)
def get_default_context(request, existing_context=None): from sentry.plugins import plugins context = { "HAS_SEARCH": settings.USE_SEARCH, "MESSAGES_PER_PAGE": settings.MESSAGES_PER_PAGE, "PROJECT_ID": str(settings.PROJECT), "VIEWS": list(View.objects.all()), "URL_PREFIX": settings.URL_PREFIX, "PLUGINS": plugins, "USE_JS_CLIENT": settings.USE_JS_CLIENT, } if request: context.update( { "request": request, "can_create_projects": can_create_projects(request.user), "can_create_teams": can_create_teams(request.user), } ) if not existing_context or "PROJECT_LIST" not in existing_context: context["PROJECT_LIST"] = get_project_list(request.user).values() if not existing_context or "TEAM_LIST" not in existing_context: context["TEAM_LIST"] = Team.objects.get_for_user(request.user).values() return context
def new_project(request): from django.contrib.auth.models import User if not can_create_projects(request.user): return HttpResponseRedirect(reverse('sentry')) allow_create_teams = can_create_teams(request.user) team_list = Team.objects.get_for_user(request.user) if request.user.has_perm('sentry.can_add_project') and User.objects.all()[0:2] == 2: project_form_cls = NewProjectAdminForm project_initial = { 'owner': request.user.username, } else: project_form_cls = NewProjectForm project_initial = {} if len(team_list) > 0: select_team_form = SelectTeamForm(team_list, request.POST or None, prefix='st') elif not allow_create_teams: return render_to_response('sentry/projects/cannot_create_teams.html', {}, request) else: select_team_form = None if allow_create_teams: new_team_form = NewTeamForm(request.POST or None, prefix='nt') else: new_team_form = None project_form = project_form_cls(request.POST or None, initial=project_initial, prefix='prj') is_new_team = new_team_form and new_team_form.is_valid() if is_new_team or not select_team_form: team_form = new_team_form else: team_form = select_team_form if project_form.is_valid() and team_form.is_valid(): project = project_form.save(commit=False) if not project.owner: project.owner = request.user if is_new_team: team = new_team_form.save(commit=False) team.owner = project.owner team.save() else: team = select_team_form.cleaned_data['team'] project.team = team project.save() return HttpResponseRedirect(reverse('sentry-project-client-help', args=[project.slug])) return render_to_response('sentry/projects/new.html', { 'project_form': project_form, 'select_team_form': select_team_form, 'new_team_form': new_team_form, }, request)
def dashboard(request, team): project_list = list(Project.objects.filter(team=team)) if not project_list and can_create_projects(request.user, team=team): return HttpResponseRedirect(reverse("sentry-new-project", args=[team.slug])) for project in project_list: project.team = team return render_to_response("sentry/dashboard.html", {"team": team, "project_list": project_list}, request)
def new_project(request): from django.contrib.auth.models import User if not can_create_projects(request.user): return HttpResponseRedirect(reverse("sentry")) allow_create_teams = can_create_teams(request.user) team_list = Team.objects.get_for_user(request.user) if request.user.has_perm("sentry.can_add_project") and User.objects.all()[0:2] == 2: project_form_cls = NewProjectAdminForm project_initial = {"owner": request.user.username} else: project_form_cls = NewProjectForm project_initial = {} if len(team_list) > 0: select_team_form = SelectTeamForm(team_list, request.POST or None, prefix="st") elif not allow_create_teams: return render_to_response("sentry/projects/cannot_create_teams.html", {}, request) else: select_team_form = None if allow_create_teams: new_team_form = NewTeamForm(request.POST or None, prefix="nt") else: new_team_form = None project_form = project_form_cls(request.POST or None, initial=project_initial, prefix="prj") is_new_team = new_team_form and new_team_form.is_valid() if is_new_team or not select_team_form: team_form = new_team_form else: team_form = select_team_form if project_form.is_valid() and team_form.is_valid(): project = project_form.save(commit=False) if not project.owner: project.owner = request.user if is_new_team: team = new_team_form.save(commit=False) team.owner = project.owner team.save() else: team = select_team_form.cleaned_data["team"] project.team = team project.save() return HttpResponseRedirect(reverse("sentry-project-client-help", args=[project.slug])) return render_to_response( "sentry/projects/new.html", {"project_form": project_form, "select_team_form": select_team_form, "new_team_form": new_team_form}, request, )
def dashboard(request): project_list = get_project_list(request.user, key="slug") has_projects = len(project_list) > 1 or (len(project_list) == 1 and project_list.values()[0].pk != settings.PROJECT) if not has_projects: if not request.user.is_authenticated(): request.session["_next"] = request.build_absolute_uri() return HttpResponseRedirect(get_login_url()) elif can_create_projects(request.user): return HttpResponseRedirect(reverse("sentry-new-project")) return render_to_response("sentry/dashboard.html", {}, request)
def dashboard(request, template='dashboard.html'): project_list = get_project_list(request.user, key='slug') has_projects = len(project_list) > 1 or (len(project_list) == 1 and project_list.values()[0].pk != settings.PROJECT) if not has_projects: if not request.user.is_authenticated(): request.session['_next'] = request.get_full_path() return HttpResponseRedirect(get_login_url()) elif can_create_projects(request.user): return HttpResponseRedirect(reverse('sentry-new-project')) return render_to_response('sentry/%s' % template, {}, request)
def dashboard(request, team): project_list = list(Project.objects.filter(team=team)) if not project_list and can_create_projects(request.user, team=team): return HttpResponseRedirect(reverse('sentry-new-project', args=[team.slug])) for project in project_list: project.team = team return render_to_response('sentry/dashboard.html', { 'team': team, 'project_list': project_list, }, request)
def dashboard(request, team): project_list = list(Project.objects.filter(team=team)) if not project_list and can_create_projects(request.user, team=team): return HttpResponseRedirect(reverse('sentry-new-project', args=[team.slug])) for project in project_list: project.team = team return render_to_response('sentry/dashboard.html', { 'team': team, 'project_list': project_list, 'SECTION': 'events', }, request)
def dashboard(request, template='dashboard.html'): project_list = get_project_list(request.user, key='slug') has_projects = len(project_list) > 1 or ( len(project_list) == 1 and project_list.values()[0].pk != settings.PROJECT) if not has_projects: if not request.user.is_authenticated(): request.session['_next'] = request.get_full_path() return HttpResponseRedirect(get_login_url()) elif can_create_projects(request.user): return HttpResponseRedirect(reverse('sentry-new-project')) return render_to_response('sentry/%s' % template, {}, request)
def dashboard(request, organization, team): project_list = list(Project.objects.filter(team=team)) if not project_list and can_create_projects(request.user, team=team): url = reverse('sentry-create-project', args=[team.organization.slug]) return HttpResponseRedirect(url + '?team=' + team.slug) for project in project_list: project.team = team return render_to_response('sentry/dashboard.html', { 'organization': team.organization, 'team': team, 'project_list': project_list, }, request)
def dashboard(request, organization, team): project_list = list(Project.objects.filter(team=team)) if not project_list and can_create_projects(request.user, team=team): url = reverse('sentry-create-project', args=[team.organization.slug]) return HttpResponseRedirect(url + '?team=' + team.slug) for project in project_list: project.team = team return render_to_response( 'sentry/dashboard.html', { 'organization': team.organization, 'team': team, 'project_list': project_list, }, request)
def manage_team_projects(request, team): result = plugins.first('has_perm', request.user, 'edit_team', team) if result is False and not request.user.has_perm('sentry.can_change_team'): return HttpResponseRedirect(reverse('sentry')) project_list = list(team.project_set.all()) context = csrf(request) context.update({ 'can_add_project': can_create_projects(request.user, team), 'page': 'projects', 'team': team, 'project_list': project_list, }) return render_to_response('sentry/teams/projects/index.html', context, request)
def post(self, request, team_id): team = Team.objects.get_from_cache(id=team_id) assert_perm(team, request.user, request.auth, access=MEMBER_ADMIN) if not can_create_projects(user=request.user, team=team): return Response(status=403) serializer = ProjectSerializer(data=request.DATA) if serializer.is_valid(): project = serializer.object project.team = team project.organization = team.organization project.save() return Response(serialize(project, request.user), status=201) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def post(self, request, team_id): team = Team.objects.get_from_cache(id=team_id) assert_perm(team, request.user, request.auth, access=MEMBER_ADMIN) if not can_create_projects(request.user, team=team_id): return Response(status=403) serializer = ProjectSerializer(data=request.DATA) if serializer.is_valid(): project = serializer.object project.team = team project.owner = team.owner project.save() return Response(serialize(project, request.user), status=201) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def manage_team_projects(request, team): result = plugins.first('has_perm', request.user, 'edit_team', team) if result is False and not request.user.has_perm('sentry.can_change_team'): return HttpResponseRedirect(reverse('sentry')) project_list = list(team.project_set.all()) context = csrf(request) context.update({ 'can_add_project': can_create_projects(request.user, team), 'page': 'projects', 'team': team, 'project_list': project_list, }) return render_to_response('sentry/teams/projects/index.html', context, request)
def manage_team(request, team): result = plugins.first('has_perm', request.user, 'edit_team', team) if result is False and not request.user.has_perm('sentry.can_change_team'): return HttpResponseRedirect(reverse('sentry')) if request.user.has_perm('sentry.can_add_team'): form_cls = EditTeamAdminForm else: form_cls = EditTeamForm form = form_cls(request.POST or None, initial={ 'owner': team.owner, }, instance=team) # XXX: form.is_valid() changes the foreignkey original_owner = team.owner if form.is_valid(): team = form.save() if team.owner != original_owner: # Update access for new membership if it's changed # (e.g. member used to be USER, but is now OWNER) team.member_set.filter(user=team.owner).update(type=MEMBER_OWNER) return HttpResponseRedirect(request.path + '?success=1') member_list = [(pm, pm.user) for pm in team.member_set.select_related('user').order_by('user__username')] pending_member_list = [(pm, pm.email) for pm in team.pending_member_set.all().order_by('email')] project_list = list(team.project_set.all()) context = csrf(request) context.update({ 'can_add_project': can_create_projects(request.user, team), 'can_add_member': can_add_team_member(request.user, team), 'can_remove_team': can_remove_team(request.user, team), 'page': 'details', 'form': form, 'team': team, 'member_list': member_list, 'pending_member_list': pending_member_list, 'project_list': project_list, }) return render_to_response('sentry/teams/manage.html', context, request)
def manage_team_projects(request, team): result = plugins.first("has_perm", request.user, "edit_team", team) if result is False and not request.user.has_perm("sentry.can_change_team"): return HttpResponseRedirect(reverse("sentry")) project_list = list(team.project_set.all()) context = csrf(request) context.update( { "can_add_project": can_create_projects(request.user, team), "page": "projects", "team": team, "project_list": project_list, } ) return render_to_response("sentry/teams/projects/index.html", context, request)
def dashboard(request, organization, team): project_list = list(Project.objects.filter(team=team)) if not project_list and can_create_projects(request.user, team=team): url = reverse("sentry-create-project", args=[team.organization.slug]) return HttpResponseRedirect(url + "?team=" + team.slug) for project in project_list: project.team = team return render_to_response( "sentry/dashboard.html", { "organization": team.organization, "team": team, "project_list": project_list, "ACCESS": access.from_user(user=request.user, organization=organization).to_django_context(), }, request, )
def get_default_context(request, existing_context=None, team=None): from sentry.plugins import plugins context = { 'COMPRESS_ENABLED': dj_settings.COMPRESS_ENABLED, 'COMPRESS_LESS': dj_settings.COMPRESS_ENABLED and dj_settings.LESS_BIN, 'HAS_SEARCH': settings.USE_SEARCH, 'MESSAGES_PER_PAGE': settings.MESSAGES_PER_PAGE, 'INTERNAL_PROJECT': get_internal_project(), 'PROJECT_ID': str(settings.PROJECT), 'URL_PREFIX': settings.URL_PREFIX, 'PLUGINS': plugins, 'USE_JS_CLIENT': settings.USE_JS_CLIENT, } if request: context.update({ 'request': request, 'can_create_projects': can_create_projects(request.user), 'can_create_teams': can_create_teams(request.user), }) if team: context.update({ 'can_admin_team': Team.objects.get_for_user(request.user, MEMBER_OWNER) }) if not existing_context or 'PROJECT_LIST' not in existing_context: if team: project_list = Project.objects.filter(team=team) else: project_list = get_project_list(request.user).values() context['PROJECT_LIST'] = sorted(project_list, key=lambda x: x.name) if not existing_context or 'TEAM_LIST' not in existing_context: context['TEAM_LIST'] = sorted(Team.objects.get_for_user(request.user).values(), key=lambda x: x.name) return context
def post(self, request, team): """ Create a new project Create a new project bound to a team. {method} {path} {{ "name": "My project" }} """ if not can_create_projects(user=request.user, team=team): return Response(status=403) serializer = ProjectSerializer(data=request.DATA) if serializer.is_valid(): project = serializer.object project.team = team project.organization = team.organization project.save() return Response(serialize(project, request.user), status=201) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def post(self, request, team): """ Create a new project Create a new project bound to a team. {method} {path} {{ "name": "My project" }} """ if not can_create_projects(user=request.user, team=team): return Response(status=403) serializer = ProjectSerializer(data=request.DATA) if serializer.is_valid(): project = serializer.object project.team = team project.organization = team.organization project.save() return Response(serialize(project, request.user), status=201) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def test_allow_creation_is_true(self): with self.settings(SENTRY_ALLOW_PROJECT_CREATION=True): user = User(id=100000) self.assertTrue(can_create_projects(user))
def new_project(request): if not can_create_projects(request.user): return HttpResponseRedirect(reverse('sentry')) return render_to_response('sentry/projects/new.html', {}, request)
def test_allow_creation_is_true(self): user = User(id=100000) self.assertTrue(can_create_projects(user))
""" 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))
def test_superuser_is_true(self): user = User(id=100000, is_superuser=True) self.assertTrue(can_create_projects(user))
""" 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))
def new_project(request): if not can_create_projects(request.user): return HttpResponseRedirect(reverse('sentry')) return render_to_response('sentry/projects/new.html', {}, request)
def test_dont_allow_creation_is_false(self): with self.Settings(SENTRY_ALLOW_PROJECT_CREATION=False): user = User(id=100000) self.assertFalse(can_create_projects(user))
def test_anonymous_is_false(self): user = AnonymousUser() self.assertFalse(can_create_projects(user))