def SaveRoleRoleScope(request): try: targetRoleId = request.POST['targetRoleId'] except: targetRoleId = None try: roleIds = request.POST['roleIds'] except: roleIds = None response = HttpResponse() if not targetRoleId: response.content = json.dumps({'Success': True, 'Data': '-1', 'Message': '角色主键为空!'}) return response try: tmpRoleIds = RolePermission.GetScopeRoleIdsByRoleId(None, targetRoleId, "Resource.ManagePermission") if not roleIds: if tmpRoleIds and len(tmpRoleIds) > 0: RolePermission.RevokeRoleRoleScope(None, targetRoleId, "Resource.ManagePermission", tmpRoleIds) else: #revokeIds = list(set(tmpRoleIds) ^ set(str(roleIds).split(','))) revokeIds = [] for r in tmpRoleIds: if r not in roleIds: revokeIds.append(r) #grantIds = list(set(str(roleIds).split(',')) ^ set(tmpRoleIds)) grantIds = [] for g in str(roleIds).split(','): if g not in tmpRoleIds: grantIds.append(g) if len(grantIds) > 0: RolePermission.GrantRoleRoleScope(CommonUtils.Current(response, request), targetRoleId, "Resource.ManagePermission", grantIds) if len(revokeIds) > 0: RolePermission.RevokeRoleRoleScope(None, targetRoleId, "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
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