Exemple #1
0
    def has_permission(self, request, view):
        project_id = view.kwargs.get("project_id")
        if not project_id:
            return True

        if request.user.is_superuser:
            return True

        access_token = request.user.token.access_token
        user_id = request.user.username

        project_code = self.get_project_code(access_token, project_id)
        if not project_code:
            return False

        if settings.REGION == 'ce':
            perm = permissions.ProjectPermission()
            return perm.can_view(user_id, project_id)
        else:
            # 实际调用paas_auth.verify_project
            verify = bcs_perm.verify_project_by_user(access_token=access_token,
                                                     project_id=project_id,
                                                     project_code=project_code,
                                                     user_id=user_id)
            return verify
Exemple #2
0
    def has_permission(self, request, view):
        project_id = view.kwargs.get("project_id")
        if not project_id:
            return True

        user_id = request.user.username
        perm = permissions.ProjectPermission()
        return perm.can_view(user_id, project_id)
Exemple #3
0
    def has_permission(self, request, view):
        project_id = view.kwargs.get("project_id")
        if not project_id:
            return True

        access_token = request.user.token.access_token
        user_id = request.user.username

        project_code = self.get_project_code(access_token, project_id)
        if not project_code:
            return False

        perm = permissions.ProjectPermission()
        return perm.can_view(user_id, project_id)
Exemple #4
0
    def has_permission(self, request, view):
        project_id = view.kwargs.get("project_id")
        if not project_id:
            return True

        if request.user.is_superuser:
            return True

        user_id = request.user.username

        if settings.REGION == 'ce':
            perm = permissions.ProjectPermission()
            return perm.can_view(user_id, project_id)
        else:
            access_token = request.user.token.access_token
            result = paas_auth.verify_project(access_token, project_id,
                                              user_id)
            if result.get('code') == 0:
                return True
            return False
Exemple #5
0
    def has_permission(self, request, view):
        if request.user.is_superuser:
            return True

        access_token = request.user.token.access_token
        user_id = request.user.username

        project_id_or_code = view.kwargs.get('project_id') or view.kwargs.get(
            'project_id_or_code')
        project_id = self._get_project_id(access_token, project_id_or_code)
        if not project_id:
            return False

        if settings.REGION == 'ce':
            # 私有化版本对接权限中心v3。如果用户有project的view权限,则返回True
            perm = permissions.ProjectPermission()
            return perm.can_view(user_id, project_id)
        else:
            # 实际调用paas_auth.verify_project(权限中心v0)
            return bcs_perm.verify_project_by_user(access_token=access_token,
                                                   project_id=project_id,
                                                   project_code="",
                                                   user_id=user_id)