예제 #1
0
        public string SetUserOrganizeScope(string systemCode, string userId, PermissionOrganizeScope permissionScope, string permissionCode = "Resource.AccessPermission", bool containChild = false)
        {
            string result = string.Empty;

            string permissionId = BaseModuleManager.GetIdByCodeByCache(systemCode, permissionCode);

            if (!string.IsNullOrEmpty(permissionId))
            {
                string tableName = BaseOrganizeScopeEntity.TableName;
                if (!string.IsNullOrEmpty(systemCode))
                {
                    tableName = systemCode + "OrganizeScope";
                }

                BaseOrganizeScopeManager organizeScopeManager    = new BaseOrganizeScopeManager(this.DbHelper, this.UserInfo, tableName);
                List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();
                parameters.Add(new KeyValuePair <string, object>(BaseOrganizeScopeEntity.FieldResourceCategory, BaseUserEntity.TableName));
                parameters.Add(new KeyValuePair <string, object>(BaseOrganizeScopeEntity.FieldResourceId, userId));
                parameters.Add(new KeyValuePair <string, object>(BaseOrganizeScopeEntity.FieldPermissionId, permissionId));
                result = organizeScopeManager.GetId(parameters);
                BaseOrganizeScopeEntity organizeScopeEntity = null;
                if (string.IsNullOrEmpty(result))
                {
                    organizeScopeEntity = new BaseOrganizeScopeEntity();
                }
                else
                {
                    organizeScopeEntity = organizeScopeManager.GetObject(result);
                }
                organizeScopeEntity.AllData           = (permissionScope == PermissionOrganizeScope.AllData ? 1 : 0);
                organizeScopeEntity.Province          = (permissionScope == PermissionOrganizeScope.Province ? 1 : 0);
                organizeScopeEntity.City              = (permissionScope == PermissionOrganizeScope.City ? 1 : 0);
                organizeScopeEntity.District          = (permissionScope == PermissionOrganizeScope.District ? 1 : 0);
                organizeScopeEntity.UserCompany       = (permissionScope == PermissionOrganizeScope.UserCompany ? 1 : 0);
                organizeScopeEntity.UserSubCompany    = (permissionScope == PermissionOrganizeScope.UserSubCompany ? 1 : 0);
                organizeScopeEntity.UserDepartment    = (permissionScope == PermissionOrganizeScope.UserDepartment ? 1 : 0);
                organizeScopeEntity.UserSubDepartment = (permissionScope == PermissionOrganizeScope.UserSubDepartment ? 1 : 0);
                organizeScopeEntity.UserWorkgroup     = (permissionScope == PermissionOrganizeScope.UserWorkgroup ? 1 : 0);
                organizeScopeEntity.OnlyOwnData       = (permissionScope == PermissionOrganizeScope.OnlyOwnData ? 1 : 0);
                organizeScopeEntity.ByDetails         = (permissionScope == PermissionOrganizeScope.ByDetails ? 1 : 0);
                organizeScopeEntity.NotAllowed        = (permissionScope == PermissionOrganizeScope.NotAllowed ? 1 : 0);
                organizeScopeEntity.Enabled           = 1;
                organizeScopeEntity.DeletionStateCode = 0;
                organizeScopeEntity.ContainChild      = containChild ? 1 : 0;
                organizeScopeEntity.PermissionId      = int.Parse(permissionId);
                organizeScopeEntity.ResourceCategory  = BaseUserEntity.TableName;
                organizeScopeEntity.ResourceId        = userId;
                if (string.IsNullOrEmpty(result))
                {
                    result = organizeScopeManager.Add(organizeScopeEntity);
                }
                else
                {
                    organizeScopeManager.Update(organizeScopeEntity);
                }
            }
            return(result);
        }
예제 #2
0
        /// <summary>
        /// 清除组织机构权限
        ///
        /// 1.清除组织机构的用户归属。
        /// 2.清除组织机构的模块权限。
        /// 3.清除组织机构的操作权限。
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <returns>数据表</returns>
        public int ClearOrganizePermission(BaseUserInfo userInfo, string id)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

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

            int returnValue = 0;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);

                    string tableName = BasePermissionEntity.TableName;
                    if (!string.IsNullOrEmpty(BaseSystemInfo.SystemCode))
                    {
                        tableName = BaseSystemInfo.SystemCode + "Permission";
                    }
                    BaseOrganizePermissionManager organizePermissionManager = new BaseOrganizePermissionManager(dbHelper, userInfo, tableName);
                    returnValue += organizePermissionManager.RevokeAll(id);

                    tableName = BasePermissionScopeEntity.TableName;
                    if (!string.IsNullOrEmpty(BaseSystemInfo.SystemCode))
                    {
                        tableName = BaseSystemInfo.SystemCode + "PermissionScope";
                    }
                    BaseOrganizeScopeManager organizeScopeManager = new BaseOrganizeScopeManager(dbHelper, userInfo, tableName);
                    returnValue += organizeScopeManager.RevokeAll(id);

                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.PermissionService_ClearOrganizePermission, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

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

            return(returnValue);
        }
예제 #3
0
        /// <summary>
        /// 授予用户模块的权限范围
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="organizeId">组织机构主键</param>
        /// <param name="grantModuleId">授予模块主键</param>
        /// <returns>影响的行数</returns>
        public string GrantOrganizeModuleScope(BaseUserInfo userInfo, string organizeId, string permissionItemCode, string grantModuleId)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

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

            string returnValue = string.Empty;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    string tableName = BasePermissionScopeEntity.TableName;
                    if (!string.IsNullOrEmpty(BaseSystemInfo.SystemCode))
                    {
                        tableName = BaseSystemInfo.SystemCode + "PermissionScope";
                    }
                    BaseOrganizeScopeManager organizeScopeManager = new BaseOrganizeScopeManager(dbHelper, userInfo, tableName);
                    // 小心异常,检查一下参数的有效性
                    if (grantModuleId != null)
                    {
                        returnValue = organizeScopeManager.GrantModule(organizeId, permissionItemCode, grantModuleId);
                    }
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.PermissionService_GrantOrganizeModuleScope, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
            #if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
            #endif
            return(returnValue);
        }
예제 #4
0
        ////
        ////
        //// 授权范围管理部分
        ////
        ////

        public List <BaseOrganizeScopeEntity> GetRoleOrganizeScopes(string roleId, string permissionCode = "Resource.AccessPermission")
        {
            List <BaseOrganizeScopeEntity> result = null;
            string permissionId = this.GetPermissionIdByCode(permissionCode);

            if (!string.IsNullOrEmpty(permissionId))
            {
                BaseOrganizeScopeManager organizeScopeManager = new BaseOrganizeScopeManager(this.DbHelper, this.UserInfo);
                string tableName = UserInfo.SystemCode + "Role";
                List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();
                parameters.Add(new KeyValuePair <string, object>(BaseOrganizeScopeEntity.FieldResourceCategory, tableName));
                parameters.Add(new KeyValuePair <string, object>(BaseOrganizeScopeEntity.FieldResourceId, roleId));
                parameters.Add(new KeyValuePair <string, object>(BaseOrganizeScopeEntity.FieldPermissionId, permissionId));
                result = organizeScopeManager.GetList <BaseOrganizeScopeEntity>(parameters);
            }
            return(result);
        }
예제 #5
0
        /// <summary>
        /// 撤消用户模块的权限范围
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="organizeId">组织机构主键</param>
        /// <param name="revokeModuleIds">撤消模块主键数组</param>
        /// <returns>影响的行数</returns>
        public int RevokeOrganizeModuleScopes(BaseUserInfo userInfo, string organizeId, string permissionItemCode, string[] revokeModuleIds)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

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

            int returnValue = 0;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseOrganizeScopeManager organizeScopeManager = new BaseOrganizeScopeManager(dbHelper, userInfo);
                    // 小心异常,检查一下参数的有效性
                    if (revokeModuleIds != null)
                    {
                        returnValue += organizeScopeManager.RevokeModules(organizeId, permissionItemCode, revokeModuleIds);
                    }
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.PermissionService_RevokeOrganizeModuleScopes, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

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

            return(returnValue);
        }
예제 #6
0
        /*
         * public List<BaseOrganizeScopeEntity> GetUserOrganizeScopes(string userId, string permissionCode = "Resource.AccessPermission")
         * {
         *  List<BaseOrganizeScopeEntity> result = null;
         *  string result = this.GetPermissionIdByCode(permissionCode);
         *  if (!string.IsNullOrEmpty(result))
         *  {
         *      BaseOrganizeScopeManager organizeScopeManager = new BaseOrganizeScopeManager(this.DbHelper, this.UserInfo);
         *      List<KeyValuePair<string, object>> parameters = new List<KeyValuePair<string, object>>();
         *      parameters.Add(new KeyValuePair<string, object>(BaseOrganizeScopeEntity.FieldResourceCategory, BaseUserEntity.TableName));
         *      parameters.Add(new KeyValuePair<string, object>(BaseOrganizeScopeEntity.FieldResourceId, userId));
         *      parameters.Add(new KeyValuePair<string, object>(BaseOrganizeScopeEntity.FieldPermissionId, result));
         *      result = organizeScopeManager.GetList<BaseOrganizeScopeEntity>(parameters);
         *  }
         *  return result;
         * }
         */

        public PermissionOrganizeScope GetUserOrganizeScope(string systemCode, string userId, out bool containChild, string permissionCode = "Resource.AccessPermission")
        {
            containChild = false;
            PermissionOrganizeScope permissionScope = PermissionOrganizeScope.UserCompany;

            BaseOrganizeScopeEntity organizeScopeEntity = null;
            string permissionId = BaseModuleManager.GetIdByCodeByCache(systemCode, permissionCode);

            if (!string.IsNullOrEmpty(permissionId))
            {
                string tableName = BaseOrganizeScopeEntity.TableName;
                if (!string.IsNullOrEmpty(systemCode))
                {
                    tableName = systemCode + "OrganizeScope";
                }

                BaseOrganizeScopeManager organizeScopeManager    = new BaseOrganizeScopeManager(this.DbHelper, this.UserInfo, tableName);
                List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();
                parameters.Add(new KeyValuePair <string, object>(BaseOrganizeScopeEntity.FieldResourceCategory, BaseUserEntity.TableName));
                parameters.Add(new KeyValuePair <string, object>(BaseOrganizeScopeEntity.FieldResourceId, userId));
                parameters.Add(new KeyValuePair <string, object>(BaseOrganizeScopeEntity.FieldPermissionId, permissionId));
                DataTable dt = organizeScopeManager.GetDataTable(parameters);
                if (dt != null && dt.Rows.Count > 0)
                {
                    organizeScopeEntity = BaseOrganizeScopeEntity.Create <BaseOrganizeScopeEntity>(dt);
                }
            }

            if (organizeScopeEntity != null)
            {
                if (organizeScopeEntity.ContainChild == 1)
                {
                    containChild = true;
                }
                if (organizeScopeEntity.AllData == 1)
                {
                    permissionScope = PermissionOrganizeScope.AllData;
                }
                if (organizeScopeEntity.Province == 1)
                {
                    permissionScope = PermissionOrganizeScope.Province;
                }
                if (organizeScopeEntity.City == 1)
                {
                    permissionScope = PermissionOrganizeScope.City;
                }
                if (organizeScopeEntity.District == 1)
                {
                    permissionScope = PermissionOrganizeScope.District;
                }
                if (organizeScopeEntity.ByDetails == 1)
                {
                    permissionScope = PermissionOrganizeScope.ByDetails;
                }
                if (organizeScopeEntity.NotAllowed == 1)
                {
                    permissionScope = PermissionOrganizeScope.NotAllowed;
                }
                if (organizeScopeEntity.OnlyOwnData == 1)
                {
                    permissionScope = PermissionOrganizeScope.OnlyOwnData;
                }
                if (organizeScopeEntity.UserCompany == 1)
                {
                    permissionScope = PermissionOrganizeScope.UserCompany;
                }
                if (organizeScopeEntity.UserSubCompany == 1)
                {
                    permissionScope = PermissionOrganizeScope.UserSubCompany;
                }
                if (organizeScopeEntity.UserDepartment == 1)
                {
                    permissionScope = PermissionOrganizeScope.UserDepartment;
                }
                if (organizeScopeEntity.UserSubDepartment == 1)
                {
                    permissionScope = PermissionOrganizeScope.UserSubDepartment;
                }
                if (organizeScopeEntity.UserWorkgroup == 1)
                {
                    permissionScope = PermissionOrganizeScope.UserWorkgroup;
                }
            }
            return(permissionScope);
        }