Пример #1
0
        /// <summary>
        /// The default constructor
        /// </summary>
        /// <param name="context">An object that supports the IInputContext interface. basePage</param>
        public PostToForumBuilder(IInputContext context)
            : base(context)
        {
            _creator = new DnaDataReaderCreator(AppContext.TheAppContext.Config.ConnectionString,
                                                AppContext.TheAppContext.Diagnostics);

            _cache = CacheFactory.GetCacheManager();
            //this is a clutch until we unify user objects
            _viewingUser = InputContext.ViewingUser.ConvertUser();

            _forumHelper = new ForumHelper(_creator, _viewingUser, InputContext.TheSiteList);
        }
Пример #2
0
        /// <summary>
        /// Converts BBC.Dna.User to BBC.Dna.Objects.User
        /// A hack until user objects are unified.
        /// </summary>
        /// <returns></returns>
        public BBC.Dna.Objects.User ConvertUser()
        {
            BBC.Dna.Objects.User userObj = new BBC.Dna.Objects.User(AppContext.ReaderCreator, AppContext.TheAppContext.Diagnostics, AppContext.DnaCacheManager)
            {
                UserId = UserID,
                UserLoggedIn = UserLoggedIn,
                Status = IsSuperUser ? 2 : 0,
                PrefStatus = _prefStatus
            };

            userObj.Groups = new List<Group>();
            foreach (string group in _userGroupsData)
            {
                userObj.Groups.Add(new Group() { Name = group.ToUpper() });
            }
            return userObj;
        }
Пример #3
0
        /// <summary>
        /// Functions generates the Recent Posts List
        /// </summary>
        /// <param name="userID">The user of the posts to get</param>
        /// <param name="skip">number of posts to skip</param>
        /// <param name="show">number to show</param>
        /// <param name="postType">Type of posts to look for</param>
        /// <param name="siteID">Site of the posts</param>
        /// <returns>Whether created ok</returns>
        public bool CreateRecentPostsList(int userID, int skip, int show, int postType, int siteID)
        {
	        //TDVASSERT(userID > 0, "CreateRecentPostsList(...) called with non-positive ID");
	        //TDVASSERT(iMaxNumber > 0, "CreateRecentPostsList(...) called with non-positive max number of posts");
        	
	        // check object is not already initialised
	        if (userID <= 0 || show <= 0)
	        {
		        return false;
	        }

	        bool showPrivate = false;
            if (InputContext.ViewingUser != null && (userID == InputContext.ViewingUser.UserID || InputContext.ViewingUser.IsEditor))
	        {
		        showPrivate = true;
	        }

	        //Allow post authors to see their user-deleted notices and events.
	        bool showUserHidden = showPrivate && (postType == 1 || postType == 2);
            int count = 0;
            int rows = 0;

            XmlElement postList = AddElementTag(RootElement, "POST-LIST");
            AddAttribute(postList, "SHOW", show);
            AddAttribute(postList, "SKIPTO", skip);
            //AddAttribute(postList, "COUNT", show);

            using (IDnaDataReader dataReader = GetUsersMostRecentPosts(userID, skip, show, postType, siteID, showUserHidden))
            {         
		        // Check to see if we found anything
		        string userName = String.Empty;
		        if (dataReader.HasRows && dataReader.Read())
		        {
                    User user = new User(InputContext);
                    user.AddUserXMLBlock(dataReader, userID, postList);
       		
                    string threadPostType = String.Empty;
                    string threadSubject = String.Empty;
		            ArrayList noticeThreadIDArray = new ArrayList();
		            int threadID = 0;
		            int postSiteID = 0;		
		            int IsPostingFromVisibleSite = 0;

                    if (skip > 0)
                    {
                        //Read/skip over the skip number of rows so that the row that the first row that in the do below is 
                        //the one required
                        for (int i = 0; i < skip; i++)
                        {
                            dataReader.Read();
                        }
                    }
                    //TODO think i will need to check if the reads fail above ie you skip past the end
		            Forum Forum = new Forum(InputContext);

		            do
		            {
			            IsPostingFromVisibleSite = dataReader.GetInt32NullAsZero("IsPostingFromVisibleSite"); 
			            if (IsPostingFromVisibleSite == 1)
			            {
 				            // Setup the Post Tag and Attributes
                            XmlElement post = CreateElement("POST");

				            AddAttribute(post, "COUNTPOSTS", dataReader.GetInt32NullAsZero("CountPosts"));

				            if (showPrivate)
				            {
                                AddAttribute(post, "LASTPOSTCOUNTREAD", dataReader.GetInt32NullAsZero("LastPostCountRead"));
				            }

				            // Add User-Hidden Status.
				            if ( showUserHidden && dataReader.DoesFieldExist("Hidden") && dataReader.GetInt32NullAsZero("Hidden") > 0 )
                            {
                                AddAttribute(post, "HIDDEN", dataReader.GetInt32NullAsZero("HIDDEN"));
				            }

				            int yourLastPost = dataReader.GetInt32NullAsZero("YourLastPost");			
            		
				            //add the editable attribute
                            if (InputContext.ViewingUser != null)
				            {
					            int editable = 0;
                                if (InputContext.ViewingUser.UserID != userID)
					            {
						            editable = 0;
					            }
					            else
					            {
						            if (yourLastPost > 0 )
						            {
							            DateTime dateMostRecent = dataReader.GetDateTime("MostRecent");		
                                        editable = Forum.GetPostEditableAttribute(userID, dateMostRecent);
						            }
						            else
						            {
							            editable = 0;
						            }
					            }
                                AddAttribute(post, "EDITABLE", editable);
				            }

                            AddAttribute(post, "PRIVATE", dataReader.GetInt32NullAsZero("Private"));

				            // Add the siteid and reply details
                            postSiteID = dataReader.GetInt32NullAsZero("SiteID");
                            AddIntElement(post, "SITEID", postSiteID);
                            AddIntElement(post, "HAS-REPLY", dataReader.GetInt32NullAsZero("Replies"));


				            // Setup a Thread Tag and Attributes
                            XmlElement thread = CreateElement("Thread");
                            AddAttribute(thread, "FORUMID", dataReader.GetInt32NullAsZero("ForumID"));
                           
                            threadID = dataReader.GetInt32NullAsZero("ThreadID");
                            AddAttribute(thread, "THREADID", threadID);

				            // Add the first post id if it exists in the result set
				            if (dataReader.DoesFieldExist("FirstPostID"))
				            {
                                AddAttribute(thread, "FIRSTPOSTID", dataReader.GetInt32NullAsZero("FirstPostID"));
				            }

                            threadPostType = dataReader.GetStringNullAsEmpty("Type");
                            AddAttribute(thread, "TYPE", threadPostType);

                            AddDateXml(dataReader, thread, "EVENTDATE", "EventDate");
                            AddDateXml(dataReader, thread, "DATEFIRSTPOSTED", "DateFirstPosted");

				            // See if we've got an notice or event, if so then get the taginfo for the post
                            if (threadPostType == "notice" || threadPostType == "event")
				            {
					            // Add the threadid to the array so we can get the tag details later
					            noticeThreadIDArray.Add(threadID);
				            }

				            // Add the Subject 
                            threadSubject = ThreadPost.FormatSubject(dataReader.GetStringNullAsEmpty("FirstSubject"), CommentStatus.Hidden.NotHidden);
                            AddTextTag(thread, "SUBJECT", threadSubject);
                            
                            AddDateXml(dataReader, thread, "LastReply", "REPLYDATE");

				            // If we have a journal user then put the following in...
				            if (dataReader.GetInt32NullAsZero("Journal") > 0)
				            {
                                XmlElement journal = CreateElement("JOURNAL");
                                AddAttribute(journal, "USERID", dataReader.GetInt32NullAsZero("Journal"));

                                AddTextTag(journal, "UserName", dataReader.GetStringNullAsEmpty("JournalName"));
                                AddTextTag(journal, "Area", dataReader.GetStringNullAsEmpty("JournalArea"));
                                AddTextTag(journal, "FirstNames", dataReader.GetStringNullAsEmpty("JournalFirstNames"));
                                AddTextTag(journal, "LastName", dataReader.GetStringNullAsEmpty("JournalLastName"));
                                AddTextTag(journal, "Title", dataReader.GetStringNullAsEmpty("JournalTitle"));
                                AddTextTag(journal, "SiteSuffix", dataReader.GetStringNullAsEmpty("JournalSiteSuffix"));

                                thread.AppendChild(journal);
				            }

				            // Get the ForumInfo and Last post details
                            //AddTextTag(thread, "ForumTitle", dataReader.GetStringNullAsEmpty("ForumTitle"));
                            string forumTitle = dataReader.GetStringNullAsEmpty("ForumTitle");
                            XmlElement forumTitleElement = AddTextElement(thread, "ForumTitle", "");
                            try
                            {
                                forumTitleElement.InnerXml = forumTitle;
                            }
                            catch (System.Xml.XmlException ex)
                            {
                                AppContext.TheAppContext.Diagnostics.WriteWarningToLog("PostList", "Escaping character in Forum Title" + ex.Message);
                                forumTitleElement.InnerXml = StringUtils.EscapeAllXml(forumTitle);
                            }

                            if (yourLastPost > 0)
				            {
                                XmlElement lastUserPost = CreateElement("LASTUSERPOST");
                                AddAttribute(lastUserPost, "POSTID", yourLastPost );
                                AddDateXml(dataReader, lastUserPost, "MostRecent", "DATEPOSTED");
                                thread.AppendChild(lastUserPost);
				            }

				            // Close the ThreadTag
                            post.AppendChild(thread);

				            // Add the first poster info
				            int firstPostUserID = 0;
                            XmlElement firstPoster = CreateElement("FIRSTPOSTER");
                            firstPostUserID = dataReader.GetInt32NullAsZero("FirstPosterUserID");
                            user.AddPrefixedUserXMLBlock(dataReader, firstPostUserID, "FirstPoster", firstPoster);
                            post.AppendChild(firstPoster);

				            // Finally close the POST tag
                            postList.AppendChild(post);
                            count++;
			            }
                        rows++;
                    } while (rows < show && dataReader.Read());
                    if (dataReader.Read())
                    {
                        AddAttribute(postList, "MORE", 1);
                    }

		            // Now insert the tag info for any notices or events found
		            if (noticeThreadIDArray.Count > 0)
		            {
			            // Set up some locals
			            string taggedNodeInfo;
			            int noticeThreadID = 0;
			            TagItem tagItem = new TagItem(InputContext);

			            // Now go through the list adding the taginfo into the XML
			            for (int i = 0; i < noticeThreadIDArray.Count; i++)
			            {
				            // Get the ThreadId for the current Index
				            noticeThreadID = (int) noticeThreadIDArray[i];
				            taggedNodeInfo = String.Empty;

				            // Get the Tagging locations!
				            if (tagItem.InitialiseFromThreadId(noticeThreadID, siteID, userID, threadSubject, false) && tagItem.GetAllNodesTaggedForItem())
				            {
					            // Get the taginfo from the tagitem object and insert it into the page
					            //tagItem.GetAsString(taggedNodeInfo);
					            //AddInsideWhereIntAttributeEquals("THREAD", "THREADID", noticeThreadID, taggedNodeInfo, 1);

                                string xpath = "/THREAD[@THREADID=" + noticeThreadID.ToString() + "]";
                                XmlNodeList threads = postList.SelectNodes(xpath);
                                if (threads.Count > 0)
                                {
                                    foreach (XmlNode thread in threads)
                                    {
                                        SiteXmlBuilder siteXml = new SiteXmlBuilder(InputContext);
                                        thread.AppendChild(ImportNode(siteXml.GenerateAllSitesXml(InputContext.TheSiteList).FirstChild));
                                    }
                                }
				            }
				            else
				            {
					            // Setup an error for this post!
					            throw new DnaException("CreateRecentPostsList : FailedToGetTagInfo - Failed to get Tagging Info for post");
				            }
			            }
		            }
                }
            }
            AddAttribute(postList, "COUNT", count);

	        RemovePrivatePosts(showPrivate);

	        return true;
        }
Пример #4
0
 /// <summary>
 /// Helper function to set up parameters for CreateArticleListTest call
 /// </summary>
 /// <param name="mocks"></param>
 /// <param name="cache"></param>
 /// <param name="readerCreator"></param>
 /// <param name="viewingUser"></param>
 public void CreateArticleListTest_SetupDefaultMocks(out MockRepository mocks, 
     out ICacheManager cache, 
     out IDnaDataReaderCreator readerCreator, 
     out User viewingUser, 
     out ISite site)
 {
     mocks = new MockRepository();
     cache = mocks.DynamicMock<ICacheManager>();
     readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
     viewingUser = UserTest.CreateTestUser();
     site = mocks.DynamicMock<ISite>();
 }
Пример #5
0
        private Article SetWritableArticleProperties(Article article, GuideEntryStyle style, string subject, string guideML,  int[] researcherUserIds)
        {
            //Need to set this before processing the guideML
            article.Style = style;

            // populate the writable parts of the object graph with the input article
            if (guideML != String.Empty)
            {
                article.GuideMLAsString = guideML;
                article.ArticleInfo.GetReferences(readerCreator, article.OriginalGuideMLAsXmlElement);
                
                if (!article.IsGuideMLWellFormed) 
                { 
                    article.XmlError = "GuideML is badly formed2";
                    throw new Exception("GuideML is badly formed"); 
                }
            }


            if (subject != String.Empty)
            {
                article.Subject = subject;
            }
            
            if (researcherUserIds != null)
            {
                article.ArticleInfo.PageAuthor.Researchers.Clear();
                foreach (int researcherId in researcherUserIds)
                {
                    BBC.Dna.Objects.User user = new BBC.Dna.Objects.User();
                    user.UserId = researcherId;
                    article.ArticleInfo.PageAuthor.Researchers.Add(user);
                }
            }

            return article;
        }
Пример #6
0
 private static void CreateMocks(out MockRepository mocks, out IDnaDataReaderCreator readerCreator, out IDnaDataReader reader, out User viewingUser)
 {
     mocks = new MockRepository();
     readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
     reader = mocks.DynamicMock<IDnaDataReader>();
     viewingUser = UserTest.CreateTestUser();
 }
Пример #7
0
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        

        public static User CreateTestUser()
        {
            IUser target = new User(null, null, null)
            {
                UserId = 1,
                IdentityUserId = "90680774725696464",
                UserMode = 1,
                UnReadPrivateMessageCount = 0,
                UnReadPublicMessageCount = 1,
                AcceptSubscriptions = 1,
                Active = true,
                Allocations = 5,
                Area = "area",
                DateJoined = new DateElement(DateTime.Now.AddDays(-5)),
                DateLastNotified = new DateElement(DateTime.Now.AddDays(-2)),
                Email = "*****@*****.**",
                FirstNames = "marcus",
                LastName = "parnwell",
                ForumId = 56,
                ForumPostedTo = 4,
                HideLocation = 1,
                HideUsername = 1,
                Journal = 1,
                MastHead = 3423,
                PostCode = "w14",
                PrefUserMode = false,
                PromptSetUsername = true,
                Region = "london",
                Score = 0.0,
                SinBin = 1,
                SiteSuffix = "h2g2",
                Status = (int)UserStatus.Active,
                SubQuota = 1,
                TaxonomyNode = 1,
                TeamId = 0,
                Title = "mr",
                UserName = "******"

            };
            return (User)target;
        }
Пример #8
0
        /// <summary>
        /// Functions generates the User Statistics XML
        /// </summary>
        /// <param name="userID">The user of the statistics to get</param>
        /// <param name="skip">Number of posts to skip</param>
        /// <param name="show">Number of posts to show</param>
        /// <param name="mode">Way the records are returned by dateposted or by forum</param>
        /// <param name="startDate">Start Date</param>
        /// <param name="endDate">End Date</param>
        public void TryCreateUserStatisticsXML(int userID, int skip, int show, int mode, DateTime startDate, DateTime endDate)
        {
            //Clean any existing XML.
            RootElement.RemoveAll();

            //Must be logged in.
            if (InputContext.ViewingUser.UserID == 0 || !InputContext.ViewingUser.UserLoggedIn)
            {
                //return error.
                AddErrorXml("invalidcredentials", "Must be logged in to view user statistics.", RootElement);
                return;
            }
            if (!InputContext.ViewingUser.IsEditor && !InputContext.ViewingUser.IsSuperUser)
            {
                //return error.
                AddErrorXml("invalidcredentials", "Must be an editor or superuser to view user statistics.", RootElement);
                return;
            }

            int recordsCount = 0;
            int total = 0;
            int numberToTryandGet = show + 1;
            bool more = false;

            string userName = String.Empty;

            XmlElement userStatistics = AddElementTag(RootElement, "USERSTATISTICS");
            AddAttribute(userStatistics, "USERID", userID);
            if (mode == 0)
            {
                AddAttribute(userStatistics, "DISPLAYMODE", "byforum");
            }
            else
            {
                AddAttribute(userStatistics, "DISPLAYMODE", "ungrouped");
            }
            AddAttribute(userStatistics, "SKIPTO", skip);
            AddAttribute(userStatistics, "SHOW", show);
            AddDateXml(startDate, userStatistics, "STARTDATE");
            AddDateXml(endDate, userStatistics, "ENDDATE");

            using (IDnaDataReader dataReader = InputContext.CreateDnaDataReader(GetUserStatisticsSP(mode)))
            {
                dataReader.AddParameter("userid", userID);
                dataReader.AddParameter("siteid", InputContext.CurrentSite.SiteID);
                dataReader.AddParameter("skip", skip);
                dataReader.AddParameter("show", numberToTryandGet);
                dataReader.AddParameter("mode", mode);
                dataReader.AddParameter("startdate", startDate);
                dataReader.AddParameter("enddate", endDate);
                dataReader.AddIntOutputParameter("recordscount");
                dataReader.Execute();

                // Check to see if we found anything
                if (dataReader.HasRows && dataReader.Read())
                {
                    User user = new User(InputContext);
                    user.AddUserXMLBlock(dataReader, userID, userStatistics);
                    userName = dataReader.GetStringNullAsEmpty("UserName"); ;

                    dataReader.NextResult();
                    if (dataReader.HasRows && dataReader.Read() & numberToTryandGet > 0)
                    {
                        total = dataReader.GetInt32NullAsZero("total");

                        XmlElement forum = CreateElement("FORUM");
                        XmlElement thread = CreateElement("THREAD");

                        int previousForumID = 0;
                        int previousThreadID = 0;

                        do
                        {
                            int forumID = dataReader.GetInt32NullAsZero("ForumID");
                            int threadID = dataReader.GetInt32NullAsZero("ThreadID");
                            int postID = dataReader.GetInt32NullAsZero("EntryID");
                            int hidden = dataReader.GetInt32NullAsZero("Hidden");
                            int siteID = dataReader.GetInt32NullAsZero("SiteID");
                            int postIndex = dataReader.GetInt32NullAsZero("PostIndex");

                            string title = dataReader.GetStringNullAsEmpty("Title");
                            string subject = dataReader.GetStringNullAsEmpty("Subject");
                            string firstSubject = dataReader.GetStringNullAsEmpty("FirstSubject");
                            string siteName = dataReader.GetStringNullAsEmpty("URLName");

                            string url = dataReader.GetStringNullAsEmpty("Url");

                            DateTime datePosted = dataReader.GetDateTime("DatePosted");

                            //close previously opened THREAD if any
                            if (threadID != previousThreadID && previousThreadID != 0)
                            {
                                forum.AppendChild(thread);
                            }

                            //close previously opened FORUM if any
                            if (forumID != previousForumID && previousForumID != 0)
                            {
                                userStatistics.AppendChild(forum);
                            }

                            //check if current forum id differs from the previous one. This will mean
                            //that entries for the previous forum are over and we should close
                            //the xml element for that forum and start new one for the current forum
                            if (forumID != previousForumID)
                            {
                                forum = CreateElement("FORUM");
                                AddAttribute(forum, "FORUMID", forumID);
                                AddTextTag(forum, "SUBJECT", title);
                                AddIntElement(forum, "SITEID", siteID);
                                AddTextTag(forum, "SITENAME", siteName);
                                AddTextTag(forum, "URL", url);

                                thread = CreateElement("THREAD");
                                AddAttribute(thread, "THREADID", threadID);
                                AddTextTag(thread, "SUBJECT", firstSubject);

                                previousForumID = forumID;
                                previousThreadID = threadID;
                            }
                            //check if current thread id differs from the previous one. This will mean
                            //that entries for the previous thread are over and we should close
                            //the xml element for that thread and start new one for the current thread
                            else if (threadID != previousThreadID)
                            {
                                thread = CreateElement("THREAD");
                                AddAttribute(thread, "THREADID", threadID);
                                AddTextTag(thread, "SUBJECT", firstSubject);

                                previousThreadID = threadID;
                            }

                            string body = dataReader.GetStringNullAsEmpty("text");
                            int style = 0;
                            if(dataReader.DoesFieldExist("PostStyle") && !dataReader.IsDBNull("PostStyle"))
                            {
                                style = dataReader.GetTinyIntAsInt("PostStyle");
                            }
                            if (style == 1)
                            {
                                body = ThreadPost.FormatPost(body, BBC.Dna.Moderation.Utils.CommentStatus.Hidden.NotHidden, true, false);
                                string temp = "<RICHPOST>" + body + "</RICHPOST>";
                                Regex regex = new Regex(@"(<[^<>]+)<BR \/>");
                                while (regex.Match(temp).Success)
                                {
                                    temp = regex.Replace(temp, @"$1 ");
                                }
                                body = temp;
                            }
                            else
                            {
                                body = StringUtils.ConvertPlainText(body);
                            }
                            XmlElement post = CreateElement("POST");
                            AddAttribute(post, "POSTID", postID);
                            AddAttribute(post, "THREADID", threadID);
                            AddAttribute(post, "HIDDEN", hidden);
                            AddTextTag(post, "SUBJECT", subject);

/*                            if (style != 1)
                            {
                                body = StringUtils.ConvertPlainText(body);
                            }
                            else
                            {
                                //TODO Do we need Rich Post stuff for the post style??
                                string temp = "<RICHPOST>" + body.Replace("\r\n", "<BR />").Replace("\n", "<BR />") + "</RICHPOST>";
                                body = temp;
                            }

 */ 
                            AddElement(post, "BODY", body);

                            AddIntElement(post, "PostIndex", postIndex);
                            AddDateXml(datePosted, post, "DATEPOSTED");

                            thread.AppendChild(post);
                            numberToTryandGet--;

                        } while (numberToTryandGet > 1 && dataReader.Read());

                        //close last opened THREAD if any
                        if (previousThreadID != 0)
                        {
                            forum.AppendChild(thread);
                        }

                        //close last opened FORUM if any
                        if (previousForumID != 0)
                        {
                            userStatistics.AppendChild(forum);
                        }

                        // See if there's an extra row waiting
                        if (dataReader.Read())
                        {
                            AddAttribute(userStatistics, "MORE", 1);
                            more = true;
                        }
                    }
                    dataReader.NextResult();
                    dataReader.TryGetIntOutputParameter("recordscount", out recordsCount);
                }
            }
            //The record count will also contain the extra 'more' row 
            //so need to take 1 off it to give a true indictation of the rows returned
            if (more)
            {
                recordsCount--;
            }

            AddAttribute(userStatistics, "COUNT", recordsCount);
            AddAttribute(userStatistics, "TOTAL", total);
            AddAttribute(userStatistics, "USERNAME", StringUtils.EscapeAllXmlForAttribute(userName));
        }
Пример #9
0
        /// <summary>
        /// The default constructor
        /// </summary>
        /// <param name="context">An object that supports the IInputContext interface. basePage</param>
        public EditPostPageBuilder(IInputContext context)
            : base(context)
        {
            _viewingUser = InputContext.ViewingUser.ConvertUser();

        }