Example #1
0
 public void Test02SignUserInViaIdentityCookie()
 {
     FullInputContext context = new FullInputContext(true);
     SignInSystem signInType = SignInSystem.Identity;
     CallingUser user = new CallingUser(signInType, null, null, null, context.SiteList);
     string cookie = TestUserAccounts.GetModeratorAccount.Cookie;
     string policy = "http://identity/policies/dna/adult";
     int siteID = 1;
     Assert.IsTrue(user.IsUserSignedIn(cookie, policy, siteID, ""));
     Assert.IsTrue(user.IsUserA(UserTypes.Moderator));
     Assert.IsFalse(user.IsUserA(UserTypes.Editor));
 }
Example #2
0
 public void Test02SignUserInViaIdentityCookie()
 {
     FullInputContext context = new FullInputContext("");
     SignInSystem signInType = SignInSystem.Identity;
     CallingUser user = new CallingUser(signInType, null, null, null, TestUserAccounts.GetModeratorAccount.UserName, context.SiteList);
     string cookie = TestUserAccounts.GetModeratorAccount.Cookie;
     string policy = "comment";
     int siteID = 1;
     Assert.IsTrue(user.IsUserSignedIn(cookie, policy, siteID, "", null, Guid.Empty));
     Assert.IsTrue(user.IsUserA(UserTypes.Moderator));
     Assert.IsFalse(user.IsUserA(UserTypes.Editor));
 }
Example #3
0
 public void Test03SignUserInAndAddThemToAcesGroup()
 {
     FullInputContext context = new FullInputContext(true);
     SignInSystem signInType = SignInSystem.Identity;
     CallingUser user = new CallingUser(signInType, context.ReaderCreator, null, null, context.SiteList);
     string cookie = TestUserAccounts.GetModeratorAccount.Cookie;
     string policy = "http://identity/policies/dna/adult";
     int siteID = 1;
     Assert.IsTrue(user.IsUserSignedIn(cookie, policy, siteID, ""));
     Assert.IsTrue(user.IsUserA(UserTypes.Moderator));
     Assert.IsFalse(user.GetUsersGroupsForSite().Exists(x => x.Name == "aces"));
     Assert.IsTrue(user.AddUserToGroup("Aces"));
     Assert.IsTrue(user.GetUsersGroupsForSite().Exists(x => x.Name == "aces"));
 }
Example #4
0
 public void Test03SignUserInAndAddThemToAcesGroup()
 {
     FullInputContext context = new FullInputContext("dotnetmoderator");
     SignInSystem signInType = SignInSystem.Identity;
     CallingUser user = new CallingUser(signInType, context.ReaderCreator, null, null, TestUserAccounts.GetModeratorAccount.UserName, context.SiteList);
     string cookie = TestUserAccounts.GetModeratorAccount.Cookie;
     string policy = "comment";
     int siteID = 1;
     Assert.IsTrue(user.IsUserSignedIn(cookie, policy, siteID, TestUserAccounts.GetModeratorAccount.UserName, null, Guid.Empty));
     Assert.IsTrue(user.IsUserA(UserTypes.Moderator));
     Assert.IsFalse(user.GetUsersGroupsForSite().Exists(x => x.Name == "aces"));
     Assert.IsTrue(user.AddUserToGroup("Aces"));
     Assert.IsTrue(user.GetUsersGroupsForSite().Exists(x => x.Name.ToLower() == "aces"));
 }
Example #5
0
        private static void SubsOnly(CallingUser callingUser)
        {
            bool authorised = callingUser.IsUserA(UserTypes.SubEditor) || callingUser.IsUserA(BBC.Dna.Users.UserTypes.Editor) || callingUser.IsUserA(BBC.Dna.Users.UserTypes.SuperUser);

            if (!authorised)
            {
                throw new DnaWebProtocolException(ApiException.GetError(ErrorType.NotAuthorized));
            }
        }
Example #6
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;
        }
Example #7
0
 public void Test04CheckSignedInNormalUserBelongsToTheCorrectGroups()
 {
     FullInputContext context = new FullInputContext(true);
     SignInSystem signInType = SignInSystem.Identity;
     CallingUser user = new CallingUser(signInType, null, null, null, context.SiteList);
     string cookie = TestUserAccounts.GetNormalUserAccount.Cookie;
     string policy = "http://identity/policies/dna/adult";
     int siteID = 1;
     Assert.IsTrue(user.IsUserSignedIn(cookie, policy, siteID, ""));
     Assert.IsTrue(user.IsUserA(UserTypes.NormalUser), "User should be a normal user");
     Assert.IsFalse(user.IsUserA(UserTypes.SuperUser), "User should not be a super user");
     Assert.IsFalse(user.IsUserA(UserTypes.Moderator), "User should not be a moderator");
     Assert.IsFalse(user.IsUserA(UserTypes.Editor), "User should not be a editor");
     Assert.IsFalse(user.IsUserA(UserTypes.Notable), "User should not be a notable");
 }
Example #8
0
 public void Test07CheckSignedInModeratorBelongsToTheCorrectGroups()
 {
     FullInputContext context = new FullInputContext("");
     SignInSystem signInType = SignInSystem.Identity;
     CallingUser user = new CallingUser(signInType, null, null, null, TestUserAccounts.GetModeratorAccount.UserName, context.SiteList);
     string cookie = TestUserAccounts.GetModeratorAccount.Cookie;
     string policy = "comment";
     int siteID = 1;
     Assert.IsTrue(user.IsUserSignedIn(cookie, policy, siteID, "", null, Guid.Empty));
     Assert.IsTrue(user.IsUserA(UserTypes.NormalUser), "User should be a normal user");
     Assert.IsFalse(user.IsUserA(UserTypes.SuperUser), "User should not be a super user");
     Assert.IsTrue(user.IsUserA(UserTypes.Moderator), "User should be a moderator");
     Assert.IsFalse(user.IsUserA(UserTypes.Editor), "User should not be a editor");
     Assert.IsFalse(user.IsUserA(UserTypes.Notable), "User should not be a notable");
 }