本文整理汇总了Python中sentry.auth.access.from_user函数的典型用法代码示例。如果您正苦于以下问题:Python from_user函数的具体用法?Python from_user怎么用?Python from_user使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了from_user函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tag_value_details
def tag_value_details(request, organization, project, key, value_id):
tag_key = TagKey.objects.get(
project=project, key=key)
tag_value = TagValue.objects.get(
project=project, key=key, id=value_id)
event_list = Group.objects.filter(
grouptag__project=project,
grouptag__key=key,
grouptag__value=tag_value.value,
).order_by('-score')
return render_to_response('sentry/explore/tag_value_details.html', {
'SECTION': 'explore',
'project': project,
'team': project.team,
'organization': organization,
'tag_key': tag_key,
'tag_value': tag_value,
'event_list': event_list,
'ACCESS': access.from_user(
user=request.user,
organization=organization,
).to_django_context(),
}, request)
示例2: get_view_response
def get_view_response(self, request, group):
from sentry.models import Event
self.selected = request.path == self.get_url(group)
if not self.selected:
return
response = self.view(request, group)
if not response:
return
if isinstance(response, HttpResponseRedirect):
return response
if not isinstance(response, Response):
raise NotImplementedError('Use self.render() when returning responses.')
event = group.get_latest_event() or Event()
event.group = group
request.access = access.from_user(request.user, group.organization)
return response.respond(request, {
'plugin': self,
'project': group.project,
'group': group,
'event': event,
'can_admin_event': request.access.has_scope('event:write'),
'can_remove_event': request.access.has_scope('event:delete'),
})
示例3: tag_list
def tag_list(request, organization, project):
tag_key_qs = sorted(TagKey.objects.filter(
project=project
), key=lambda x: x.get_label())
tag_value_qs = TagValue.objects.filter(
project=project).order_by('-times_seen')
# O(N) db access
tag_list = []
for tag_key in tag_key_qs:
# prevent some excess queries by binding project
tag_key.project = project
tag_values = tag_value_qs.filter(key=tag_key.key)[:5]
for tag_value in tag_values:
tag_value.project = project
tag_list.append((tag_key, tag_values))
return render_to_response('sentry/explore/tag_list.html', {
'SECTION': 'explore',
'project': project,
'team': project.team,
'organization': organization,
'tag_list': tag_list,
'ACCESS': access.from_user(
user=request.user,
organization=organization,
).to_django_context(),
}, request)
示例4: get
def get(self, request, organization):
"""
Retrieve an organization
Return details on an individual organization including various details
such as membership access, features, and teams.
{method} {path}
"""
team_list = list(Team.objects.filter(
organization=organization,
status=TeamStatus.VISIBLE,
))
feature_list = []
if features.has('organizations:sso', organization, actor=request.user):
feature_list.append('sso')
if getattr(organization.flags, 'allow_joinleave'):
feature_list.append('open-membership')
context = serialize(organization, request.user)
context['access'] = access.from_user(request.user, organization).scopes
context['features'] = feature_list
context['teams'] = serialize(
team_list, request.user, TeamWithProjectsSerializer())
return Response(context)
示例5: tag_value_list
def tag_value_list(request, organization, project, key):
tag_key = TagKey.objects.select_related('project').get(
project=project, key=key)
tag_values_qs = TagValue.objects.filter(
project=project, key=key).select_related('project')
sort = request.GET.get('sort')
if sort not in SORT_OPTIONS:
sort = DEFAULT_SORT_OPTION
if sort == 'recent':
tag_values_qs = tag_values_qs.order_by('-last_seen')
elif sort == 'newest':
tag_values_qs = tag_values_qs.order_by('-first_seen')
elif sort == 'events':
tag_values_qs = tag_values_qs.order_by('-times_seen')
return render_to_response('sentry/explore/tag_value_list.html', {
'SECTION': 'explore',
'project': project,
'team': project.team,
'organization': organization,
'SORT_OPTIONS': SORT_OPTIONS,
'sort_label': SORT_OPTIONS[sort],
'tag_key': tag_key,
'tag_values': tag_values_qs,
'ACCESS': access.from_user(
user=request.user,
organization=project.organization,
).to_django_context(),
}, request)
示例6: test_member_no_teams_open_membership
def test_member_no_teams_open_membership(self):
user = self.create_user()
organization = self.create_organization(
owner=self.user,
flags=Organization.flags.allow_joinleave,
)
member = self.create_member(
organization=organization,
user=user,
role='member',
teams=(),
)
team = self.create_team(organization=organization)
project = self.create_project(organization=organization, teams=[team])
result = access.from_user(user, organization)
assert result.sso_is_valid
assert not result.requires_sso
assert result.scopes == member.get_scopes()
assert result.has_team_access(team)
assert result.has_team_scope(team, 'project:read')
assert result.has_project_access(project)
assert result.has_projects_access([project])
assert result.has_project_scope(project, 'project:read')
assert not result.has_project_membership(project)
示例7: serialize
def serialize(self, obj, attrs, user):
from sentry import features
from sentry.app import env
from sentry.api.serializers.models.team import TeamWithProjectsSerializer
team_list = list(Team.objects.filter(organization=obj, status=TeamStatus.VISIBLE))
feature_list = []
if features.has("organizations:events", obj, actor=user):
feature_list.append("events")
if features.has("organizations:sso", obj, actor=user):
feature_list.append("sso")
if getattr(obj.flags, "allow_joinleave"):
feature_list.append("open-membership")
context = super(DetailedOrganizationSerializer, self).serialize(obj, attrs, user)
context["quota"] = {
"maxRate": quotas.get_organization_quota(obj),
"projectLimit": int(
OrganizationOption.objects.get_value(organization=obj, key="sentry:project-rate-limit", default=100)
),
}
context["teams"] = serialize(team_list, user, TeamWithProjectsSerializer())
if env.request:
context["access"] = access.from_request(env.request, obj).scopes
else:
context["access"] = access.from_user(user, obj).scopes
context["features"] = feature_list
context["pendingAccessRequests"] = OrganizationAccessRequest.objects.filter(team__organization=obj).count()
return context
示例8: serialize
def serialize(self, obj, attrs, user):
from sentry import features
from sentry.api.serializers.models.team import TeamWithProjectsSerializer
team_list = list(Team.objects.filter(
organization=obj,
status=TeamStatus.VISIBLE,
))
feature_list = []
if features.has('organizations:sso', obj, actor=user):
feature_list.append('sso')
if getattr(obj.flags, 'allow_joinleave'):
feature_list.append('open-membership')
context = super(DetailedOrganizationSerializer, self).serialize(
obj, attrs, user)
context['teams'] = serialize(
team_list, user, TeamWithProjectsSerializer())
context['access'] = access.from_user(user, obj).scopes
context['features'] = feature_list
context['pendingAccessRequests'] = OrganizationAccessRequest.objects.filter(
team__organization=obj,
).count()
return context
示例9: test_anonymous_user
def test_anonymous_user(self):
user = self.create_user()
anon_user = AnonymousUser()
organization = self.create_organization(owner=user)
result = access.from_user(anon_user, organization)
assert not result.is_active
示例10: get_default_context
def get_default_context(request, existing_context=None, team=None):
from sentry.plugins import plugins
context = {
'EVENTS_PER_PAGE': EVENTS_PER_PAGE,
'URL_PREFIX': settings.SENTRY_URL_PREFIX,
'SINGLE_ORGANIZATION': settings.SENTRY_SINGLE_ORGANIZATION,
'PLUGINS': plugins,
'ALLOWED_HOSTS': settings.ALLOWED_HOSTS,
'SENTRY_RAVEN_JS_URL': settings.SENTRY_RAVEN_JS_URL,
}
if existing_context:
if team is None and 'team' in existing_context:
team = existing_context['team']
if 'project' in existing_context:
project = existing_context['project']
else:
project = None
else:
project = None
if team:
organization = team.organization
elif project:
organization = project.organization
else:
organization = None
if request:
context.update({
'request': request,
})
if (not existing_context or 'TEAM_LIST' not in existing_context) and team:
context['TEAM_LIST'] = Team.objects.get_for_user(
organization=team.organization,
user=request.user,
with_projects=True,
)
user = request.user
else:
user = AnonymousUser()
if organization:
context['selectedOrganization'] = serialize(organization, user)
if team:
context['selectedTeam'] = serialize(team, user)
if project:
context['selectedProject'] = serialize(project, user)
if not existing_context or 'ACCESS' not in existing_context:
context['ACCESS'] = access.from_user(
user=user,
organization=organization,
).to_django_context()
return context
示例11: group_list
def group_list(request, organization, project):
query = request.GET.get("query")
if query and uuid_re.match(query):
# Forward to event if it exists
try:
group_id = EventMapping.objects.filter(project=project, event_id=query).values_list("group", flat=True)[0]
except IndexError:
pass
else:
return HttpResponseRedirect(
reverse(
"sentry-group",
kwargs={
"project_id": project.slug,
"organization_slug": project.organization.slug,
"group_id": group_id,
},
)
)
response = _get_group_list(request=request, project=project)
if isinstance(response, HttpResponse):
return response
# XXX: this is duplicate in _get_group_list
sort_label = SORT_OPTIONS[response["sort"]]
has_realtime = not request.GET.get("cursor")
query_dict = request.GET.copy()
if "cursor" in query_dict:
del query_dict["cursor"]
cursorless_query_string = query_dict.urlencode()
GroupMeta.objects.populate_cache(response["event_list"])
return render_to_response(
"sentry/groups/group_list.html",
{
"team": project.team,
"organization": organization,
"project": project,
"from_date": response["date_from"],
"to_date": response["date_to"],
"date_type": response["date_type"],
"has_realtime": has_realtime,
"event_list": response["event_list"],
"prev_cursor": response["prev_cursor"],
"next_cursor": response["next_cursor"],
"today": response["today"],
"sort": response["sort"],
"query": query,
"cursorless_query_string": cursorless_query_string,
"sort_label": sort_label,
"SORT_OPTIONS": SORT_OPTIONS,
"ACCESS": access.from_user(user=request.user, organization=organization).to_django_context(),
},
request,
)
示例12: render_with_group_context
def render_with_group_context(group, template, context, request=None,
event=None, is_public=False):
context.update({
'team': group.project.team,
'organization': group.project.organization,
'project': group.project,
'group': group,
})
if request and request.user.is_authenticated():
context['ACCESS'] = access.from_user(
user=request.user,
organization=group.organization,
).to_django_context()
else:
context['ACCESS'] = access.DEFAULT.to_django_context()
if event:
if event.id:
# TODO(dcramer): we dont want to actually use gt/lt here as it should
# be inclusive. However, that would need to ensure we have some kind
# of way to know which event was the previous (an offset), or to add
# a third sort key (which is not yet indexed)
base_qs = group.event_set.exclude(id=event.id)
try:
next_event = base_qs.filter(
datetime__gt=event.datetime,
).order_by('datetime')[0:1].get()
except Event.DoesNotExist:
next_event = None
try:
prev_event = base_qs.filter(
datetime__lt=event.datetime,
).order_by('-datetime')[0:1].get()
except Event.DoesNotExist:
prev_event = None
else:
next_event = None
prev_event = None
if not is_public:
extra_data = event.data.get('extra', {})
if not isinstance(extra_data, dict):
extra_data = {}
context.update({
'tags': event.get_tags(),
'json_data': extra_data,
})
context.update({
'event': event,
'version_data': event.data.get('modules', None),
'next_event': next_event,
'prev_event': prev_event,
})
return render_to_response(template, context, request)
示例13: test_anonymous_user
def test_anonymous_user(self):
from django.contrib.auth.models import AnonymousUser
user = self.create_user()
anon_user = AnonymousUser()
organization = self.create_organization(owner=user)
result = access.from_user(anon_user, organization)
assert not result.is_active
示例14: group_list
def group_list(request, organization, project):
query = request.GET.get('query')
if query and uuid_re.match(query):
# Forward to event if it exists
try:
group_id = EventMapping.objects.filter(
project=project, event_id=query
).values_list('group', flat=True)[0]
except IndexError:
pass
else:
return HttpResponseRedirect(reverse('sentry-group', kwargs={
'project_id': project.slug,
'organization_slug': project.organization.slug,
'group_id': group_id,
}))
response = _get_group_list(
request=request,
project=project,
)
if isinstance(response, HttpResponse):
return response
# XXX: this is duplicate in _get_group_list
sort_label = SORT_OPTIONS[response['sort']]
has_realtime = not request.GET.get('cursor')
query_dict = request.GET.copy()
if 'cursor' in query_dict:
del query_dict['cursor']
cursorless_query_string = query_dict.urlencode()
GroupMeta.objects.populate_cache(response['event_list'])
return render_to_response('sentry/groups/group_list.html', {
'team': project.team,
'organization': organization,
'project': project,
'from_date': response['date_from'],
'to_date': response['date_to'],
'date_type': response['date_type'],
'has_realtime': has_realtime,
'event_list': response['event_list'],
'prev_cursor': response['prev_cursor'],
'next_cursor': response['next_cursor'],
'today': response['today'],
'sort': response['sort'],
'query': query,
'cursorless_query_string': cursorless_query_string,
'sort_label': sort_label,
'SORT_OPTIONS': SORT_OPTIONS,
'ACCESS': access.from_user(
user=request.user,
organization=organization,
).to_django_context(),
}, request)
示例15: serialize
def serialize(self, obj, attrs, user):
from sentry import features
from sentry.app import env
from sentry.api.serializers.models.team import TeamWithProjectsSerializer
team_list = list(Team.objects.filter(
organization=obj,
status=TeamStatus.VISIBLE,
))
for team in team_list:
team._organization_cache = obj
onboarding_tasks = list(OrganizationOnboardingTask.objects.filter(
organization=obj,
).select_related('user'))
feature_list = []
if features.has('organizations:sso', obj, actor=user):
feature_list.append('sso')
if features.has('organizations:callsigns', obj, actor=user):
feature_list.append('callsigns')
if features.has('organizations:new-tracebacks', obj, actor=user):
feature_list.append('new-tracebacks')
if features.has('organizations:onboarding', obj, actor=user) and \
not OrganizationOption.objects.filter(organization=obj).exists():
feature_list.append('onboarding')
if features.has('organizations:api-keys', obj, actor=user) or \
ApiKey.objects.filter(organization=obj).exists():
feature_list.append('api-keys')
if getattr(obj.flags, 'allow_joinleave'):
feature_list.append('open-membership')
if not getattr(obj.flags, 'disable_shared_issues'):
feature_list.append('shared-issues')
context = super(DetailedOrganizationSerializer, self).serialize(
obj, attrs, user)
context['quota'] = {
'maxRate': quotas.get_organization_quota(obj),
'projectLimit': int(OrganizationOption.objects.get_value(
organization=obj,
key='sentry:project-rate-limit',
default=100,
)),
}
context['teams'] = serialize(
team_list, user, TeamWithProjectsSerializer())
if env.request:
context['access'] = access.from_request(env.request, obj).scopes
else:
context['access'] = access.from_user(user, obj).scopes
context['features'] = feature_list
context['pendingAccessRequests'] = OrganizationAccessRequest.objects.filter(
team__organization=obj,
).count()
context['onboardingTasks'] = serialize(onboarding_tasks, user, OnboardingTasksSerializer())
return context