Example #1
0
        /// <summary>
        /// 获得某个用户的所有权限列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="userId">用户主键</param>
        /// <param name="fromCache">是否从缓存读取</param>
        /// <returns>主键数组</returns>
        public string[] GetPermissionIds(BaseUserInfo userInfo, string systemCode, string userId, bool fromCache)
        {
            string[] result = null;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var permissionManager = new BasePermissionManager(dbHelper, userInfo);
                result = permissionManager.GetPermissionIdsByUser(systemCode, userId, string.Empty, true, fromCache);
            });

            return(result);
        }
Example #2
0
        /// <summary>
        /// 获得某个用户的所有权限列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="userId">用户主键</param>
        /// <returns>数据表</returns>
        public DataTable GetPermissionDTByUser(BaseUserInfo userInfo, string userId)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
            LogOnService.UserIsLogOn(userInfo);
            #endif

            DataTable dataTable = new DataTable(BasePermissionItemEntity.TableName);
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    string tableName = BasePermissionItemEntity.TableName;
                    if (!string.IsNullOrEmpty(BaseSystemInfo.SystemCode))
                    {
                        tableName = BaseSystemInfo.SystemCode + "PermissionItem";
                    }
                    // 是否超级管理员
                    BaseUserManager           userManager           = new BaseUserManager(dbHelper, userInfo);
                    BasePermissionItemManager permissionItemManager = new BasePermissionItemManager(dbHelper, userInfo, tableName);
                    if (userManager.IsAdministrator(userId))
                    {
                        dataTable = permissionItemManager.GetDataTable();
                    }
                    else
                    {
                        tableName = BasePermissionEntity.TableName;
                        if (!string.IsNullOrEmpty(BaseSystemInfo.SystemCode))
                        {
                            tableName = BaseSystemInfo.SystemCode + "Permission";
                        }
                        BasePermissionManager permissionManager = new BasePermissionManager(dbHelper, userInfo, tableName);
                        string[] ids = permissionManager.GetPermissionIdsByUser(userId);
                        // 若是以前赋予的权限,后来有些权限设置为无效了,那就不应该再获取哪些无效的权限才对。
                        // bug修正:没有赋值DataTable,导致返回值空
                        dataTable = permissionItemManager.GetDataTable(
                            new KeyValuePair <string, object>(BasePermissionItemEntity.FieldId, ids)
                            , new KeyValuePair <string, object>(BasePermissionItemEntity.FieldEnabled, 1)
                            , new KeyValuePair <string, object>(BasePermissionItemEntity.FieldDeletionStateCode, 0));
                    }
                    dataTable.TableName = tableName;
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.PermissionService_GetPermissionDTByUser, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
            #if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
            #endif

            return(dataTable);
        }