def SaveModuleScope(request):
    try:
        targetUserId = request.POST['targetUserId']
    except:
        targetUserId = None

    try:
        moduleIds = request.POST['moduleIds']
    except:
        moduleIds = None

    response = HttpResponse()

    if not targetUserId:
        response.content = json.dumps({'Success': True, 'Data': '-1', 'Message': '用户主键为空!'})
        return response

    try:
        tmpModuleIds = UserPermission.GetScopeModuleIdsByUserId(None, targetUserId, "Resource.ManagePermission")

        if not moduleIds:
            if tmpModuleIds and len(tmpModuleIds) > 0:
                UserPermission.RevokeUserModuleScope(None, targetUserId, "Resource.ManagePermission", tmpModuleIds)
        else:

            #revokeIds = list(set(tmpRoleIds) ^ set(str(roleIds).split(',')))
            revokeIds = []
            for r in tmpModuleIds:
                if r not in moduleIds:
                    revokeIds.append(r)

            #grantIds = list(set(str(roleIds).split(',')) ^ set(tmpRoleIds))
            grantIds = []
            for g in str(moduleIds).split(','):
                if g not in tmpModuleIds:
                    grantIds.append(g)

            if len(grantIds) > 0:
                UserPermission.GrantUserModuleScope(CommonUtils.Current(response, request), targetUserId, "Resource.ManagePermission", grantIds)

            if len(revokeIds) > 0:
                UserPermission.RevokeUserModuleScope(None, targetUserId, "Resource.ManagePermission", revokeIds)
        response.content = json.dumps({'Success': True, 'Data': '1', 'Message': "授权成功!"})
        return response
    except:
        response.content = json.dumps({'Success': False, 'Data': '-2', 'Message': '操作失败!'})
        return response
Exemplo n.º 2
0
def SetUserModulePermission(request):
    try:
        userId = request.POST['userId']
    except:
        userId = None

    try:
        grantIds = request.POST['grantIds']
    except:
        grantIds = None

    try:
        revokeIds = request.POST['revokeIds']
    except:
        revokeIds = None

    response = HttpResponse()
    vUser = CommonUtils.Current(response, request)

    if not userId:
        response.content = json.dumps({
            'Success': False,
            'Data': '0',
            'Message': '请选择相应的用户!'
        })
        return response

    successFlag = 0

    if grantIds and (grantIds != ','):
        arrayGrantIds = str(grantIds).strip(',').split(',')
        if len(arrayGrantIds) > 0:
            successFlag = successFlag + UserPermission.GrantUserModuleScope(
                CommonUtils.Current(response, request), userId,
                "Resource.AccessPermission", arrayGrantIds)
        else:
            successFlag = 1

    if revokeIds and (revokeIds != ','):
        arrayRevokeIds = str(revokeIds).strip(',').split(',')
        if len(arrayRevokeIds) > 0:
            successFlag = successFlag + UserPermission.RevokeUserModuleScope(
                None, userId, "Resource.AccessPermission", arrayRevokeIds)
        else:
            successFlag = 1

    if successFlag > 0:
        successFlag = 1
        response.content = json.dumps({
            'Success': True,
            'Data': '1',
            'Message': '操作成功!'
        })
        return response
    else:
        response.content = json.dumps({
            'Success': False,
            'Data': '0',
            'Message': '操作失败!'
        })
        return response