private bool ModifyUserModerationStatus(ModerationClass modClass)
        {
            if (_updateStatus)
            {
                bool hideAllSites = InputContext.DoesParamExist("hideAllSites", "hideAllSites");
                var newPrefStatus = (BBC.Dna.Moderation.Utils.ModerationStatus.UserStatus)Enum.Parse(typeof(BBC.Dna.Moderation.Utils.ModerationStatus.UserStatus), InputContext.GetParamStringOrEmpty("userStatusDescription", "new status"));
                int newPrefStatusDuration = InputContext.GetParamIntOrZero("duration", "new status");
                bool hideAllContent = InputContext.DoesParamExist("hideAllPosts", "hideAllPosts");
                
                
                string reason = InputContext.GetParamStringOrEmpty("reasonChange", "");
                if (string.IsNullOrEmpty(reason))
                {
                    AddErrorXml("EmptyReason", "Please provide a valid reason for this change for auditing purposes.", null);
                    return false;
                }
                var extraNotes = InputContext.GetParamStringOrEmpty("additionalNotes", "");
                if (!String.IsNullOrEmpty(extraNotes))
                {
                    reason += " - " + extraNotes;
                }
                if (hideAllContent && newPrefStatus != BBC.Dna.Moderation.Utils.ModerationStatus.UserStatus.Deactivated)
                {
                    AddErrorXml("InvalidStatus", "To hide all content you must deactivate the users account.", null);
                    return false;
                }

                if (newPrefStatusDuration != 0 && (newPrefStatus != BBC.Dna.Moderation.Utils.ModerationStatus.UserStatus.Postmoderated
                    && newPrefStatus != BBC.Dna.Moderation.Utils.ModerationStatus.UserStatus.Premoderated))
                {
                    AddErrorXml("UnableToSetDuration", "You cannot set a status duration when the status is not premoderation or postmoderation.", null);
                    return false;
                }

                if (newPrefStatus == BBC.Dna.Moderation.Utils.ModerationStatus.UserStatus.Deactivated)//deactivate account
                {
                    if (!InputContext.ViewingUser.IsSuperUser)
                    {
                        AddErrorXml("InsufficientPermissions", "You do not have sufficient permissions to deactivate users.", null);
                        return false;
                    }
                    BBC.Dna.Moderation.Utils.ModerationStatus.DeactivateAccount(AppContext.ReaderCreator, new List<int>{_userId},
                        hideAllContent, reason, InputContext.ViewingUser.UserID);
                }
                else
                {
                    UserReputation userRep = new UserReputation()
                    {
                        ModClass = modClass,
                        UserId = _userId,
                        ReputationDeterminedStatus = newPrefStatus
                    };
                    userRep.ApplyModerationStatus(AppContext.ReaderCreator, hideAllSites, newPrefStatusDuration, reason,
                        InputContext.ViewingUser.UserID); 
                }

            }
            return true;
        }
Пример #2
0
        public void ApplyModerationStatus_NotInitalised_ThrowsError()
        {
            var notes = "";
            var duration = 5;
            var reader = Mocks.DynamicMock<IDnaDataReader>();
            var creator = Mocks.DynamicMock<IDnaDataReaderCreator>();

            reader.Stub(x => x.Read()).Return(true).Repeat.Once();

            creator.Stub(x => x.CreateDnaDataReader("updatetrackedmemberformodclass")).Return(reader);
            Mocks.ReplayAll();

            ModerationClass modClass = new ModerationClass() { };

            var userRep = new UserReputation();
            try
            {
                userRep.ApplyModerationStatus(creator, true, duration, notes, 1);
                throw new Exception("no exception thrown");
            }
            catch (Exception e)
            {
                Assert.AreEqual("UserId cannot be zero", e.Message);
            }

            reader.AssertWasNotCalled(x => x.Execute());
            
        }
Пример #3
0
        public void ApplyModerationStatus_ValidDB_NoErrors()
        {
            var bannedEmailsTests = new BannedEmailsTests();
            bannedEmailsTests.InitializebannedEmails_EmptyCacheValidRecordSet_ReturnsValidObject();


            var notes = "somenotes";
            var duration = 5;
            var reader = Mocks.DynamicMock<IDnaDataReader>();
            var creator = Mocks.DynamicMock<IDnaDataReaderCreator>();

            reader.Stub(x => x.Read()).Return(true).Repeat.Once();

            creator.Stub(x => x.CreateDnaDataReader("updatetrackedmemberformodclass")).Return(reader);
            Mocks.ReplayAll();

            ModerationClass modClass = new ModerationClass() { };

            var userRep = new UserReputation
            {
                UserId = 1,
                ModClass = new ModerationClass() { ClassId = 1 },
                ReputationDeterminedStatus = BBC.Dna.Moderation.Utils.ModerationStatus.UserStatus.Premoderated,
            };

            userRep.ApplyModerationStatus(creator, false, duration, notes, 1);

            reader.AssertWasCalled(x => x.AddParameter("userid", userRep.UserId));
            reader.AssertWasCalled(x => x.AddParameter("viewinguser", 1));
            reader.AssertWasCalled(x => x.AddParameter("reason", notes));
            reader.AssertWasCalled(x => x.AddParameter("prefstatusduration", duration));
            reader.AssertWasCalled(x => x.AddParameter("modclassid", userRep.ModClass.ClassId));
            reader.AssertWasCalled(x => x.AddParameter("prefstatus", (int)userRep.ReputationDeterminedStatus));
        }
        private bool UpdateUserList()
        {
            if (InputContext.DoesParamExist("ApplyAction", "ApplyAction"))
            {
                bool applyToAll = InputContext.DoesParamExist("applyToAll", "applyToAll");

                for(int i=1; i <= _itemsPerPage; i++)
                {
                    string formvar = string.Format("applyto|{0}", i);
                    if (applyToAll || InputContext.DoesParamExist(formvar, formvar))
                    {
                        var userRep = new UserReputation();
                        userRep.UserId = InputContext.GetParamIntOrZero(string.Format("{0}|userid", i), "");
                        userRep.ModClass = new ModerationClass() { ClassId = InputContext.GetParamIntOrZero(string.Format("{0}|modclassid", i), "") };
                        userRep.ReputationDeterminedStatus = (ModerationStatus.UserStatus)Enum.Parse(typeof(ModerationStatus.UserStatus), InputContext.GetParamStringOrEmpty(string.Format("{0}|reputationdeterminedstatus", i), ""));
                        userRep.ApplyModerationStatus(AppContext.ReaderCreator, false, 0, String.Empty, InputContext.ViewingUser.UserID);
                    }
                }
                return true;
            }
            return false;
        }