Ejemplo n.º 1
0
        /// <summary>
        /// 获取用户可(查看、编辑、删除)模块中哪些组织下的数据,
        /// 返回可(查看、编辑、删除)的组织Id集合
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="moduleId">模块Id</param>
        /// <param name="dataPermissionType">数据权限类型,0-查看,1-编辑,2-删除</param>
        /// <returns>返回组织Id集合字典</returns>
        public List <string> GetUserDataPermissions(Guid userId, Guid moduleId, int dataPermissionType)
        {
            List <string> orgIds = new List <string>();
            //如果存在用户自定义权限则取自定义用户权限
            string errMsg = string.Empty;
            BaseDAL <Sys_UserPermissionData> userPermissionDal = new BaseDAL <Sys_UserPermissionData>(this.CurrUser);
            Sys_UserPermissionData           permissionData    = userPermissionDal.GetEntity(out errMsg, x => x.Sys_UserId == userId && x.Sys_ModuleId == moduleId && !x.IsDeleted);
            string orgIdsStr = string.Empty;

            if (permissionData != null)
            {
                orgIdsStr = dataPermissionType == 0 ? permissionData.CanViewOrgIds :
                            (dataPermissionType == 1 ? permissionData.CanEditOrgIds : permissionData.CanDelOrgIds);
            }
            if (!string.IsNullOrWhiteSpace(orgIdsStr))
            {
                string[] token = orgIdsStr.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                if (token.Contains("-1"))
                {
                    return new List <string>()
                           {
                               "-1"
                           }
                }
                ;
                foreach (string orgId in token)
                {
                    if (!orgIds.Contains(orgId))
                    {
                        orgIds.Add(orgId);
                    }
                }
                return(orgIds);
            }
            //取用户角色权限
            List <Guid> roleIds = ObjectReferenceClass.GetUserRoleIds(userId);

            foreach (Guid roleId in roleIds)
            {
                Dictionary <string, bool> tempOrgIds = GetRoleDataPermissions(roleId, moduleId, dataPermissionType, true);
                if (tempOrgIds.ContainsKey("-1"))
                {
                    return new List <string>()
                           {
                               "-1"
                           }
                }
                ;
                foreach (string orgId in tempOrgIds.Keys)
                {
                    if (!orgIds.Contains(orgId))
                    {
                        orgIds.Add(orgId);
                    }
                }
            }
            return(orgIds);
        }
    }
}
Ejemplo n.º 2
0
        /// <summary>
        /// 获取用户(查看、新增、编辑)字段权限
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="moduleId">模块Id</param>
        /// <param name="fieldPermissionType">字段权限类型,0-查看,1-新增,2-编辑</param>
        /// <returns>返回允许(查看、新增、编辑)的字段名集合</returns>
        public List <string> GetUserFieldsPermissions(Guid userId, Guid moduleId, int fieldPermissionType)
        {
            List <string> fieldNames = new List <string>();
            //如果存在用户自定义权限则取自定义用户权限
            string errMsg = string.Empty;
            BaseDAL <Sys_UserPermissionField> userPermissionDal = new BaseDAL <Sys_UserPermissionField>();
            Sys_UserPermissionField           permissionField   = userPermissionDal.GetEntity(out errMsg, x => x.Sys_UserId == userId && x.Sys_ModuleId == moduleId && !x.IsDeleted);
            string fields = string.Empty;

            if (permissionField != null)
            {
                fields = fieldPermissionType == 0 ? permissionField.CanViewFields :
                         (fieldPermissionType == 1 ? permissionField.CanAddFields : permissionField.CanEditFields);
            }
            if (!string.IsNullOrWhiteSpace(fields))
            {
                string[] token = fields.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                if (token.Contains("-1"))
                {
                    return new List <string>()
                           {
                               "-1"
                           }
                }
                ;                                       //所有字段权限
                foreach (string field in token)
                {
                    if (!fieldNames.Contains(field))
                    {
                        fieldNames.Add(field);
                    }
                }
                return(fieldNames);
            }
            //取用户角色权限
            List <Guid> roleIds = ObjectReferenceClass.GetUserRoleIds(userId);

            foreach (Guid roleId in roleIds)
            {
                Dictionary <string, bool> tempFields = GetRoleFieldPermissions(roleId, moduleId, fieldPermissionType, true);
                if (tempFields.ContainsKey("-1"))
                {
                    return new List <string>()
                           {
                               "-1"
                           }
                }
                ;                                                                     //所有字段权限
                foreach (string field in tempFields.Keys)
                {
                    if (!fieldNames.Contains(field))
                    {
                        fieldNames.Add(field);
                    }
                }
            }
            return(fieldNames);
        }
    }
}
Ejemplo n.º 3
0
        /// <summary>
        /// 获取用户的功能(菜单或网格按钮)权限,返回字典,
        /// 字典的第一个参数为功能Id(菜单或按钮Id),第二个
        /// 参数为是否来自父角色的权限,非当前角色权限
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="functionType">功能类型(菜单、网格按钮),0-菜单,1-按钮</param>
        /// <param name="moduleId">模块ID,针对按钮需要</param>
        /// <returns></returns>
        public Dictionary <Guid, bool> GetUserFunPermissions(Guid userId, int functionType, Guid?moduleId)
        {
            Dictionary <Guid, bool> funIds = new Dictionary <Guid, bool>();
            //如果存在用户自定义权限则取自定义用户权限
            string errMsg = string.Empty;
            BaseDAL <Sys_UserPermissionFun> userPermissionDal    = new BaseDAL <Sys_UserPermissionFun>();
            Expression <Func <Sys_UserPermissionFun, bool> > exp = x => x.Sys_UserId == userId && x.FunType == functionType && !x.IsDeleted;

            if (functionType == 1 && moduleId.HasValue)
            {
                string mId = moduleId.Value.ToString().ToUpper();
                Expression <Func <Sys_UserPermissionFun, bool> > tempExp = x => x.Des == mId;
                exp = ExpressionExtension.And(exp, tempExp);
            }
            List <Sys_UserPermissionFun> userFuns = userPermissionDal.GetEntities(out errMsg, exp, null, false);

            if (userFuns != null && userFuns.Count > 0)
            {
                List <Guid> tempFunIds = userFuns.Select(x => x.FunId).Distinct().ToList();
                foreach (Guid funId in tempFunIds)
                {
                    if (funIds.Keys.Contains(funId))
                    {
                        continue;
                    }
                    funIds.Add(funId, false);
                }
                return(funIds);
            }
            //取用户角色权限
            List <Guid> roleIds = ObjectReferenceClass.GetUserRoleIds(userId);

            foreach (Guid roleId in roleIds)
            {
                Dictionary <Guid, bool> dic = GetRoleFunPermissions(roleId, functionType, moduleId);
                foreach (Guid funId in dic.Keys)
                {
                    if (funIds.ContainsKey(funId))
                    {
                        continue;
                    }
                    funIds.Add(funId, dic[funId]);
                }
            }
            return(funIds);
        }