private bool ProcessDeleteDoings(int operatorID, bool isUpdatePoint, DeleteDoingsCallback deleteAction) { if (ValidateDoingAdminPermission(operatorID) == false) { return(false); } Guid[] excludeRoleIDs = ManagePermission.GetNoPermissionTargetRoleIds(operatorID, PermissionTargetType.Content); DeleteResult deleteResult = null; if (isUpdatePoint) { bool succeed = DoingPointAction.Instance.UpdateUsersPoints(delegate(PointActionManager.TryUpdateUserPointState state, out PointResultCollection <DoingPointType> pointResults) { pointResults = null; if (state != PointActionManager.TryUpdateUserPointState.CheckSucceed) { return(false); } deleteResult = deleteAction(excludeRoleIDs); if (deleteResult != null && deleteResult.Count > 0) { pointResults = new PointResultCollection <DoingPointType>(); foreach (DeleteResultItem item in deleteResult) { pointResults.Add(item.UserID, item.UserID == operatorID ? DoingPointType.DoingWasDeletedBySelf : DoingPointType.DoingWasDeletedByAdmin, item.Count); } return(true); } return(false); }); } else { deleteResult = deleteAction(excludeRoleIDs); } if (deleteResult != null && deleteResult.Count > 0) { ClearCachedEveryoneData(); foreach (DeleteResultItem item in deleteResult) { ClearCachedUserData(item.UserID); } } return(true); }
/// <summary> /// 验证操作者的管理权限,没权限时会ThrowError(只要对任意一个用户组有管理权限都算有权限) /// </summary> /// <typeparam name="ErrorType">错误类型</typeparam> /// <param name="operatorID">操作者ID</param> /// <returns></returns> protected bool ValidateAdminPermission <ErrorType>(int operatorID) where ErrorType : ErrorInfo, new() //老达TODO:最后好改成NoPermissionError基类 { if (ManagePermission.HasPermissionForSomeone(operatorID, ManageAction)) { return(true); } ThrowError <ErrorType>(new ErrorType()); return(false); }
/// <summary> /// 验证操作者是否具有编辑某条数据的权限 /// </summary> /// <param name="operatorID">操作者ID</param> /// <param name="dataOwnerID">数据所有者ID</param> /// <param name="lastEditorID">数据最后编辑者ID</param> /// <returns>操作者具有编辑权限则返回true否则返回false</returns> protected bool CheckEditPermission(int editorID, int dataOwnerID) { if (editorID == dataOwnerID) { return(true); //2009-07-09 喳喳鸟又说不判断最后编辑者了 Permission.Can(editorID, UseAction); } else { NoPermissionType reason = NoPermissionType.NoPermission; return(ManagePermission.Can(editorID, ManageAction, dataOwnerID, out reason)); } }
/// <summary> /// 验证操作者是否具有编辑某条数据的权限 /// </summary> /// <param name="operatorID">操作者ID</param> /// <param name="dataOwnerID">数据所有者ID</param> /// <param name="lastEditorID">数据最后编辑者ID</param> /// <returns>操作者具有编辑权限则返回true否则返回false</returns> protected bool CheckEditPermission(int editorID, int dataOwnerID, int lastEditorID) { if (editorID == dataOwnerID) //2009-07-09 喳喳鸟又说不判断最后编辑者了 && editorID == lastEditorID) { return(true); //2009-07-09 喳喳鸟又说不判断最后编辑者了 Permission.Can(editorID, UseAction); } else { /* 2009-0714 据喳喳鸟要求在没有专门给管理员编辑内容的页面前,不要提供让管理员编辑别人数据的功能*/ /*什么乱七八糟的,不懂。 注释的代码被我恢复了 wen*/ NoPermissionType reason = NoPermissionType.NoPermission; return(ManagePermission.Can(editorID, ManageAction, dataOwnerID, lastEditorID, out reason)); } }
/// <summary> /// 获取记录用于管理 /// </summary> /// <param name="operatorID">操作者ID</param> /// <param name="filter">文章搜索条件</param> /// <param name="pageNumber">数据分页页码</param> /// <returns></returns> public DoingCollection GetDoingsForAdmin(int operatorID, AdminDoingFilter filter, int pageNumber) { if (ValidateDoingAdminPermission(operatorID) == false) { return(null); } Guid[] excludeRoleIDs = ManagePermission.GetNoPermissionTargetRoleIds(operatorID, PermissionTargetType.Content); DoingCollection doings = DoingDao.Instance.GetDoingsBySearch(excludeRoleIDs, filter, pageNumber); ProcessKeyword(doings, ProcessKeywordMode.FillOriginalText); return(doings); }
/// <summary> /// 搜索评论 /// </summary> /// <param name="operatorID"></param> /// <param name="filter"></param> /// <param name="pageNumber"></param> /// <returns></returns> public CommentCollection GetCommentsForAdmin(int operatorID, AdminCommentFilter filter, int pageNumber) { if (ValidateCommentAdminPermission(operatorID) == false) { return(null); } Guid[] excludeRoleIDs = ManagePermission.GetNoPermissionTargetRoleIds(operatorID, PermissionTargetType.Content); CommentCollection comments = CommentDao.Instance.GetCommentsBySearch(operatorID, excludeRoleIDs, filter, pageNumber); ProcessKeyword(comments, ProcessKeywordMode.FillOriginalText); return(comments); }
/// <summary> /// 删除符合指定条件的通知 /// </summary> public bool DeleteNotifiesBySearch(int operatorUserID, AdminNotifyFilter notifyFilter) { if (notifyFilter == null) { notifyFilter = new AdminNotifyFilter(); } Guid[] excludeRoleIds = ManagePermission.GetNoPermissionTargetRoleIds(operatorUserID, PermissionTargetType.Content); NotifyDao.Instance.DeleteNotifiesBySearch(notifyFilter, excludeRoleIds); //bool isDeleted = NotifyDao.Instance.DeleteNotifiesBySearch(notifyFilter); //if (isDeleted) //{ // UserBO.Instance.ClearUserDataCache(); //} return(true); }
private bool ProcessDeleteComments(int operatorID, bool isUpdatePoint, DeleteCommentsCallback deleteAction) { Guid[] excludeRoleIDs = ManagePermission.GetNoPermissionTargetRoleIds(operatorID, PermissionTargetType.Content); DeleteResult deleteResult = null; if (isUpdatePoint) { bool succeed = CommentPointAction.Instance.UpdateUsersPoints(delegate(PointActionManager.TryUpdateUserPointState state, out PointResultCollection <CommentPointType> pointResults) { pointResults = null; if (state != PointActionManager.TryUpdateUserPointState.CheckSucceed) { return(false); } deleteResult = deleteAction(excludeRoleIDs); if (deleteResult != null && deleteResult.Count > 0) { pointResults = new PointResultCollection <CommentPointType>(); foreach (DeleteResultItem item in deleteResult) { pointResults.Add(item.UserID, item.UserID == operatorID ? CommentPointType.DeleteCommentBySelf : CommentPointType.DeleteCommentByAdmin, item.Count); } return(true); } return(false); }); } else { deleteResult = deleteAction(excludeRoleIDs); } return(true); }
///// <summary> ///// 删除搜索结果 ///// </summary> ///// <param name="filter"></param> ///// <returns></returns> //public bool RemoveCommentsBySearch(int operatorUserID, AdminCommentFilter filter, bool updatePoint) //{ // Guid[] excludeRoleIDs = ManagePermission.GetNoPermissionTargetRoleIds(operatorUserID); // //DeleteResult deleteResult = CommentDao.Instance.DeleteCommentsBySearch(filter, operatorUserID, excludeRoleIDs); // DeleteResult deleteResult = null; // if (updatePoint) // { // bool success = CommentPointAction.Instance.UpdateUsersPoint(CommentPointType.DeleteCommentByAdmin, delegate(PointActionManager.TryUpdateUserPointState state, out Dictionary<int, int> userIDs) // { // if (state == PointActionManager.TryUpdateUserPointState.CheckSucceed) // { // deleteResult = CommentDao.Instance.DeleteCommentsByFilter(filter, operatorUserID, excludeRoleIDs, true); // userIDs = new Dictionary<int, int>(); // foreach (DeleteResultItem item in deleteResult) // { // userIDs.Add(item.UserID, item.Count); // } // return true; // } // else // { // userIDs = null; // return false; // } // }); // if (!success) // return false; // } // else // { // deleteResult = CommentDao.Instance.DeleteCommentsByFilter(filter, operatorUserID, excludeRoleIDs, true); // } // foreach (DeleteResultItem item in deleteResult) // { // UserBO.Instance.RemoveUserCache(item.UserID); // } // CacheUtil.RemoveBySearch("Doing/List/All"); // CacheUtil.RemoveBySearch("Comment/List/Space"); // return true; //} ///// <summary> ///// 更新关键字版本和评论内容 ///// </summary> ///// <param name="comments"></param> //protected void TryUpdateKeyword(CommentCollection comments) //{ // TextRevertableCollection processlist = new TextRevertableCollection(); // KeywordReplaceRegulation keyword = AllSettings.Current.ContentKeywordSettings.ReplaceKeywords; // foreach (Comment comment in comments) // { // if (keyword.NeedUpdateText(comment)) // { // processlist.Add(comment); // } // } // if (processlist.Count > 0) // { // CommentDao.Instance.FillCommentReverters(processlist); // keyword.Update(processlist); // CommentDao.Instance.UpdateCommentKeywords(processlist); // } //} /// <summary> /// 审核评论单条或多条 用于后台 /// </summary> /// <param name="commentIDs"></param> public bool ApproveComments(int operatorUserID, IEnumerable <int> commentIDs) { if (ValidateUtil.HasItems <int>(commentIDs) == false) { ThrowError(new NotSelectedCommentsError("commentIDs")); return(false); } CommentCollection comments = CommentDao.Instance.GetComments(commentIDs); if (comments.Count == 0) { return(true); } List <int> canApproveCommentIDs = new List <int>(); foreach (Comment comment in comments) { if (ManagePermission.Can(operatorUserID, BackendPermissions.ActionWithTarget.Manage_Comment, comment.UserID)) { canApproveCommentIDs.Add(comment.CommentID); } } if (canApproveCommentIDs.Count == 0) { ThrowError <NoPermissionApproveCommentError>(new NoPermissionApproveCommentError()); return(false); } CommentDao.Instance.ApproveComments(canApproveCommentIDs); //TODO:优化 CacheUtil.RemoveBySearch("Doing/List/All"); CacheUtil.RemoveBySearch("Comment/List/Space"); return(true); }
/// <summary> /// 删除通知 /// </summary> /// <param name="messageID">要删除的通知的ID</param> public bool DeleteNotify(AuthUser operatorUser, int notifyID) { #if !Passport PassportClientConfig settings = Globals.PassportClient; if (settings.EnablePassport) { APIResult result = settings.PassportService.Notify_DeleteNotify(operatorUser.UserID, notifyID); if (result.ErrorCode == Consts.ExceptionCode) { if (result.Messages.Length > 0) { throw new Exception(result.Messages[0]); } return(false); } else if (result.IsSuccess == false) { ThrowError <CustomError>(new CustomError("", result.Messages[0])); return(false); } return(true); } else #endif { Notify notify = NotifyDao.Instance.GetNotify <Notify>(null, notifyID, false); if (notify != null) { if (notify.UserID != operatorUser.UserID && ManagePermission.Can(operatorUser, BackendPermissions.ActionWithTarget.Manage_Notify, notify.UserID) == false) { ThrowError(new NoPermissionDeleteNotifyError()); return(false); } if (HasUnCatchedError) { return(false); } UnreadNotifies unread; NotifyDao.Instance.DeleteNotify(null, notifyID, out unread); if (unread != null) { if (OnUserNotifyCountChanged != null) { OnUserNotifyCountChanged(unread); } AuthUser user = UserBO.Instance.GetUserFromCache <AuthUser>(unread.UserID); if (user != null) { user.UnreadNotify = unread; } RemoveCacheByType(unread.UserID, 0); } } //bool isDeleted = NotifyDao.Instance.DeleteNotify(userID, notifyID); //if (isDeleted) //{ // UserBO.Instance.RemoveUserDataCache(notify.UserID); //} return(true); } }
/// <summary> /// 删除多个通知 /// </summary> /// <param name="notifyIDs">要删除的通知的ID集</param> public bool DeleteNotifies(int operatorUserID, IEnumerable <int> notifyIDs) { if (notifyIDs == null) { ThrowError(new NoSelectedNotifiesError("notifyIDs")); return(false); } if (!ValidateUtil.HasItems <int>(notifyIDs)) { return(true); } #if !Passport PassportClientConfig settings = Globals.PassportClient; if (settings.EnablePassport) { List <int> ids = new List <int>(); foreach (int id in notifyIDs) { ids.Add(id); } int[] t = new int[ids.Count]; ids.CopyTo(t); APIResult result = null; try { result = settings.PassportService.Notify_DeleteNotifies(operatorUserID, t); } catch (Exception ex) { ThrowError(new APIError(ex.Message)); return(false); } if (result.ErrorCode == Consts.ExceptionCode) { if (result.Messages.Length > 0) { throw new Exception(result.Messages[0]); } return(false); } else if (result.IsSuccess == false) { ThrowError <CustomError>(new CustomError("", result.Messages[0])); return(false); } return(true); } else #endif { List <int> deleteNotifyIds = new List <int>(); NotifyCollection notifies = NotifyDao.Instance.GetNotifies(notifyIDs); ///如果集合里没有数据, 会出现没有权限的误报, 因此直接返回 if (notifies.Count == 0) { return(true); } foreach (Notify notify in notifies) { if (notify.UserID == operatorUserID || ManagePermission.Can(operatorUserID, BackendPermissions.ActionWithTarget.Manage_Notify, notify.UserID)) { deleteNotifyIds.Add(notify.NotifyID); } } if (deleteNotifyIds.Count == 0) { ThrowError(new NoPermissionDeleteNotifyError()); return(false); } UnreadNotifyCollection unread; NotifyDao.Instance.DeleteNotifies(null, deleteNotifyIds, out unread); foreach (UnreadNotifies un in unread) { RemoveCacheByType(un.UserID, 0); if (OnUserNotifyCountChanged != null) { OnUserNotifyCountChanged(un); } AuthUser user = UserBO.Instance.GetUserFromCache <AuthUser>(un.UserID); if (user != null) { user.UnreadNotify = un; } } return(true); } }
/* * /// <summary> * /// 删除评论 包括删除自己的评论 别人对自己应用的评论 并更新缓存 * /// </summary> * /// <param name="commentID"></param> * /// <param name="type"></param> * /// <returns></returns> * public bool RemoveComment(int userID, int commentID, CommentType type) * { * if (commentID <= 0) * { * ThrowError(new InvalidParamError("commentID")); * return false; * } * * int commentUserID; * * CommentPointManager.Instance.UpdateUserPoint(userID, CommentPMType.DeleteComment, delegate(UserBO.TryUpdateUserPointState state) * { * return true; * }); * * CommentDao.Instance.DeleteComment(userID, commentID, out commentUserID); * * if (type == CommentType.Doing) * CacheUtil.RemoveBySearch("Doing/List/All"); * if (type == CommentType.Board) * CacheUtil.RemoveBySearch(string.Format(cacheKey_List_Space, commentUserID, type)); * * //TODO;对comment用户的积分操作 * * return true; * } */ /// <summary> /// 删除评论单条或批量 并更新缓存 用于后台 /// </summary> /// <param name="commentIDs"></param> public bool RemoveComments(int operatorUserID, IEnumerable <int> commentIDs, bool isUpdatePoint) { if (ValidateUtil.HasItems <int>(commentIDs) == false) { ThrowError(new NotSelectedCommentsError("commentIDs")); return(false); } CommentCollection comments = CommentDao.Instance.GetComments(commentIDs); Dictionary <int, int> deleteResults = new Dictionary <int, int>(); List <int> deleteCommentIDs = new List <int>(); foreach (Comment comment in comments) { if (comment.UserID == operatorUserID || comment.TargetUserID == operatorUserID) //是自己的 或者 是别人评论自己的可以删除 { deleteCommentIDs.Add(comment.CommentID); if (deleteResults.ContainsKey(comment.UserID)) { deleteResults[comment.UserID] += 1; } else { deleteResults.Add(comment.UserID, 1); } } else //不是自己的判断权限 { if (ManagePermission.Can(operatorUserID, BackendPermissions.ActionWithTarget.Manage_Comment, comment.UserID, comment.LastEditUserID) == false) { //没权限 跳过 } else { deleteCommentIDs.Add(comment.CommentID); if (deleteResults.ContainsKey(comment.UserID)) { deleteResults[comment.UserID] += 1; } else { deleteResults.Add(comment.UserID, 1); } } } } if (deleteResults.Count == 0) { ThrowError <NoPermissionDeleteCommentError>(new NoPermissionDeleteCommentError()); return(false); } if (isUpdatePoint) { CommentPointType pointType; if (deleteResults.Count == 1 && deleteResults.ContainsKey(operatorUserID)) //自己删除 { pointType = CommentPointType.DeleteCommentBySelf; } else { pointType = CommentPointType.DeleteCommentByAdmin; } bool success = CommentPointAction.Instance.UpdateUsersPoint(deleteResults, pointType, delegate(PointActionManager.TryUpdateUserPointState state) { if (state == PointActionManager.TryUpdateUserPointState.CheckSucceed) { CommentDao.Instance.DeleteComments(deleteCommentIDs); return(true); } else { return(false); } }); if (!success) { return(false); } } else { CommentDao.Instance.DeleteComments(deleteCommentIDs); } if (comments.Count == 1) { if (comments[0].Type == CommentType.Doing) { CacheUtil.RemoveBySearch("Doing/List/All"); } if (comments[0].Type == CommentType.Board) { CacheUtil.RemoveBySearch(string.Format(cacheKey_List_Space, comments[0].UserID, CommentType.Board)); } FeedBO.Instance.DeleteFeed(AppActionType.AddComment, comments[0].TargetID, comments[0].UserID); } else { //TODO:优化 CacheUtil.RemoveBySearch("Doing/List/All"); CacheUtil.RemoveBySearch("Comment/List/Space"); Dictionary <int, List <int> > deleteFeedIDs = new Dictionary <int, List <int> >(); foreach (Comment comment in comments) { if (deleteFeedIDs.ContainsKey(comment.TargetID) == false) { deleteFeedIDs.Add(comment.TargetID, new List <int>(new int[] { comment.UserID })); } else { deleteFeedIDs[comment.TargetID].Add(comment.UserID); } } FeedBO.Instance.DeleteFeeds(AppActionType.AddComment, deleteFeedIDs); } return(true); }