def GetEntity(request): try: key = request.POST['key'] except: key = None entity = ModuleService.GetEntity(None, key) response = HttpResponse() response.content = entity.toJSON() return response
def GetModuleScope(response, request, permissionItemScopeCode): vUser = CommonUtils.Current(response, request) if vUser.IsAdministrator or (not permissionItemScopeCode) or ( not SystemInfo.EnableUserAuthorizationScope): dtModule = ModuleService.GetDT(None) return dtModule else: dataTable = ScopPermission.GetModuleDTByPermissionScope( None, vUser.Id, permissionItemScopeCode) return dataTable
def GetModuleDTByUserId(self, userInfo, userId): """ 获得指定用户有权限访问的模块 Args: userId (string): 用户主键 Returns: returnValue(Pimodule[]): 模块数据表 """ if userInfo.IsAdministrator: returnValue = Pimodule.objects.filter(Q(deletemark=0) & Q(enabled=1)).order_by('sortcode').values_list('id', flat=True) else: returnValue = ModuleService.GetDTByUser(self, userId) return returnValue
def GetModuleByIds(request): moduleIds = None try: moduleIds = request.POST['moduleIds'] except: moduleIds = None dtPermissionItem = ModuleService.GetDTByIds(None, str(moduleIds).split(",")) treeData = GetJsonData(dtPermissionItem) treeData = treeData.replace("icon ", "").replace("\"iconcss\"", "\"iconCls\"") response = HttpResponse() response.content = treeData return response
def GetModuleIdsByUserId(self, userInfo, userId): """ 获取用户有权限访问的模块 Args: userInfo (UserInfo): 当前用户 userId (string): 用户主键 Returns: returnValue(string[]): 模块主键数组 """ if userInfo.IsAdministrator: returnValue = Pimodule.objects.filter(Q(deletemark=0) & Q(enabled=1)).values_list('id', flat=True) else: returnValue = ModuleService.GetIDsByUser(self, userId) return returnValue
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 IsModuleAuthorizedByUserId(self, userId, moduleCode): """ 指定用户是否对某个模块有相应的权限 Args: userId (string): 用户 moduleCode (string): 模块编码 Returns: returnValue(True or False): 是否有权限,true:是,false:否 """ returnValue = False userEntity = Piuser.objects.get(id=userId) returnValue = PermissionService.IsAdministrator(self, userEntity) if not returnValue: dateTable = ModuleService.GetDTByUser(self, userId) for module in dateTable: if module.code == moduleCode: returnValue = True return returnValue
def Delete(request): try: key = request.POST['key'] except: key = '' returnValue = ModuleService.SetDeleted(None, [key]) if returnValue: response = HttpResponse() response.content = json.dumps({ 'Success': True, 'Data': '1', 'Message': FrameworkMessage.MSG0013 }) return response else: response = HttpResponse() response.content = json.dumps({ 'Success': False, 'Data': '0', 'Message': FrameworkMessage.MSG3020 }) return response
def SubmitForm(request): try: IsOk = '1' try: key = request.GET['key'] except: key = None response = HttpResponse() curUser = CommonUtils.Current(response, request) if not key: module = Pimodule() module = module.loadJson(request) if not module.moduletype: module.moduletype = 6 if not module.parentid: module.parentid = None if not module.navigateurl: module.navigateurl = '#' module.id = uuid.uuid4() # user.isstaff = 0 # user.isvisible = 1 # user.isdimission = 0 module.deletemark = 0 module.createon = datetime.datetime.now().strftime( '%Y-%m-%d %H:%M:%S') module.createby = curUser.RealName module.createuserid = curUser.Id module.modifiedon = datetime.datetime.now().strftime( '%Y-%m-%d %H:%M:%S') module.modifiedby = curUser.RealName module.enabled = 1 returnCode, returnMessage, returnValue = ModuleService.Add( None, module) if returnCode == StatusCode.statusCodeDic['OKAdd']: response.content = json.dumps({ 'Success': True, 'Data': IsOk, 'Message': returnMessage }) return response elif returnCode == StatusCode.statusCodeDic['ErrorCodeExist']: response.content = json.dumps({ 'Success': False, 'Data': '0', 'Message': '编码或名称重复' }) return response else: response.content = json.dumps({ 'Success': False, 'Data': '0', 'Message': returnMessage }) return response else: module = ModuleService.GetEntity(None, key) if module: module = module.loadJson(request) if curUser: module.modifiedby = curUser.RealName module.modifieduserid = curUser.Id module.modifiedon = datetime.datetime.now() returnCode, returnMessage = ModuleService.Update(None, module) if returnCode == StatusCode.statusCodeDic['OKUpdate']: response.content = json.dumps({ 'Success': True, 'Data': IsOk, 'Message': returnMessage }) return response else: response.content = json.dumps({ 'Success': False, 'Data': '0', 'Message': returnMessage }) return response except Exception as e: print(e) response = HttpResponse() response.content = json.dumps({ 'Success': False, 'Data': '0', 'Message': FrameworkMessage.MSG3020 }) return response