/// <summary> /// Method called to update the statuses of any of the comment forums. /// </summary> private bool TryUpdateCommentForum() { string action = String.Empty; if (InputContext.TryGetParamString("dnaaction", ref action, "Action to take on this request. 'update' is the only action currently recognised")) { if (action == "create") { string uid = String.Empty; if (InputContext.DoesParamExist("dnauid", "The uid of the given comment forum.")) { InputContext.TryGetParamString("dnauid", ref uid, "The uid of the given comment forum."); if (uid == String.Empty) { return AddErrorXml("invalidparameters", "blank unique id provided", null); } } else { //Cannot continue. return AddErrorXml("invalidparameters", "No unique id provided", null); } string hostPageUrl = String.Empty; if (InputContext.DoesParamExist("dnahostpageurl", "The url of the given comment forum.")) { InputContext.TryGetParamString("dnahostpageurl", ref hostPageUrl, "The url of the given comment forum."); if (hostPageUrl == String.Empty) { return AddErrorXml("invalidparameters", "blank url provided", null); } } else { //Cannot continue. return AddErrorXml("invalidparameters", "No url provided", null); } string title = String.Empty; if (InputContext.DoesParamExist("dnatitle", "The title of the given comment forum.")) { InputContext.TryGetParamString("dnatitle", ref title, "The title of the given comment forum."); if (title == String.Empty) { return AddErrorXml("invalidparameters", "blank title provided", null); } } else { //Cannot continue. return AddErrorXml("invalidparameters", "No title provided", null); } ISite siteForForum = InputContext.CurrentSite; if (InputContext.DoesParamExist("dnasitename", "The name of the dna site you want to use")) { string siteURLName = ""; if (InputContext.TryGetParamString("dnasitename", ref siteURLName, "The name of the dna site you want to use")) { siteForForum = InputContext.TheSiteList.GetSite(siteURLName); if (siteForForum == null) { return AddErrorXml("invalidparameters", "invalid dna site name", null); } } } CommentForum forum = new CommentForum() { Id = uid, ParentUri = hostPageUrl, Title = title }; Comments comments = new Comments(AppContext.TheAppContext.Diagnostics, AppContext.ReaderCreator, CacheFactory.GetCacheManager(), InputContext.TheSiteList); try { comments.CreateCommentForum(forum, siteForForum); } catch(ApiException e) { return AddErrorXml(e.type.ToString(), e.Message, null); } } if (action == "update") { string newCloseDateParam = String.Empty; object newCloseDate = null; int newModStatus = 0; int newCanWrite = 0; string uid = String.Empty; string docUid = "The uid of the given comment forum."; bool uidExists = false; uidExists = InputContext.DoesParamExist("dnauid", docUid); if (uidExists) { InputContext.TryGetParamString("dnauid", ref uid, docUid); if (uid == String.Empty) { return AddErrorXml("invalidparameters", "blank unique id provided", null); } } else { //Cannot continue. return AddErrorXml("invalidparameters", "No unique id provided", null); } string docNewForumCloseDate = "The new CommentBoxForum Close Date for the given comment forum."; bool newNewForumCloseDateExists = false; newNewForumCloseDateExists = InputContext.DoesParamExist("dnanewforumclosedate", docNewForumCloseDate); if (newNewForumCloseDateExists) { InputContext.TryGetParamString("dnanewforumclosedate", ref newCloseDateParam, docNewForumCloseDate); // Try to parse the date try { // Set the closing date from the value - The format of the date is YYYYMMDD. newCloseDate = new DateTime(Convert.ToInt32(newCloseDateParam.Substring(0, 4)), Convert.ToInt32(newCloseDateParam.Substring(4, 2).TrimStart('0')), Convert.ToInt32(newCloseDateParam.Substring(6, 2).TrimStart('0'))); } catch (Exception ex) { return AddErrorXml("invalidparameters", "Invalid date format given for forumclosedate. " + ex.Message, null); } } string docNewModStatus = "The new Moderation Status for the given comment forum."; bool newModStatusExists = false; newModStatusExists = InputContext.DoesParamExist("dnanewmodstatus", docNewModStatus); if (newModStatusExists) { string dnaNewModStatus = InputContext.GetParamStringOrEmpty("dnanewmodstatus", docNewModStatus); if (dnaNewModStatus == "reactive") { newModStatus = 1; } else if (dnaNewModStatus == "postmod") { newModStatus = 2; } else if (dnaNewModStatus == "premod") { newModStatus = 3; } else { return AddErrorXml("invalidparameters", "Illegal New Moderation Status setting (" + dnaNewModStatus + ")", null); } } int fastModStatus = 0; bool newFastModStatusExists = InputContext.DoesParamExist("dnafastmod", ""); if (newFastModStatusExists) { var fastModVal = InputContext.GetParamStringOrEmpty("dnafastmod", ""); if (fastModVal.ToUpper() == "ENABLED") { fastModStatus = 1; } else { fastModStatus = 0; } } string docNewCanWrite = "The new Open Close Status for the given comment forum."; bool newNewCanWriteExists = false; newNewCanWriteExists = InputContext.DoesParamExist("dnanewcanwrite", docNewCanWrite); if (newNewCanWriteExists) { newCanWrite = InputContext.GetParamIntOrZero("dnanewcanwrite", docNewCanWrite); } #region Anonymous Posting int forumId = 0; if (InputContext.DoesParamExist("forumid", "Forum ID")) { forumId = InputContext.GetParamIntOrZero("forumid", "Forum ID"); } bool anonymousPostingStatusExists = false; anonymousPostingStatusExists = InputContext.DoesParamExist("dnaanonymoussetting", ""); if (anonymousPostingStatusExists && forumId != 0) { var anonPostVal = InputContext.GetParamStringOrEmpty("dnaanonymoussetting", ""); if (anonPostVal.ToUpper() == "ALLOW") { if (InputContext.TheSiteList.GetSiteOptionValueBool(InputContext.CurrentSite.SiteID, "CommentForum", "AllowNotSignedInCommenting")) { var user = new Dna.Users.User(AppContext.ReaderCreator, AppContext.TheAppContext.Diagnostics, AppContext.DnaCacheManager); user.CreateAnonymousUserForForum(InputContext.CurrentSite.SiteID, forumId, ""); } } } #endregion if (newNewForumCloseDateExists || newModStatusExists || newNewCanWriteExists || newFastModStatusExists) { using (IDnaDataReader dataReader = InputContext.CreateDnaDataReader("updatecommentforumstatus")) { dataReader.AddParameter("uid", uid); if (newNewForumCloseDateExists && newCloseDate != null) { dataReader.AddParameter("forumclosedate", newCloseDate); } else { dataReader.AddParameter("forumclosedate", DBNull.Value); } if (newModStatusExists) { dataReader.AddParameter("modstatus", newModStatus); } else { dataReader.AddParameter("modstatus", DBNull.Value); } if (newNewCanWriteExists) { dataReader.AddParameter("canwrite", newCanWrite); } else { dataReader.AddParameter("canwrite", DBNull.Value); } if (newFastModStatusExists) { dataReader.AddParameter("fastmod", fastModStatus); } else { dataReader.AddParameter("fastmod", DBNull.Value); } dataReader.Execute(); } } } } return true; }
public void GivenIHaveAnCommentInTheReferalQueue() { //To get to this stage we need:- //1. Create a comment forum (make it pre-mod) //2. Add at least 2 posts //3. Refer the first post // a) for a post to be referred it should be in the mod queue (so - make the comment forum pre-mod //Let's not make a web request if possible - we'll need the databse though //SnapshotInitialisation.RestoreFromSnapshot(); //TODO: SnapshotInitialisation should not depend on IIS at all. //Whatever info is required should be injected. //TODO: get this from config string connectionString = @"database=smallGuide; server=.\MSSQL2008R2; user id=sa; password=Thanatos99; pooling=false"; DataReaderCreator = new DnaDataReaderCreator(connectionString, Diagnostics.Object); SiteList = new SiteList(DataReaderCreator, Diagnostics.Object, CacheManager.Object, RipleyServerAddresses, DotNetServerAddresses); var comments = new BBC.Dna.Api.Comments(Diagnostics.Object, DataReaderCreator, CacheManager.Object, SiteList); Forum = new Forum(); Forum.Id = "distress-message-fun-and-games"; Forum.ParentUri = "http://www.bbc.co.uk/dna/h2g2"; Forum.Title = "distress-message-fun-and-games"; Forum.ModerationServiceGroup = ModerationStatus.ForumStatus.PostMod; Site.Setup(x => x.SiteID).Returns(1); Site.Setup(x => x.SiteName).Returns("h2g2"); //see if this comment forum already exists var commentForum = comments.GetCommentForumByUid(Forum.Id, Site.Object, true); if (commentForum == null) { commentForum = comments.CreateCommentForum(Forum, Site.Object); } //save the forumid for later in the test CommentForumId = commentForum.ForumID; //if we have less than 2 comments we need to get up to 2 int commentCount = commentForum.commentList.TotalCount; while (commentCount < 2) { //Ok this is what I want to do but... //commentForum.Post(new Comment(...)); //TODO: can we add this method through a good refactor var commentInfo = new CommentInfo(); commentInfo.text = "Simple comment text " + commentCount.ToString(); var callingUser = new Mock<ICallingUser>(); callingUser.Setup(x => x.UserID).Returns(TestUserAccounts.GetNormalUserAccount.UserID); callingUser.Setup(x => x.IsSecureRequest).Returns(true); comments.CallingUser = callingUser.Object; var info = comments.CreateComment(commentForum, commentInfo); commentCount++; } }