/// <summary> /// Closes a thread with a CallingUser IsSuperUser check /// </summary> /// <param name="currentSiteId"></param> /// <param name="forumId"></param> /// <param name="threadId"></param> public void CloseThreadWithCallingUser(int currentSiteId, int forumId, int threadId, BBC.Dna.Users.ICallingUser user, ISiteList siteList) { bool authorised = (user.IsUserA(BBC.Dna.Users.UserTypes.Editor) || user.IsUserA(BBC.Dna.Users.UserTypes.SuperUser)); if (!authorised && siteList.GetSiteOptionValueBool(currentSiteId, "Forum", "ArticleAuthorCanCloseThreads")) {//check if author can modify forum thread. authorised = IsUserAuthorForArticle(forumId); } if (authorised) {//do work CallCloseThreadSP(threadId); } else { throw new BBC.Dna.Api.ApiException("Unable to close thread", BBC.Dna.Api.ErrorType.NotAuthorized); } }
/// <summary> /// Creates new post after checking relevant items... /// </summary> /// <param name="cacheManager"></param> /// <param name="readerCreator"></param> /// <param name="site"></param> /// <param name="viewingUser"></param> /// <param name="siteList"></param> /// <param name="forumId"></param> /// <param name="ThreadId"></param> /// <param name="_iPAddress"></param> /// <param name="bbcUidCookie"></param> public void PostToForum(ICacheManager cacheManager, IDnaDataReaderCreator readerCreator, ISite site, IUser viewingUser, ISiteList siteList, string _iPAddress, Guid bbcUidCookie, int forumId) { if (viewingUser.UserId == 0) { throw ApiException.GetError(ErrorType.NotAuthorized); } ForumSource forumSource = ForumSource.CreateForumSource(cacheManager, readerCreator, null, forumId, ThreadId, site.SiteID, false, false, false); if (forumSource == null) { throw ApiException.GetError(ErrorType.ForumUnknown); } bool isNotable = viewingUser.IsNotable; ForumHelper helper = new ForumHelper(readerCreator); bool ignoreModeration = viewingUser.IsEditor || viewingUser.IsSuperUser; // Check 4) check ThreadId exists and user has permission to write if (!ignoreModeration) { if (ThreadId != 0) { bool canReadThread = false; bool canWriteThread = false; helper.GetThreadPermissions(viewingUser.UserId, ThreadId, ref canReadThread, ref canWriteThread); if (!canReadThread) { throw ApiException.GetError(ErrorType.NotAuthorized); } if (!canWriteThread) { throw ApiException.GetError(ErrorType.ForumReadOnly); } } else { bool canReadForum = false; bool canWriteForum = false; helper.GetForumPermissions(viewingUser.UserId, forumId, ref canReadForum, ref canWriteForum); if (!canReadForum) { throw ApiException.GetError(ErrorType.NotAuthorized); } if (!canWriteForum) { throw ApiException.GetError(ErrorType.ForumReadOnly); } } } if (viewingUser.IsBanned) { throw ApiException.GetError(ErrorType.UserIsBanned); } if (!ignoreModeration && (site.IsEmergencyClosed || site.IsSiteScheduledClosed(DateTime.Now))) { throw ApiException.GetError(ErrorType.SiteIsClosed); } if (String.IsNullOrEmpty(Text)) { throw ApiException.GetError(ErrorType.EmptyText); } try { int maxCharCount = siteList.GetSiteOptionValueInt(site.SiteID, "CommentForum", "MaxCommentCharacterLength"); string tmpText = StringUtils.StripFormattingFromText(Text); if (maxCharCount != 0 && tmpText.Length > maxCharCount) { throw ApiException.GetError(ErrorType.ExceededTextLimit); } } catch (SiteOptionNotFoundException) { } try { //check for option - if not set then it throws exception int minCharCount = siteList.GetSiteOptionValueInt(site.SiteID, "CommentForum", "MinCommentCharacterLength"); string tmpText = StringUtils.StripFormattingFromText(Text); if (minCharCount != 0 && tmpText.Length < minCharCount) { throw ApiException.GetError(ErrorType.MinCharLimitNotReached); } } catch (SiteOptionNotFoundException) { } //Only check xml parsing for richtext plain text we want what is there so smileys etc work //if (this.Style == PostStyle.Style.richtext) //{ // string errormessage = string.Empty; // // Check to make sure that the comment is made of valid XML // if (!HtmlUtils.ParseToValidGuideML(Text, ref errormessage)) // { // throw ApiException.GetError(ErrorType.XmlFailedParse); // } //} bool forceModeration; string matchingProfanity= string.Empty; string profanityxml = string.Empty; string postString = Subject + " " + Text; List<Term> terms = null; if (InReplyTo > 0) {//only check text if not first post postString = Text; } CheckForProfanities(site, postString, out forceModeration, out matchingProfanity, out terms, forumId); if (false == string.IsNullOrEmpty(matchingProfanity)) { matchingProfanity = "Filtered terms: " + matchingProfanity; // Adding an extra bit of information for clarity } if (terms != null && terms.Count > 0) { profanityxml = new Term().GetProfanityXML(terms); } //check posting frequency if (!viewingUser.IsEditor && !viewingUser.IsSuperUser && !viewingUser.IsNotable) { SecondsToWait = CheckPostFrequency(readerCreator, viewingUser.UserId, site.SiteID); if (SecondsToWait != 0) { var error = ApiException.GetError(ErrorType.PostFrequencyTimePeriodNotExpired); ApiException newError = new ApiException( error.Message + " You must wait " + SecondsToWait.ToString() + " more seconds before posting.", error.type); throw newError; } } bool forcePreModeration = false; // PreModerate first post in discussion if site premoderatenewdiscussions option set. if ((InReplyTo == 0) && siteList.GetSiteOptionValueBool(site.SiteID, "Moderation", "PreModerateNewDiscussions")) { if (!ignoreModeration && !isNotable) { forcePreModeration = true; } } if (forumSource.Type == ForumSourceType.Journal && ThreadId == 0) { CreateJournalPost(readerCreator, site.SiteID, viewingUser.UserId, viewingUser.UserName, forumId, false, _iPAddress, bbcUidCookie, forceModeration); } else { CreateForumPost(readerCreator, viewingUser.UserId, forumId, ignoreModeration, isNotable, _iPAddress, bbcUidCookie, false, false, forcePreModeration, forceModeration, matchingProfanity, profanityxml); } }