/// <summary> /// 撤消资源的权限 /// </summary> /// <param name="userInfo">用户</param> /// <param name="resourceCategory">资源分类</param> /// <param name="resourceId">资源主键</param> /// <param name="revokePermissionIds">权限主键</param> /// <returns>影响的行数</returns> public int RevokeResourcePermission(BaseUserInfo userInfo, string resourceCategory, string resourceId, string[] revokePermissionIds) { var result = 0; var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) => { // BaseRoleScopeManager manager = new BaseRoleScopeManager(dbHelper, result); // 小心异常,检查一下参数的有效性 if (revokePermissionIds != null) { var permissionManager = new BasePermissionManager(dbHelper, userInfo); for (var i = 0; i < revokePermissionIds.Length; i++) { var parameters = new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceCategory, resourceCategory), new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceId, resourceId), new KeyValuePair <string, object>(BasePermissionEntity.FieldPermissionId, revokePermissionIds[i]) }; // result += permissionManager.SetDeleted(parameters); result += permissionManager.Delete(parameters); } } }); return(result); }
// // 撤销权限的实现部分 // #region private int Revoke(BasePermissionManager permissionManager, string systemCode, string organizeId, string result) 为了提高撤销的运行速度 /// <summary> /// 为了提高撤销的运行速度 /// </summary> /// <param name="permissionManager">资源权限读写器</param> /// <param name="organizeId">组织机构主键</param> /// <param name="result">权限主键</param> /// <returns>影响行数</returns> private int Revoke(BasePermissionManager permissionManager, string systemCode, string organizeId, string permissionId) { int result = 0; List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceCategory, BaseOrganizeEntity.TableName)); parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceId, organizeId)); parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldPermissionId, permissionId)); result = permissionManager.Delete(parameters); // 2015-09-21 吉日嘎拉 这里增加变更日志 string tableName = systemCode + ".Permission.Organize"; SQLBuilder sqlBuilder = new SQLBuilder(this.DbHelper); sqlBuilder.BeginInsert(BaseModifyRecordEntity.TableName); sqlBuilder.SetValue(BaseModifyRecordEntity.FieldTableCode, tableName); sqlBuilder.SetFormula(BaseModifyRecordEntity.FieldId, "SEQ_" + BaseModifyRecordEntity.TableName + ".NEXTVAL"); sqlBuilder.SetValue(BaseModifyRecordEntity.FieldRecordKey, organizeId); sqlBuilder.SetValue(BaseModifyRecordEntity.FieldColumnCode, permissionId); sqlBuilder.SetValue(BaseModifyRecordEntity.FieldColumnDescription, BaseModuleManager.GetNameByCache(systemCode, permissionId)); sqlBuilder.SetValue(BaseModifyRecordEntity.FieldOldValue, "1"); sqlBuilder.SetValue(BaseModifyRecordEntity.FieldNewValue, "撤销授权"); sqlBuilder.SetValue(BaseModifyRecordEntity.FieldCreateUserId, this.UserInfo.Id); sqlBuilder.SetValue(BaseModifyRecordEntity.FieldCreateBy, this.UserInfo.RealName); sqlBuilder.SetDBNow(BaseModifyRecordEntity.FieldCreateOn); sqlBuilder.SetValue(BaseModifyRecordEntity.FieldIPAddress, this.UserInfo.IPAddress); sqlBuilder.EndInsert(); return(result); }
/// <summary> /// 撤销用户全部权限 /// </summary> /// <param name="roleId">角色主键</param> /// <returns>影响行数</returns> public int RevokeAll(string userId) { BasePermissionManager permissionManager = new BasePermissionManager(DbHelper, UserInfo, this.CurrentTableName); List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceCategory, BaseUserEntity.TableName)); parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceId, userId)); return(permissionManager.Delete(parameters)); }
// // 撤销权限的实现部分 // #region private int Revoke(BasePermissionManager permissionManager, string userId, string permissionItemId) 为了提高撤销的运行速度 /// <summary> /// 为了提高撤销的运行速度 /// </summary> /// <param name="permissionManager">资源权限读写器</param> /// <param name="userId">用户主键</param> /// <param name="permissionItemId">权限主键</param> /// <returns>影响行数</returns> private int Revoke(BasePermissionManager permissionManager, string userId, string permissionItemId) { List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceCategory, BaseUserEntity.TableName)); parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceId, userId)); parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldPermissionItemId, permissionItemId)); return(permissionManager.Delete(parameters)); }
/// <summary> /// 撤销角色全部权限 /// </summary> /// <param name="systemCode">系统编号</param> /// <param name="roleId">角色主键</param> /// <returns>影响行数</returns> public int RevokeAll(string systemCode, string roleId) { string tableName = systemCode + "Permission"; BasePermissionManager permissionManager = new BasePermissionManager(DbHelper, UserInfo, tableName); List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); tableName = systemCode + "Role"; parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceCategory, tableName)); parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceId, roleId)); return(permissionManager.Delete(parameters)); }
/// <summary> /// 撤消资源的权限 /// </summary> /// <param name="userInfo">用户</param> /// <param name="resourceCategory">资源分类</param> /// <param name="resourceId">资源主键</param> /// <param name="revokePermissionItemIds">权限主键</param> /// <returns>影响的行数</returns> public int RevokeResourcePermission(BaseUserInfo userInfo, string resourceCategory, string resourceId, string[] revokePermissionItemIds) { // 写入调试信息 #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); // BaseRoleScopeManager manager = new BaseRoleScopeManager(dbHelper, userInfo); // 小心异常,检查一下参数的有效性 if (revokePermissionItemIds != null) { BasePermissionManager permissionManager = new BasePermissionManager(dbHelper, userInfo); for (int i = 0; i < revokePermissionItemIds.Length; i++) { List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceCategory, resourceCategory)); parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceId, resourceId)); parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldPermissionItemId, revokePermissionItemIds[i])); // returnValue += permissionManager.SetDeleted(parameters); returnValue += permissionManager.Delete(parameters); } } BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.PermissionService_RevokeResourcePermission, 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); }
public int Delete(string moduleId, string permissionItemId) { int returnValue = 0; List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceCategory, BaseModuleEntity.TableName)); parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceId, moduleId)); parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldPermissionItemId, permissionItemId)); BasePermissionManager manager = new BasePermissionManager(this.DbHelper, this.UserInfo); returnValue = manager.Delete(parameters); return(returnValue); }
// // 撤销权限的实现部分 // #region public int Revoke(string systemCode, string roleId, string permissionId) 为了提高撤销的运行速度 /// <summary> /// 为了提高撤销的运行速度 /// </summary> /// <param name="systemCode">资源权限读写器</param> /// <param name="roleId">角色主键</param> /// <param name="permissionId">权限主键</param> /// <returns>影响行数</returns> public int Revoke(string systemCode, string roleId, string permissionId) { int result = 0; string tableName = systemCode + "Permission"; BasePermissionManager permissionManager = new BasePermissionManager(DbHelper, UserInfo, tableName); tableName = systemCode + "Role"; List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceCategory, tableName)); parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceId, roleId)); parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldPermissionId, permissionId)); // 2015-09-21 吉日嘎拉 这里增加变更日志 tableName = systemCode + ".Permission.Role"; SQLBuilder sqlBuilder = new SQLBuilder(this.DbHelper); sqlBuilder.BeginInsert(BaseModifyRecordEntity.TableName); sqlBuilder.SetValue(BaseModifyRecordEntity.FieldTableCode, tableName); if (DbHelper.CurrentDbType == CurrentDbType.Oracle) { sqlBuilder.SetFormula(BaseModifyRecordEntity.FieldId, "SEQ_" + BaseModifyRecordEntity.TableName + ".NEXTVAL"); } sqlBuilder.SetValue(BaseModifyRecordEntity.FieldRecordKey, roleId); sqlBuilder.SetValue(BaseModifyRecordEntity.FieldColumnCode, "撤销授权"); sqlBuilder.SetValue(BaseModifyRecordEntity.FieldColumnDescription, BaseModuleManager.GetNameByCache(systemCode, permissionId)); sqlBuilder.SetValue(BaseModifyRecordEntity.FieldOldValue, "1"); sqlBuilder.SetValue(BaseModifyRecordEntity.FieldNewValue, permissionId); sqlBuilder.SetValue(BaseModifyRecordEntity.FieldCreateUserId, this.UserInfo.Id); sqlBuilder.SetValue(BaseModifyRecordEntity.FieldCreateBy, this.UserInfo.RealName); sqlBuilder.SetDBNow(BaseModifyRecordEntity.FieldCreateOn); sqlBuilder.SetValue(BaseModifyRecordEntity.FieldIPAddress, this.UserInfo.IPAddress); sqlBuilder.EndInsert(); // 伪删除、数据有冗余,但是有历史记录 // result = permissionManager.SetDeleted(parameters); // 真删除、执行效率高、但是没有历史记录 result = permissionManager.Delete(parameters); return(result); }