Esempio n. 1
0
        private Article SaveArticle(ISite site, CallingUser callingUser, Article article, string siteName, bool isNewArticle, int h2g2Id)
        {
            // Check: does user have edit permission
            if ((!isNewArticle) && !article.HasEditPermission(callingUser))
            {
                throw new DnaWebProtocolException(ApiException.GetError(ErrorType.UserDoesNotHavePermissionToEditArticle));
            }

            // Check: profanities
            bool moderateProfanities = false;
            string matchingProfanity;
            List<Term> terms = null;
            CheckForProfanities(site, article.Subject + " " + article.GuideMLAsString, out moderateProfanities, out matchingProfanity, out terms);

            // Check: url filter
            if ((siteList.GetSiteOptionValueBool(site.SiteID, "General", "IsURLFiltered")) && !((callingUser.IsUserA(UserTypes.Editor) || callingUser.IsUserA(UserTypes.Notable))))
            {
                List<string> nonAllowedMatches = new List<string>();
                UrlFilter urlFilter = new UrlFilter();

                UrlFilter.FilterState result = urlFilter.CheckForURLs(article.Subject + " " + article.GuideMLAsString, nonAllowedMatches, site.SiteID, readerCreator);

                if (result == UrlFilter.FilterState.Fail)
                {
                    throw new DnaWebProtocolException(ApiException.GetError(ErrorType.ArticleContainsURLs));
                }
            }

            // Check: email filter
            if ((siteList.GetSiteOptionValueBool(site.SiteID, "Forum", "EmailAddressFilter")) && !((callingUser.IsUserA(UserTypes.Editor) || callingUser.IsUserA(UserTypes.Notable))))
            {
                if (EmailAddressFilter.CheckForEmailAddresses(article.Subject + " " + article.GuideMLAsString))
                {
                    throw new DnaWebProtocolException(ApiException.GetError(ErrorType.ArticleContainsEmailAddress));
                }
            }

            if (isNewArticle)
            {
                article.CreateNewArticle(cacheManager, readerCreator, callingUser.UserID, site.SiteID);

                //Users subscribed to this author should have their subscribed content updated.
                callingUser.UpdateUserSubscriptions(readerCreator, article.H2g2Id);

            }
            else // existing article
            {
                //Don't overwrite the existing editor of the article 
                int editorId = 0;
                try
                {
                     editorId = article.ArticleInfo.PageAuthor.Editor.user.UserId;
                    if (editorId == 0)
                    {
                        editorId = callingUser.UserID;
                    }
                }
                catch
                {
                    editorId = callingUser.UserID;
                }
                article.UpdateArticle(cacheManager, readerCreator, editorId);
            }

            // set the archive status
            if (callingUser.IsUserA(UserTypes.Editor))
            {
                article.SetArticleForumArchiveStatus(readerCreator, false);
            }


            // moderate isUserImmuneFromModeration needed
            bool isSiteModerated = !(site.ModerationStatus == BBC.Dna.Moderation.Utils.ModerationStatus.SiteStatus.UnMod);
            bool isUserModerated = (callingUser.IsPreModerated || callingUser.IsPostModerated);
            bool isArticleModerated = ((article.ArticleInfo.ModerationStatus == BBC.Dna.Moderation.Utils.ModerationStatus.ArticleStatus.PreMod) || article.ArticleInfo.ModerationStatus == BBC.Dna.Moderation.Utils.ModerationStatus.ArticleStatus.PostMod);
            bool isArticleInModeration = article.IsArticleIsInModeration(readerCreator);
            bool isUserInSinbin = (callingUser.IsAutoSinBin == 1);
            bool isUserImmuneFromModeration = callingUser.HasSpecialEditPermissions(article.H2g2Id);

            // Queue, update moderation status and hide the guide entry.
            int modID = 0;
            if (!isUserImmuneFromModeration)
            {
                if (isSiteModerated || isUserModerated || isArticleModerated || isArticleInModeration || moderateProfanities || isUserInSinbin)
                {
                    if (!String.IsNullOrEmpty(matchingProfanity)) { matchingProfanity = "Profanities: " + matchingProfanity; }

                    article.QueueForModeration(readerCreator, matchingProfanity, ref modID);

                }
            }


            if (article.HiddenStatus == (int)BBC.Dna.Moderation.Utils.CommentStatus.Hidden.NotHidden)
            {
                //visible
                article.UnhideArticle(readerCreator, 0, 0, callingUser.UserID);
            }
            else
            {
                // hidden
                article.HideArticle(readerCreator, 0, 0, callingUser.UserID);
            }

            
            article.UpdateResearchers(readerCreator);

            return article;
        }