Пример #1
0
        public bool UpdateModels(AuthUser operatorUser, IEnumerable <int> modelIDs, IEnumerable <int> sortOrders, IEnumerable <string> modelNames, IEnumerable <int> enableIDs)
        {
            if (AllSettings.Current.BackendPermissions.Can(operatorUser, BackendPermissions.Action.Manage_ThreadCate) == false)
            {
                ThrowError(new NoPermissionManageThreadCateError());
                return(false);
            }
            if (ValidateUtil.HasItems <int>(modelIDs) == false)
            {
                return(true);
            }

            int i = 0;

            foreach (string name in modelNames)
            {
                if (string.IsNullOrEmpty(name))
                {
                    ThrowError(new EmptyThreadCateModelNameError("modelName", i));
                }
                if (StringUtil.GetByteCount(name) > modelNameMaxLength)
                {
                    ThrowError(new InvalidThreadCateModelNameLengthError("modelName", i, name, modelNameMaxLength));
                }
                i++;
            }

            if (HasUnCatchedError)
            {
                return(false);
            }

            bool success = ThreadCateDao.Instance.UpdateModels(modelIDs, sortOrders, modelNames, enableIDs);

            if (success)
            {
                models = null;
            }

            return(success);
        }
Пример #2
0
        public bool DeleteThreadCates(AuthUser operatorUser, IEnumerable <int> cateIDs)
        {
            if (AllSettings.Current.BackendPermissions.Can(operatorUser, BackendPermissions.Action.Manage_ThreadCate) == false)
            {
                ThrowError(new NoPermissionManageThreadCateError());
                return(false);
            }
            if (ValidateUtil.HasItems <int>(cateIDs) == false)
            {
                return(true);
            }

            bool success = ThreadCateDao.Instance.DeleteThreadCates(cateIDs);

            if (success)
            {
                allThreadCates = null;
            }

            return(success);
        }
Пример #3
0
        public bool LoadModelFields(AuthUser operatorUser, int modelID, IEnumerable <int> fieldIDs)
        {
            if (AllSettings.Current.BackendPermissions.Can(operatorUser, BackendPermissions.Action.Manage_ThreadCate) == false)
            {
                ThrowError(new NoPermissionManageThreadCateError());
                return(false);
            }

            if (ValidateUtil.HasItems <int>(fieldIDs) == false)
            {
                return(true);
            }

            bool success = ThreadCateDao.Instance.LoadModelFields(modelID, fieldIDs);

            if (success)
            {
                allThreadCateModelFields = null;
            }

            return(success);
        }
Пример #4
0
        public byte[] PackCFC(int userID, IEnumerable <int> emoticonIdentities)
        {
            if (!CanExport(userID))
            {
                ThrowError(new NoPermissonExportEmoticonError());
                return(null);
            }

            if (!ValidateUtil.HasItems <int>(emoticonIdentities))
            {
                return(null);
            }

            EmoticonCollection emoticons = GetEmoticons(userID, emoticonIdentities);

            if (emoticons.Count == 0)
            {
                return(null);
            }

            return(CFCBuilder.BuildCFCFileFromBytes(emoticons));
        }
Пример #5
0
        ///// <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);
        }
Пример #6
0
        public bool UpdateThreadCateModelFields(AuthUser operatorUser, IEnumerable <int> fieldIDs, IEnumerable <bool> enables, IEnumerable <int> sortOrders
                                                , IEnumerable <bool> searchs, IEnumerable <bool> advancedSearchs, IEnumerable <bool> displayInLists, IEnumerable <bool> mustFilleds)
        {
            if (AllSettings.Current.BackendPermissions.Can(operatorUser, BackendPermissions.Action.Manage_ThreadCate) == false)
            {
                ThrowError(new NoPermissionManageThreadCateError());
                return(false);
            }

            if (ValidateUtil.HasItems <int>(fieldIDs) == false)
            {
                return(true);
            }

            bool success = ThreadCateDao.Instance.UpdateThreadCateModelFields(fieldIDs, enables, sortOrders, searchs, advancedSearchs, displayInLists, mustFilleds);

            if (success)
            {
                allThreadCateModelFields = null;
            }

            return(success);
        }
Пример #7
0
        private bool ValidateSystemNotifyData(string Content, IEnumerable <Guid> receiveRoles, IEnumerable <int> receiveUserIDs, DateTime beginDate, DateTime endDate)
        {
            bool ok = true;

            if (string.IsNullOrEmpty(Content))
            {
                ThrowError(new SystemNotifyContentEmptyError("content"));
                ok = false;
            }

            if (Content.Length > 2000)
            {
                ThrowError(new SystemNotifyContentOverflow("content"));
                ok = false;
            }

            if (endDate <= DateTimeUtil.Now)
            {
                ThrowError(new SystemNotifyEndDateError("enddate"));
                ok = false;
            }

            if (!ValidateUtil.HasItems <int>(receiveUserIDs) && !ValidateUtil.HasItems <Guid>(receiveRoles))
            {
                ThrowError(new SystemNotifyNoReceive());
                ok = false;
            }

            if (beginDate >= endDate)
            {
                ThrowError(new SystemNotifyTimespanError());
                ok = false;
            }

            return(ok);
        }
Пример #8
0
        /// <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);
            }
        }
Пример #9
0
        /*
         * /// <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);
        }