예제 #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
        public void MarkThreadRead_ValidDbCall_ReturnsNoExceptions()
        {
            
            IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>();
            IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("markthreadread")).Return(reader);
            mocks.ReplayAll();

            int userId = 0; 
            int threadId = 0; 
            int postId = 0; 
            bool force = false;
            ForumHelper helper = new ForumHelper(creator);
            helper.MarkThreadRead(userId, threadId, postId, force);
            helper.MarkThreadRead(userId, threadId, postId, true);
            
        }
예제 #3
0
        /// <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);
            }
        }
예제 #4
0
        public void AddThreadToSticky_DatabaseError_ReturnsValidError()
        {
            var viewingUser = mocks.DynamicMock<IUser>();
            viewingUser.Stub(x => x.IsEditor).Return(false);
            viewingUser.Stub(x => x.IsSuperUser).Return(true);

            var siteList = mocks.DynamicMock<ISiteList>();
            siteList.Stub(x => x.GetSiteOptionValueBool(0, "Forum", "EnableStickyThreads")).Return(true);

            var reader = mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.Execute()).IgnoreArguments().Throw(new Exception("Database error"));

            var creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("addthreadtostickylist")).Return(reader).Repeat.AtLeastOnce();
            mocks.ReplayAll();

            var target = new ForumHelper(creator, viewingUser, siteList);
            target.AddThreadToStickyList(0, 0, 0);
            Assert.AreEqual("AddThreadToStickyList", target.LastError.Type);
            Assert.AreEqual("Unable to update database.", target.LastError.ErrorMessage);

        }
예제 #5
0
        public void AddThreadToSticky_NotAuthorised_ReturnsValidError()
        {
            var viewingUser = mocks.DynamicMock<IUser>();
            viewingUser.Stub(x => x.IsEditor).Return(false);
            viewingUser.Stub(x => x.IsSuperUser).Return(false);

            var siteList = mocks.DynamicMock<ISiteList>();
            siteList.Stub(x => x.GetSiteOptionValueBool(0, "Forum", "EnableStickyThreads")).Return(true);

            //var reader = mocks.DynamicMock<IDnaDataReader>();
            var creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("addthreadtostickylist")).Throw(new Exception("addthreadtostickylist should not have been called"));
            mocks.ReplayAll();

            var target = new ForumHelper(creator, viewingUser, siteList);
            target.AddThreadToStickyList(0, 0, 0);
            Assert.AreEqual("AddThreadToStickyList", target.LastError.Type);
            Assert.AreEqual("Viewing user unauthorised.", target.LastError.ErrorMessage);

        }
예제 #6
0
        public void UpdateForumModerationStatus_NotRead_ReturnsValidError()
        {
            IUser viewingUser = mocks.DynamicMock<IUser>();
            viewingUser.Stub(x => x.IsEditor).Return(true);
            viewingUser.Stub(x => x.IsSuperUser).Return(false);

            ISiteList siteList = mocks.DynamicMock<ISiteList>();
            IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.HasRows).Return(false);
            reader.Stub(x => x.Read()).Return(false);
            reader.Stub(x => x.GetInt32NullAsZero("Success")).Return(1);


            IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("updateforummoderationstatus")).Return(reader).Repeat.AtLeastOnce();
            mocks.ReplayAll();


            ForumHelper target = new ForumHelper(creator, viewingUser, siteList);
            target.UpdateForumModerationStatus(0, 0);

            Assert.AreEqual("FORUM-MOD-STATUS-UPDATE", target.LastError.Type);
            Assert.AreEqual("Failed to update the moderation status of the forum!", target.LastError.ErrorMessage);


        }
예제 #7
0
        public void UpdateForumModerationStatus_NotSuperUser_ReturnsValidError()
        {
            IUser viewingUser = mocks.DynamicMock<IUser>();
            viewingUser.Stub(x => x.IsEditor).Return(false);
            viewingUser.Stub(x => x.IsSuperUser).Return(false);

            ISiteList siteList = mocks.DynamicMock<ISiteList>();
            IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.HasRows).Return(false);
            reader.Stub(x => x.Read()).Return(false);

            IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("updateforummoderationstatus")).Throw(new Exception("updateforummoderationstatus should not have been called"));
            mocks.ReplayAll();


            ForumHelper target = new ForumHelper(creator, viewingUser, siteList);
            target.UpdateForumModerationStatus(0, 0);

            Assert.AreEqual("UpdateForumModerationStatus", target.LastError.Type);
            Assert.AreEqual("Logged in user is not authorised to update status", target.LastError.ErrorMessage);

        }
예제 #8
0
        public void ReOpenThread_IsInForum_ReturnsSuccess()
        {
            IUser viewingUser = mocks.DynamicMock<IUser>();
            viewingUser.Stub(x => x.IsEditor).Return(false);
            viewingUser.Stub(x => x.IsSuperUser).Return(true);

            ISiteList siteList = mocks.DynamicMock<ISiteList>();
            IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.HasRows).Return(false);
            reader.Stub(x => x.Read()).Return(true);
            reader.Stub(x => x.GetInt32NullAsZero("ThreadBelongsToForum")).Return(1);


            IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("SetThreadVisibletoUsers")).Return(reader).Repeat.AtLeastOnce();
            mocks.ReplayAll();


            ForumHelper target = new ForumHelper(creator, viewingUser, siteList);
            target.ReOpenThread(0, 0);

            Assert.IsNull(target.LastError);

        }
예제 #9
0
        public void CloseThread_AsSuperUser_CallsSp()
        {
            IUser viewingUser = mocks.DynamicMock<IUser>();
            viewingUser.Stub(x => x.IsEditor).Return(false);
            viewingUser.Stub(x => x.IsSuperUser).Return(true);

            IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.HasRows).Return(false);
            reader.Stub(x => x.Read()).Return(false);

            IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("closethread")).Return(reader).Repeat.AtLeastOnce();
            mocks.ReplayAll();

            ForumHelper target = new ForumHelper(creator, viewingUser, null);
            target.CloseThread(0, 0, 0);

        }
예제 #10
0
        public void GetForumPermissionsTest_NoData_ReturnsUnchangedDefaults()
        {
            IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.HasRows).Return(false);
            reader.Stub(x => x.Read()).Return(false);

            IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("getforumpermissions")).Return(reader);
            mocks.ReplayAll();


            int userId = 0;
            int forumId = 0;
            bool canRead = false;
            bool canReadExpected = false;
            bool canWrite = false;
            bool canWriteExpected = false;
            ForumHelper helper = new ForumHelper(creator);
            helper.GetForumPermissions(userId, forumId, ref canRead, ref canWrite);
            Assert.AreEqual(canReadExpected, canRead);
            Assert.AreEqual(canWriteExpected, canWrite);
        }
예제 #11
0
        public void GetForumPermissions_ValidDataSet_ReturnsExpectedResults()
        {
            int canReadOut = 0;
            int canWriteOut = 0;
            IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.TryGetIntOutputParameter("CanRead", out canReadOut)).Return(true).OutRef(1);
            reader.Stub(x => x.TryGetIntOutputParameter("CanWrite", out canWriteOut)).Return(true).OutRef(1);
            reader.Stub(x => x.HasRows).Return(true);
            reader.Stub(x => x.Read()).Return(true);

            IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("getforumpermissions")).Return(reader);
            mocks.ReplayAll();
 

            int userId = 0; 
            int forumId = 0; 
            bool canRead = false; 
            bool canReadExpected = true; 
            bool canWrite = false; 
            bool canWriteExpected = true;
            ForumHelper helper = new ForumHelper(creator);
            helper.GetForumPermissions(userId, forumId, ref canRead, ref canWrite);
            Assert.AreEqual(canReadExpected, canRead);
            Assert.AreEqual(canWriteExpected, canWrite);
        }
예제 #12
0
        public void RemoveThreadFromSticky_SiteOptionNotSet_ReturnsValidError()
        {
            var viewingUser = mocks.DynamicMock<IUser>();
            viewingUser.Stub(x => x.IsEditor).Return(false);
            viewingUser.Stub(x => x.IsSuperUser).Return(false);

            var siteList = mocks.DynamicMock<ISiteList>();
            siteList.Stub(x => x.GetSiteOptionValueBool(0, "Forum", "EnableStickyThreads")).Return(false);

            //var reader = mocks.DynamicMock<IDnaDataReader>();
            var creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("removethreadfromstickylist")).Throw(new Exception("RemoveThreadFromStickyList should not have been called"));
            mocks.ReplayAll();

            var target = new ForumHelper(creator, viewingUser, siteList);
            target.RemoveThreadFromStickyList(0, 0, 0);
            Assert.AreEqual("RemoveThreadFromStickyList", target.LastError.Type);
            Assert.AreEqual("'EnableStickyThreads' site option is false.", target.LastError.ErrorMessage);

        }
예제 #13
0
        public void CloseThread(string siteName, string forumId, string threadId)
        {
            // Check 1) get the site and check if it exists
            ISite site = GetSite(siteName);

            // Check 2) get the calling user             
            CallingUser callingUser = GetCallingUser(site);
            if (callingUser == null || callingUser.UserID == 0 || !callingUser.IsUserA(UserTypes.SuperUser))
            {
                throw new DnaWebProtocolException(ApiException.GetError(ErrorType.NotAuthorized));
            }

            try
            {
                int forumIdInt = Int32.Parse(forumId);
                int threadIdInt = Int32.Parse(threadId);
                ForumHelper forumHelper = new ForumHelper(readerCreator);

                forumHelper.CloseThreadWithCallingUser(site.SiteID, forumIdInt, threadIdInt, callingUser, siteList);
            }
            catch (ApiException ex)
            {
                throw new DnaWebProtocolException(ex);
            }
        }
예제 #14
0
        public ThreadPost CreateThreadPost(string siteName, string forumId, string threadId, ThreadPost threadPost)
        {
            int forumIdAsInt;
            try
            {
                forumIdAsInt = Convert.ToInt32(forumId);
            }
            catch
            {
                throw new DnaWebProtocolException(ApiException.GetError(ErrorType.ForumIDNotWellFormed));
            }
            int threadIdAsInt = 0;
            if (!Int32.TryParse(threadId, out threadIdAsInt))
            {
                throw new DnaWebProtocolException(ApiException.GetError(ErrorType.InvalidThreadID));
            }


            // Check 1) get the site and check if it exists
            ISite site = GetSite(siteName);

            // Check 2) get the calling user             
            CallingUser callingUser = GetCallingUser(site);
            if (callingUser == null || callingUser.UserID == 0)
            {
                throw new DnaWebProtocolException(ApiException.GetError(ErrorType.NotAuthorized));
            }

            bool requireSecurePost = siteList.GetSiteOptionValueInt(site.SiteID, "CommentForum", "EnforceSecurePosting") == 1;
            if (requireSecurePost && !callingUser.IsSecureRequest)
            {
                throw new DnaWebProtocolException(ApiException.GetError(ErrorType.NotSecure));
            }

            // Check 3) check threadid is well formed
            
            ForumHelper helper = new ForumHelper(readerCreator);

            
            // save the Post in the database
            threadPost.ThreadId = threadIdAsInt;
            try
            {
                threadPost.PostToForum(cacheManager, readerCreator, site, (Objects.User)callingUser, siteList, _iPAddress, bbcUidCookie, forumIdAsInt);
            }
            catch (ApiException e)
            {
                throw new DnaWebProtocolException(e);
            }

            return threadPost;
        }
예제 #15
0
        public Stream GetForumThreadsWithPost(string siteName, string forumId, string threadId, string postId)
        {
            bool applySkin = QueryStringHelper.GetQueryParameterAsBool("applyskin", false);
            
            ISite site = Global.siteList.GetSite(siteName);

            ForumThreadPosts forumThreadPosts = null;

            CallingUser callingUser = null;
            try
            {
                callingUser = GetCallingUser(site);
            }
            catch (DnaWebProtocolException)
            {
                callingUser = null;
            }

            int fourmIdInt = Int32.Parse(forumId);
            int threadIdInt = Int32.Parse(threadId);

            forumThreadPosts = ForumThreadPosts.CreateThreadPostsByCallingUser(readerCreator, cacheManager, callingUser, siteList, site.SiteID,
                Int32.Parse(forumId), Int32.Parse(threadId), itemsPerPage, startIndex, Int32.Parse(postId), (SortBy.Created == sortBy), false, applySkin);
            
            try
            {
                if (callingUser.UserID > 0)
                {
                    //get subscriptions
                    SubscribeState subscribeState = SubscribeState.GetSubscriptionState(readerCreator,
                                                                                        callingUser.UserID,
                                                                                        threadIdInt, 
                                                                                        fourmIdInt);

                    if (subscribeState != null && subscribeState.Thread != 0 && forumThreadPosts != null && forumThreadPosts.Post.Count > 0)
                    {
                        //update the last read post if the user is subscribed, increment by 1 because its a 0 based index
                        if (subscribeState.LastPostCountRead < forumThreadPosts.Post[forumThreadPosts.Post.Count - 1].Index + 1)
                        {
                            ForumHelper forumHelper = new ForumHelper(readerCreator);

                            forumHelper.MarkThreadRead(callingUser.UserID, threadIdInt,
                                                        forumThreadPosts.Post[forumThreadPosts.Post.Count - 1].Index + 1, true);
                        }
                    }

                }
            }
            catch
            {
            }

            return GetOutputStream(forumThreadPosts);
        }
예제 #16
0
        public void ReOpenThread_NotSuperUser_ReturnsValidError()
        {
            IUser viewingUser = mocks.DynamicMock<IUser>();
            viewingUser.Stub(x => x.IsEditor).Return(false);
            viewingUser.Stub(x => x.IsSuperUser).Return(false);

            ISiteList siteList = mocks.DynamicMock<ISiteList>();
            IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.HasRows).Return(false);
            reader.Stub(x => x.Read()).Return(false);

            IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("ThreadBelongsToForum")).Throw(new Exception("ThreadBelongsToForum should not have been called"));
            mocks.ReplayAll();


            ForumHelper target = new ForumHelper(creator, viewingUser, siteList);
            target.ReOpenThread(0, 0);

            Assert.AreEqual("UnHideThread", target.LastError.Type);
            Assert.AreEqual("Logged in user is not authorised to reopen threads", target.LastError.ErrorMessage);

        }
예제 #17
0
        public void ReOpenThread_NotRead_ReturnsValidError()
        {
            IUser viewingUser = mocks.DynamicMock<IUser>();
            viewingUser.Stub(x => x.IsEditor).Return(true);
            viewingUser.Stub(x => x.IsSuperUser).Return(false);

            ISiteList siteList = mocks.DynamicMock<ISiteList>();
            IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.HasRows).Return(false);
            reader.Stub(x => x.Read()).Return(false);
            reader.Stub(x => x.GetInt32NullAsZero("ThreadBelongsToForum")).Return(0);


            IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("SetThreadVisibletoUsers")).Return(reader).Repeat.AtLeastOnce();
            mocks.ReplayAll();


            ForumHelper target = new ForumHelper(creator, viewingUser, siteList);
            target.ReOpenThread(0, 0);

            Assert.AreEqual("UnHideThread", target.LastError.Type);
            Assert.AreEqual("Unable to open thread", target.LastError.ErrorMessage);

        }
예제 #18
0
        public void CloseThread_AsAuthorWithSiteOption_CallsSp()
        {
            IUser viewingUser = mocks.DynamicMock<IUser>();
            viewingUser.Stub(x => x.IsEditor).Return(false);
            viewingUser.Stub(x => x.IsSuperUser).Return(false);

            ISiteList siteList = mocks.DynamicMock<ISiteList>();
            siteList.Stub(x => x.GetSiteOptionValueBool(0, "Forum", "ArticleAuthorCanCloseThreads")).Return(true);

            IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.HasRows).Return(true);
            reader.Stub(x => x.Read()).Return(true);

            IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("closethread")).Return(reader).Repeat.AtLeastOnce();
            creator.Stub(x => x.CreateDnaDataReader("isuserinauthormembersofarticle")).Return(reader);
            mocks.ReplayAll();

            ForumHelper target = new ForumHelper(creator, viewingUser, siteList);
            target.CloseThread(0, 0, 0);

        }
예제 #19
0
        public void UpdateForumPermissions_AsSuperUser_ReturnsNoError()
        {
            IUser viewingUser = mocks.DynamicMock<IUser>();
            viewingUser.Stub(x => x.IsEditor).Return(false);
            viewingUser.Stub(x => x.IsSuperUser).Return(true);

            ISiteList siteList = mocks.DynamicMock<ISiteList>();
            IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.HasRows).Return(false);
            reader.Stub(x => x.Read()).Return(false);


            IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("updateforumpermissions")).Return(reader).Repeat.AtLeastOnce();
            mocks.ReplayAll();


            ForumHelper target = new ForumHelper(creator, viewingUser, siteList);

            target.UpdateForumPermissions(0, 0, 0, 0, 0);
            Assert.IsNull(target.LastError);

        }
예제 #20
0
        public void CloseThread_NotAuthorWithSiteOption_CallsSp()
        {
            IUser viewingUser = mocks.DynamicMock<IUser>();
            viewingUser.Stub(x => x.IsEditor).Return(false);
            viewingUser.Stub(x => x.IsSuperUser).Return(false);

            ISiteList siteList = mocks.DynamicMock<ISiteList>();
            siteList.Stub(x => x.GetSiteOptionValueBool(0, "Forum", "ArticleAuthorCanCloseThreads")).Return(true);

            IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.HasRows).Return(false);
            reader.Stub(x => x.Read()).Return(false);

            IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("closethread")).Throw(new Exception("closethread should not have been called"));
            creator.Stub(x => x.CreateDnaDataReader("isuserinauthormembersofarticle")).Return(reader);
            mocks.ReplayAll();

            ForumHelper target = new ForumHelper(creator, viewingUser, siteList);
            target.CloseThread(0, 0, 0);

            Assert.AreEqual("CloseThread", target.LastError.Type);
            Assert.AreEqual("Logged in user is not authorised to close threads", target.LastError.ErrorMessage);


        }
예제 #21
0
        public void GetThreadPermissions_ValidDataSet_ReturnsExpectedResults()
        {
            IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.GetBoolean("CanRead")).Return(true);
            reader.Stub(x => x.GetBoolean("CanWrite")).Return(true);
            reader.Stub(x => x.HasRows).Return(true);
            reader.Stub(x => x.Read()).Return(true);

            IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("getthreadpermissions")).Return(reader);
            mocks.ReplayAll();

            int userId = 0; 
            int threadId = 0; 
            bool canRead = false; 
            bool canReadExpected = true; 
            bool canWrite = false; 
            bool canWriteExpected = true;
            ForumHelper helper = new ForumHelper(creator);
            helper.GetThreadPermissions(userId, threadId, ref canRead, ref canWrite);
            Assert.AreEqual(canReadExpected, canRead);
            Assert.AreEqual(canWriteExpected, canWrite);
        }
예제 #22
0
        public void HideThread_NotSuperUser_ReturnsValidError()
        {
            IUser viewingUser = mocks.DynamicMock<IUser>();
            viewingUser.Stub(x => x.IsEditor).Return(false);
            viewingUser.Stub(x => x.IsSuperUser).Return(false);

            ISiteList siteList = mocks.DynamicMock<ISiteList>();
            siteList.Stub(x => x.GetSiteOptionValueBool(0, "Forum", "ArticleAuthorCanCloseThreads")).Return(true);

            IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.HasRows).Return(false);
            reader.Stub(x => x.Read()).Return(false);

            IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("SetThreadVisibletoUsers")).Throw(new Exception("SetThreadVisibletoUsers should not have been called"));
            mocks.ReplayAll();


            ForumHelper target = new ForumHelper(creator, viewingUser, siteList); 
            target.HideThread(0,0);

            Assert.AreEqual("HideThread", target.LastError.Type);
            Assert.AreEqual("Logged in user is not authorised to hide threads", target.LastError.ErrorMessage);

        }
예제 #23
0
        public void UpdateForumModerationStatus_WithSuccessReturned_ReturnsSuccess()
        {
            IUser viewingUser = mocks.DynamicMock<IUser>();
            viewingUser.Stub(x => x.IsEditor).Return(false);
            viewingUser.Stub(x => x.IsSuperUser).Return(true);

            ISiteList siteList = mocks.DynamicMock<ISiteList>();
            IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.HasRows).Return(false);
            reader.Stub(x => x.Read()).Return(true);
            reader.Stub(x => x.GetInt32NullAsZero("Success")).Return(1);


            IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("updateforummoderationstatus")).Return(reader).Repeat.AtLeastOnce();
            mocks.ReplayAll();


            ForumHelper target = new ForumHelper(creator, viewingUser, siteList);
            target.UpdateForumModerationStatus(0, 0);

            Assert.IsNull(target.LastError);

        }
예제 #24
0
        public void UpdateAlertInstantly_NotAllowed_ReturnsError()
        {
            IUser viewingUser = mocks.DynamicMock<IUser>();
            viewingUser.Stub(x => x.IsEditor).Return(false);
            viewingUser.Stub(x => x.IsSuperUser).Return(false);

            ISiteList siteList = mocks.DynamicMock<ISiteList>();
            IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.HasRows).Return(false);
            reader.Stub(x => x.Read()).Return(true);
            reader.Stub(x => x.GetInt32NullAsZero("ThreadBelongsToForum")).Return(1);


            IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("UpdateForumAlertInstantly")).Return(reader).Throw(new Exception("UpdateForumAlertInstantly should not be called"));
            mocks.ReplayAll();

            ForumHelper target = new ForumHelper(creator, viewingUser, siteList);
            target.UpdateAlertInstantly(0, 0);

            Assert.AreEqual("UpdateAlertInstantly", target.LastError.Type);
            Assert.AreEqual("Logged in user is not authorised to update AlertInstantly flag", target.LastError.ErrorMessage);
        }
예제 #25
0
        public void AddThreadToSticky_Authorised_ReturnsNoError()
        {
            var viewingUser = mocks.DynamicMock<IUser>();
            viewingUser.Stub(x => x.IsEditor).Return(true);
            viewingUser.Stub(x => x.IsSuperUser).Return(false);

            var siteList = mocks.DynamicMock<ISiteList>();
            siteList.Stub(x => x.GetSiteOptionValueBool(0, "Forum", "EnableStickyThreads")).Return(true);

            var reader = mocks.DynamicMock<IDnaDataReader>();
            var creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("addthreadtostickylist")).Return(reader).Repeat.AtLeastOnce();
            mocks.ReplayAll();

            var target = new ForumHelper(creator, viewingUser, siteList);
            target.AddThreadToStickyList(0, 0, 0);
            Assert.IsNull(target.LastError);
        }
예제 #26
0
        public void UpdateAlertInstantly_AsSuperUser_ReturnsNoError()
        {
            IUser viewingUser = mocks.DynamicMock<IUser>();
            viewingUser.Stub(x => x.IsEditor).Return(false);
            viewingUser.Stub(x => x.IsSuperUser).Return(true);

            ISiteList siteList = mocks.DynamicMock<ISiteList>();
            IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.HasRows).Return(false);
            reader.Stub(x => x.Read()).Return(true);
            reader.Stub(x => x.GetInt32NullAsZero("ThreadBelongsToForum")).Return(1);


            IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("UpdateForumAlertInstantly")).Return(reader).Repeat.AtLeastOnce();
            mocks.ReplayAll();

            ForumHelper target = new ForumHelper(creator, viewingUser, siteList);
            target.UpdateAlertInstantly(0, 1);

            Assert.IsNull(target.LastError);
        }
예제 #27
0
        /// <summary>
        /// Unsubscribes from journal and returns resulting xml object
        /// </summary>
        /// <param name="creator"></param>
        /// <param name="userId"></param>
        /// <param name="threadId"></param>
        /// <param name="forumId"></param>
        /// <returns></returns>
        static public SubscribeResult SubscribeToThread(IDnaDataReaderCreator creator, int userId, int threadId, int forumId, bool unSubcribe)
        {
            SubscribeResult result = new SubscribeResult();
            string spToCall = string.Empty;
            if (unSubcribe)
            {
                spToCall = "unsubscribefromthread";
                result.FromThreadId = threadId;
            }
            else
            {
                spToCall = "subscribetothread";
                result.ToThreadId = threadId;
            }

            //get permissions
            bool canRead = false;
            bool canWrite = false;
            ForumHelper helper = new ForumHelper(creator);
            helper.GetThreadPermissions(userId, threadId, ref canRead, ref canWrite);

            if (canRead)
            {
                using (IDnaDataReader reader = creator.CreateDnaDataReader(spToCall))
                {
                    reader.AddParameter("userid", userId);
                    reader.AddParameter("threadid", threadId);
                    reader.AddParameter("forumid", forumId);
                    reader.Execute();
                }
            }
            else
            {
                result.Failed = 5;
                result.Value = "You don't have permission to read this thread";
            }


            return result;
        }
예제 #28
0
        public void IsUserAuthorForArticle_ValidResults_ReturnsTrue()
        {
            IUser viewingUser = mocks.DynamicMock<IUser>();

            IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.HasRows).Return(true);
            reader.Stub(x => x.Read()).Return(true);

            IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("isuserinauthormembersofarticle")).Return(reader);
            mocks.ReplayAll();
            ForumHelper target = new ForumHelper(creator, viewingUser, null);
            Assert.IsTrue(target.IsUserAuthorForArticle(0));

        }