def BatchDelete(userInfo, ids): """ 单个删除用户 Args: ids (string[]): 用户主键列表 Returns: returnValue (True or False): 删除结果 """ # 已删除用户Piuser表中的DELETEMARK设置为1 LogService.WriteLog(userInfo, __class__.__name__, FrameworkMessage.UserService, sys._getframe().f_code.co_name, FrameworkMessage.UserService_BatchDelete, str(ids)) try: user = Piuser.objects.filter(id__in=ids) if len(user) == 0: return False user.update(deletemark=1) except Exception as e: return False # 用户已经被删除的员工的UserId设置为Null Pistaff.objects.filter(userid__in=Piuser.objects.filter( id__in=ids)).update(userid=None) # 清除用户的操作权限 for id in ids: UserPermission.ClearUserPermissionByUserId(None, id) return True
def Delete(userInfo, id): """ 单个删除用户 Args: id (string): 主键 Returns: returnValue (True or False): 删除结果 """ LogService.WriteLog(userInfo, __class__.__name__, FrameworkMessage.UserService, sys._getframe().f_code.co_name, FrameworkMessage.UserService_Delete, id) try: #已删除用户Piuser表中的DELETEMARK设置为1 try: user = Piuser.objects.get(id=id) except Piuser.DoesNotExist as e: return False user.deletemark = 1 user.save() #用户已经被删除的员工的UserId设置为Null Pistaff.objects.filter(userid__in=Piuser.objects.filter( deletemark=1)).update(userid=None) # 清除用户的操作权限 UserPermission.ClearUserPermissionByUserId(None, id) return True except Exception as e: return False
def SavePermissionItemScope(request): try: targetUserId = request.POST['targetUserId'] except: targetUserId = None try: permissionItemIds = request.POST['permissionItemIds'] except: permissionItemIds = None response = HttpResponse() if not targetUserId: response.content = json.dumps({'Success': True, 'Data': '-1', 'Message': '用户主键为空!'}) return response try: tmpScopeIds = UserPermission.GetScopePermissionItemIdsByUserId(None, targetUserId, "Resource.ManagePermission") if not permissionItemIds: if tmpScopeIds and len(tmpScopeIds) > 0: UserPermission.RevokeUserPermissionItemScope(None, targetUserId, "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: UserPermission.GrantUserPermissionItemScope(CommonUtils.Current(response, request), targetUserId, "Resource.ManagePermission", grantIds) if len(revokeIds) > 0: UserPermission.RevokeUserPermissionItemScope(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
def GetPermissionItemsByUserId(request): try: userId = request.POST['userId'] except: userId = None if userId: ids = UserPermission.GetUserPermissionItemIds(None, userId) returnValue = StringHelper.GetSpitString(ids, ',') response = HttpResponse() response.content = returnValue return response else: response = HttpResponse() response.content = '' return response
def LoadTreeMenu(request): """ 加载无限树菜单 Args: Returns: """ try: moduleId = request.POST['moduleId'] except: moduleId = '84CA44CB-8A0F-43A1-BD86-1ED764216C59' response = HttpResponse() list = None if CommonUtils.Current(response, request).IsAdministrator: list = ModuleService.GetList(ModuleService) else: list = UserPermission.GetModuleDTByUserId( None, CommonUtils.Current(response, request), CommonUtils.Current(response, request).Id) listWhere = list.filter( Q(moduletype=None) | Q(moduletype=2) | Q(moduletype=3) | Q(ispublic=1)) treeList = [] for item in listWhere: tree = TreeJsonEntity() hasChildren = False for i in list: if i.parentid == item.id: hasChildren = True break tree.id = item.id tree.text = item.fullname tree.value = item.id tree.url = item.mvcnavigateurl tree.title = item.fullname tree.isExpand = item.expand tree.hasChildren = hasChildren tree.parentId = item.parentid if item.iconcss: tree.iconCls = item.iconcss.replace('icon ', '') else: tree.iconCls = '' treeList.append(tree) response.content = TreeJsonEntity.TreeToJson(treeList, moduleId) return response
def GetModuleByUserId(request): try: userId = request.POST['userId'] except: userId = None if userId: moduleIds = UserPermission.GetScopeModuleIdsByUserId( None, userId, "Resource.AccessPermission") returnValue = StringHelper.GetSpitString(moduleIds, ',') response = HttpResponse() response.content = returnValue return response else: response = HttpResponse() response.content = '' return response
def GetScopePermissionItemIdsByUserId(request): try: userId = request.POST['userId'] except: userId = None if userId: scopeIds = UserPermission.GetScopePermissionItemIdsByUserId(None, userId, "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
def SetDeleted(userInfo, ids): """ 批量打删除标志 Args: ids (string[]): 用户主键列表 Returns: returnValue (True or False): 影响行数 """ LogService.WriteLog(userInfo, __class__.__name__, FrameworkMessage.UserService, sys._getframe().f_code.co_name, FrameworkMessage.UserService_SetDeleted, str(ids)) try: user = Piuser.objects.filter(id__in=ids) if len(user) == 0: return False user.update(deletemark=1) except Exception as e: return False # 清除用户的操作权限 for id in ids: UserPermission.ClearUserPermissionByUserId(None, id) return True
def SetUserPermissionItem(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.GrantUserPermissions( CommonUtils.Current(response, request), [userId], arrayGrantIds) else: successFlag = 1 if revokeIds and (revokeIds != ','): arrayRevokeIds = str(revokeIds).strip(',').split(',') if len(arrayRevokeIds) > 0: successFlag = successFlag + UserPermission.RevokeUserPermissions( None, [userId], 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