• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python superuser.is_active_superuser函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sentry.auth.superuser.is_active_superuser函数的典型用法代码示例。如果您正苦于以下问题:Python is_active_superuser函数的具体用法?Python is_active_superuser怎么用?Python is_active_superuser使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了is_active_superuser函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: get

    def get(self, request):
        status = request.GET.get('status')

        if status == 'published':
            queryset = SentryApp.objects.filter(status=SentryAppStatus.PUBLISHED)

        elif status == 'unpublished':
            if is_active_superuser(request):
                queryset = SentryApp.objects.filter(
                    status=SentryAppStatus.UNPUBLISHED
                )
            else:
                queryset = SentryApp.objects.filter(
                    status=SentryAppStatus.UNPUBLISHED,
                    owner__in=request.user.get_orgs(),
                )
        else:
            if is_active_superuser(request):
                queryset = SentryApp.objects.all()
            else:
                queryset = SentryApp.objects.filter(status=SentryAppStatus.PUBLISHED)

        return self.paginate(
            request=request,
            queryset=queryset,
            order_by='-date_added',
            paginator_cls=OffsetPaginator,
            on_results=lambda x: serialize(x, request.user),
        )
开发者ID:getsentry,项目名称:sentry,代码行数:29,代码来源:sentry_apps.py


示例2: get_projects

    def get_projects(
        self,
        request,
        organization,
        force_global_perms=False,
        include_all_accessible=False,
    ):
        """
        Determines which project ids to filter the endpoint by. If a list of
        project ids is passed in via the `project` querystring argument then
        validate that these projects can be accessed. If not passed, then
        return all project ids that the user can access within this
        organization.

        :param request:
        :param organization: Organization to fetch projects for
        :param force_global_perms: Permission override. Allows subclasses to
        perform their own validation and allow the user to access any project
        in the organization. This is a hack to support the old
        `request.auth.has_scope` way of checking permissions, don't use it
        for anything else, we plan to remove this once we remove uses of
        `auth.has_scope`.
        :param include_all_accessible: Whether to factor the organization
        allow_joinleave flag into permission checks. We should ideally
        standardize how this is used and remove this parameter.
        :return: A list of project ids, or raises PermissionDenied.
        """
        project_ids = set(map(int, request.GET.getlist('project')))

        requested_projects = project_ids.copy()

        user = getattr(request, 'user', None)

        qs = Project.objects.filter(
            organization=organization,
            status=ProjectStatus.VISIBLE,
        )

        if project_ids:
            qs = qs.filter(id__in=project_ids)

        if force_global_perms:
            projects = list(qs)
        else:
            if (
                user and is_active_superuser(request) or
                requested_projects or
                include_all_accessible
            ):
                func = request.access.has_project_access
            else:
                func = request.access.has_project_membership
            projects = [p for p in qs if func(p)]

        project_ids = set(p.id for p in projects)

        if requested_projects and project_ids != requested_projects:
            raise PermissionDenied

        return projects
开发者ID:getsentry,项目名称:sentry,代码行数:60,代码来源:organization.py


示例3: wrapped

 def wrapped(request, *args, **kwargs):
     if not is_active_superuser(request):
         if request.user.is_superuser:
             auth.initiate_login(request, next_url=request.get_full_path())
             return HttpResponseRedirect(auth.get_login_url())
         return render_to_response('sentry/missing_permissions.html', {}, request, status=400)
     return func(request, *args, **kwargs)
开发者ID:Kayle009,项目名称:sentry,代码行数:7,代码来源:decorators.py


示例4: from_request

def from_request(request, organization, scopes=None):
    if not organization:
        return DEFAULT

    if is_active_superuser(request):
        # we special case superuser so that if they're a member of the org
        # they must still follow SSO checks, but they gain global access
        try:
            member = OrganizationMember.objects.get(
                user=request.user,
                organization=organization,
            )
        except OrganizationMember.DoesNotExist:
            requires_sso, sso_is_valid = False, True
        else:
            requires_sso, sso_is_valid = _sso_params(member)

        team_list = list(organization.team_set.all())
        return Access(
            scopes=scopes if scopes is not None else settings.SENTRY_SCOPES,
            is_active=True,
            teams=team_list,
            memberships=team_list,
            sso_is_valid=sso_is_valid,
            requires_sso=requires_sso,
        )
    return from_user(request.user, organization, scopes=scopes)
开发者ID:gencer,项目名称:sentry,代码行数:27,代码来源:access.py


示例5: get

    def get(self, request, *args, **kwargs):
        next_uri = self.get_next_uri(request, *args, **kwargs)
        if request.user.is_authenticated():
            # if the user is a superuser, but not 'superuser authenticated'
            # we allow them to re-authenticate to gain superuser status
            if not request.user.is_superuser or is_active_superuser(request):
                return self.handle_authenticated(request, *args, **kwargs)

        request.session.set_test_cookie()

        # we always reset the state on GET so you dont end up at an odd location
        auth.initiate_login(request, next_uri)

        # Single org mode -- send them to the org-specific handler
        if settings.SENTRY_SINGLE_ORGANIZATION:
            org = Organization.get_default()
            next_uri = reverse('sentry-auth-organization', args=[org.slug])
            return HttpResponseRedirect(next_uri)

        session_expired = 'session_expired' in request.COOKIES
        if session_expired:
            messages.add_message(request, messages.WARNING,
                                 WARN_SESSION_EXPIRED)

        response = self.handle_basic_auth(request, *args, **kwargs)

        if session_expired:
            response.delete_cookie('session_expired')

        return response
开发者ID:hosmelq,项目名称:sentry,代码行数:30,代码来源:auth_login.py


示例6: has_object_permission

    def has_object_permission(self, request, view, project):
        result = super(ProjectPermission,
                       self).has_object_permission(request, view, project.organization)

        if not result:
            return result
        if project.teams.exists():
            return any(
                has_team_permission(request, team, self.scope_map) for team in project.teams.all()
            )
        elif request.user.is_authenticated():
            # this is only for team-less projects
            if is_active_superuser(request):
                return True
            try:
                role = OrganizationMember.objects.filter(
                    organization=project.organization,
                    user=request.user,
                ).values_list('role', flat=True).get()
            except OrganizationMember.DoesNotExist:
                # this should probably never happen?
                return False

            return roles.get(role).is_global
        elif hasattr(request.auth, 'project_id') and project.id == request.auth.project_id:
            return True

        return False
开发者ID:Kayle009,项目名称:sentry,代码行数:28,代码来源:project.py


示例7: post

    def post(self, request):
        if not (is_active_superuser(request) and request.access.has_permission('broadcasts.admin')):
            return self.respond(status=401)

        validator = AdminBroadcastValidator(data=request.DATA)
        if not validator.is_valid():
            return self.respond(validator.errors, status=400)

        result = validator.object

        with transaction.atomic():
            broadcast = Broadcast.objects.create(
                title=result['title'],
                message=result['message'],
                link=result['link'],
                is_active=result.get('isActive') or False,
                date_expires=result.get('expiresAt'),
            )
            logger.info('broadcasts.create', extra={
                'ip_address': request.META['REMOTE_ADDR'],
                'user_id': request.user.id,
                'broadcast_id': broadcast.id,
            })

        if result.get('hasSeen'):
            try:
                with transaction.atomic():
                    BroadcastSeen.objects.create(
                        broadcast=broadcast,
                        user=request.user,
                    )
            except IntegrityError:
                pass

        return self.respond(self._serialize_objects(broadcast, request))
开发者ID:Kayle009,项目名称:sentry,代码行数:35,代码来源:broadcast_index.py


示例8: _serialize_objects

    def _serialize_objects(self, items, request):
        if is_active_superuser(request):
            serializer_cls = AdminBroadcastSerializer
        else:
            serializer_cls = BroadcastSerializer

        return serialize(items, request.user, serializer=serializer_cls())
开发者ID:Kayle009,项目名称:sentry,代码行数:7,代码来源:broadcast_index.py


示例9: get_allowed_projects

    def get_allowed_projects(self, request, organization):
        has_valid_api_key = False
        if isinstance(request.auth, ApiKey):
            if request.auth.organization_id != organization.id:
                return []
            has_valid_api_key = request.auth.has_scope('project:releases') or \
                request.auth.has_scope('project:write')

        if not (has_valid_api_key or request.user.is_authenticated()):
            return []

        if has_valid_api_key or is_active_superuser(request) or organization.flags.allow_joinleave:
            allowed_teams = Team.objects.filter(organization=organization).values_list(
                'id', flat=True
            )
        else:
            allowed_teams = OrganizationMemberTeam.objects.filter(
                organizationmember__user=request.user,
                team__organization_id=organization.id,
            ).values_list(
                'team_id', flat=True
            )

        return Project.objects.filter(
            id__in=ProjectTeam.objects.filter(
                team_id__in=allowed_teams,
            ).values_list('project_id', flat=True)
        )
开发者ID:binlee1990,项目名称:sentry,代码行数:28,代码来源:organization.py


示例10: serialize

    def serialize(self, obj, attrs, user):
        from sentry.mediators.service_hooks.creator import consolidate_events

        data = {
            'name': obj.name,
            'slug': obj.slug,
            'author': obj.author,
            'scopes': obj.get_scopes(),
            'events': consolidate_events(obj.events),
            'status': obj.get_status_display(),
            'schema': obj.schema,
            'uuid': obj.uuid,
            'webhookUrl': obj.webhook_url,
            'redirectUrl': obj.redirect_url,
            'isAlertable': obj.is_alertable,
            'overview': obj.overview,
        }

        if is_active_superuser(env.request) or (
            hasattr(user, 'get_orgs') and obj.owner in user.get_orgs()
        ):
            data.update({
                'clientId': obj.application.client_id,
                'clientSecret': obj.application.client_secret,
                'owner': {
                    'id': obj.owner.id,
                    'slug': obj.owner.slug,
                },
            })

        return data
开发者ID:getsentry,项目名称:sentry,代码行数:31,代码来源:sentry_app.py


示例11: handle

    def handle(self, request, organization):
        try:
            auth_provider = AuthProvider.objects.get(
                organization=organization,
            )
        except AuthProvider.DoesNotExist:
            pass
        else:
            provider = auth_provider.get_provider()
            requires_feature = provider.required_feature

            # Provider is not enabled
            # Allow superusers to edit and disable SSO for orgs that
            # downgrade plans and can no longer access the feature
            if requires_feature and not features.has(
                requires_feature,
                organization,
                actor=request.user
            ) and not is_active_superuser(request):
                home_url = organization.get_url()
                messages.add_message(request, messages.ERROR, ERR_NO_SSO)

                return HttpResponseRedirect(home_url)

            return self.handle_existing_provider(
                request=request,
                organization=organization,
                auth_provider=auth_provider,
            )

        if request.method == 'POST':
            provider_key = request.POST.get('provider')
            if not manager.exists(provider_key):
                raise ValueError(u'Provider not found: {}'.format(provider_key))

            helper = AuthHelper(
                request=request,
                organization=organization,
                provider_key=provider_key,
                flow=AuthHelper.FLOW_SETUP_PROVIDER,
            )

            feature = helper.provider.required_feature
            if feature and not features.has(feature, organization, actor=request.user):
                return HttpResponse('Provider is not enabled', status=401)

            if request.POST.get('init'):
                helper.init_pipeline()

            if not helper.pipeline_is_valid():
                return helper.error('Something unexpected happened during authentication.')

            # render first time setup view
            return helper.current_step()

        # Otherwise user is in bad state since frontend/react should handle this case
        return HttpResponseRedirect(
            organization.get_url()
        )
开发者ID:yaoqi,项目名称:sentry,代码行数:59,代码来源:organization_auth_settings.py


示例12: can

 def can(self, request):
     if 'prof' not in request.GET:
         return False
     if settings.DEBUG:
         return True
     if is_active_superuser(request):
         return True
     return False
开发者ID:Kayle009,项目名称:sentry,代码行数:8,代码来源:profiler.py


示例13: has_object_permission

 def has_object_permission(self, request, view, user=None):
     if user is None:
         user = request.user
     if request.user == user:
         return True
     if request.auth:
         return False
     if is_active_superuser(request):
         return True
     return False
开发者ID:alexandrul,项目名称:sentry,代码行数:10,代码来源:user.py


示例14: get_allowed_roles

    def get_allowed_roles(self, request, organization, member=None):
        can_admin = request.access.has_scope('member:admin')

        allowed_roles = []
        if can_admin and not is_active_superuser(request):
            acting_member = OrganizationMember.objects.get(
                user=request.user,
                organization=organization,
            )
            if member and roles.get(acting_member.role).priority < roles.get(member.role).priority:
                can_admin = False
            else:
                allowed_roles = [
                    r for r in roles.get_all()
                    if r.priority <= roles.get(acting_member.role).priority
                ]
                can_admin = bool(allowed_roles)
        elif is_active_superuser(request):
            allowed_roles = roles.get_all()
        return (can_admin, allowed_roles, )
开发者ID:yaoqi,项目名称:sentry,代码行数:20,代码来源:base.py


示例15: _get_identities

    def _get_identities(self, item_list, user):
        if not (env.request and is_active_superuser(env.request)):
            item_list = [x for x in item_list if x == user]

        queryset = AuthIdentity.objects.filter(
            user__in=item_list,
        ).select_related('auth_provider', 'auth_provider__organization')

        results = {i.id: [] for i in item_list}
        for item in queryset:
            results[item.user_id].append(item)
        return results
开发者ID:hosmelq,项目名称:sentry,代码行数:12,代码来源:user.py


示例16: _can_access

    def _can_access(self, request, member):
        # TODO(dcramer): ideally org owners/admins could perform these actions
        if is_active_superuser(request):
            return True

        if not request.user.is_authenticated():
            return False

        if request.user.id == member.user_id:
            return True

        return False
开发者ID:gencer,项目名称:sentry,代码行数:12,代码来源:organization_member_team_details.py


示例17: show_toolbar_for_request

 def show_toolbar_for_request(self, request):
     # This avoids touching user session, which means we avoid
     # setting `Vary: Cookie` as a response header which will
     # break HTTP caching entirely.
     if request.path_info.startswith(settings.ANONYMOUS_STATIC_PREFIXES):
         return
     if not settings.SENTRY_DEBUGGER:
         return False
     if not is_active_superuser(request):
         return False
     if 'text/html' not in request.META.get('HTTP_ACCEPT', '*/*'):
         return False
     return True
开发者ID:Kayle009,项目名称:sentry,代码行数:13,代码来源:middleware.py


示例18: _get_broadcast

    def _get_broadcast(self, request, broadcast_id):
        if is_active_superuser(request) and request.access.has_permission('broadcasts.admin'):
            queryset = Broadcast.objects.all()
        else:
            queryset = Broadcast.objects.filter(
                Q(date_expires__isnull=True) | Q(date_expires__gt=timezone.now()),
                is_active=True,
            )

        try:
            return queryset.get(id=broadcast_id)
        except Broadcast.DoesNotExist:
            raise ResourceDoesNotExist
开发者ID:Kayle009,项目名称:sentry,代码行数:13,代码来源:broadcast_details.py


示例19: convert_args

    def convert_args(self, request, organization_slug, *args, **kwargs):
        if is_active_superuser(request):
            organizations = Organization.objects.all()
        else:
            organizations = request.user.get_orgs()

        try:
            organization = organizations.get(slug=organization_slug)
        except Organization.DoesNotExist:
            raise Http404
        self.check_object_permissions(request, organization)

        kwargs['organization'] = organization
        return (args, kwargs)
开发者ID:getsentry,项目名称:sentry,代码行数:14,代码来源:sentryapps.py


示例20: put

    def put(self, request, user):
        """
        Update Account Appearance options
        `````````````````````````````````

        Update account appearance options. Only supplied values are updated.

        :pparam string user_id: user id
        :param string language: language preference
        :param string stacktrace_order: One of -1 (default), 1 (most recent call last), 2 (most recent call first).
        :param string timezone: timezone option
        :param clock_24_hours boolean: use 24 hour clock
        :auth: required
        """

        if is_active_superuser(request):
            serializer_cls = AdminUserSerializer
        else:
            serializer_cls = UserSerializer
        serializer = serializer_cls(user, data=request.DATA, partial=True)

        serializer_options = UserOptionsSerializer(
            data=request.DATA.get('options', {}), partial=True)

        # This serializer should NOT include privileged fields e.g. password
        if not serializer.is_valid() or not serializer_options.is_valid():
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

        # map API keys to keys in model
        key_map = {
            'language': 'language',
            'timezone': 'timezone',
            'stacktraceOrder': 'stacktrace_order',
            'clock24Hours': 'clock_24_hours',
            'seenReleaseBroadcast': 'seen_release_broadcast',
        }

        options_result = serializer_options.object

        for key in key_map:
            if key in options_result:
                UserOption.objects.set_value(
                    user=user,
                    key=key_map.get(key, key),
                    value=options_result.get(key),
                )

        user = serializer.save()

        return Response(serialize(user, request.user, DetailedUserSerializer()))
开发者ID:binlee1990,项目名称:sentry,代码行数:50,代码来源:user_details.py



注:本文中的sentry.auth.superuser.is_active_superuser函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python default_cache.get函数代码示例发布时间:2022-05-27
下一篇:
Python access.from_user函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap