Пример #1
0
def SetRolePermissionItem(request):
    try:
        roleId = request.POST['roleId']
    except:
        roleId = 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 roleId:
        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 + RolePermission.GrantRolePermissions(
                vUser, [roleId], arrayGrantIds)
        else:
            successFlag = 1

    if revokeIds and (revokeIds != ','):
        arrayRevokeIds = str(revokeIds).strip(',').split(',')
        if len(arrayRevokeIds) > 0:
            successFlag = successFlag + RolePermission.RevokeRolePermissions(
                None, [roleId], 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
def SaveRolePermissionItemScope(request):
    try:
        targetRoleId = request.POST['targetRoleId']
    except:
        targetRoleId = None

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

    response = HttpResponse()

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

    try:
        tmpScopeIds = RolePermission.GetScopePermissionItemIdsByRoleId(None, targetRoleId, "Resource.ManagePermission")

        if not permissionItemIds:
            if tmpScopeIds and len(tmpScopeIds) > 0:
                RolePermission.RevokeRolePermissionItemScope(None, targetRoleId, "Resource.ManagePermission", tmpScopeIds)
        else:

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

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

            if len(grantIds) > 0:
                RolePermission.GrantRolePermissionItemScope(CommonUtils.Current(response, request), targetRoleId, "Resource.ManagePermission", grantIds)

            if len(revokeIds) > 0:
                RolePermission.RevokeRolePermissionItemScope(None, targetRoleId, "Resource.ManagePermission", revokeIds)
        response.content = json.dumps({'Success': True, 'Data': '1', 'Message': "授权成功!"})
        return response
    except Exception as e:
        print(e)
        response.content = json.dumps({'Success': False, 'Data': '-2', 'Message': '操作失败!'})
        return response
Пример #3
0
def GetPermissionItemsByRoleId(request):
    try:
        roleId = request.POST['roleId']
    except:
        roleId = None

    if roleId:
        ids = RolePermission.GetRolePermissionItemIds(None, roleId)
        returnValue = StringHelper.GetSpitString(ids, ',')
        response = HttpResponse()
        response.content = returnValue
        return response
    else:
        response = HttpResponse()
        response.content = ''
        return response
Пример #4
0
def GetModuleByRoleId(request):
    try:
        roleId = request.POST['roleId']
    except:
        roleId = None

    if roleId:
        moduleIds = RolePermission.GetScopeModuleIdsByRoleId(
            None, roleId, "Resource.AccessPermission")
        returnValue = StringHelper.GetSpitString(moduleIds, ',')
        response = HttpResponse()
        response.content = returnValue
        return response
    else:
        response = HttpResponse()
        response.content = ''
        return response
def GetScopeRoleIdsByRoleId(request):
    try:
        roleId = request.POST['roleId']
    except:
        roleId = None
    if roleId:
        scopeIds = RolePermission.GetScopeRoleIdsByRoleId(None, roleId, "Resource.ManagePermission")
        returnValue = '['
        for id in scopeIds:
            returnValue = returnValue + '"' + id + '",'
        returnValue = returnValue.strip(',')
        returnValue = returnValue + ']'
        response = HttpResponse()
        response.content = returnValue
        return response
    else:
        response = HttpResponse()
        response.content = '[]'
        return response