Example #1
0
    def IsAdministrator(entity):
        """
        当前用户是否超级管理员
        Args:
            userInfo (UserInfo): 用户
        Returns:
            returnValue(True or False): 当前用户是否为超级管理员,true:是,false:否
        """
        returnValue = False
        userEntity = Piuser.objects.get(id=entity.id)
        if userEntity.id == 'Administrator':
            return True
        if userEntity.code and userEntity.code == 'Administrator':
            return True
        if userEntity.username and userEntity.username == 'Administrator':
            return True

        #TODO:if (this.UserInfo == null) return false;

        #用户的默认角色是超级管理员
        roleEntity = None
        if userEntity.roleid:
            roleIds = UserRoleService.GetRoleIds(userEntity.id)
            for tmpid in roleIds:
                if tmpid == DefaultRole.Administrators:
                    return True
                roleEntity = Pirole.objects.get(id=tmpid)
                if roleEntity.code and roleEntity.code == DefaultRole.Administrators:
                    return True
        return False
Example #2
0
    def GetUserPageDTByDepartment(self,
                                  userInfo,
                                  permissionScopeCode,
                                  searchValue,
                                  enabled,
                                  auditStates,
                                  roleIds,
                                  showRole,
                                  userAllInformation,
                                  pageIndex=0,
                                  pageSize=100,
                                  sort=None,
                                  departmentId=None):
        #TODO:还需要完善此方法
        if not departmentId:
            departmentId = ''

        myrecordCount = 0
        myrecordCount, dt = UserSerivce.SearchByPage(
            self, userInfo, permissionScopeCode, searchValue, roleIds, enabled,
            auditStates, departmentId, pageIndex, pageSize)

        if showRole:
            #这里是获取角色列表
            dataTableRole = RoleService.GetDT(None)
            #友善的显示属于多个角色的功能
            roleName = ''
            for user in dt:
                roleName = ''
                roleIds = UserRoleService.GetRoleIds(user['ID'])
                if roleIds:
                    for i in roleIds:
                        roleName = roleName + dataTableRole.filter(
                            id=i)[0].realname + ", "
                if roleName:
                    roleName = roleName.strip(", ")
                    user['ROLENAME'] = roleName
        return myrecordCount, dt