示例#1
0
        /// <summary>
        /// Generates user reputation object
        /// </summary>
        /// <param name="creator"></param>
        /// <param name="modClass"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public static UserReputation GetUserReputation(IDnaDataReaderCreator creator, ModerationClass modClass,
            int userId)
        {
            UserReputation userRep = new UserReputation() { ModClass = modClass, UserId = userId };

            using (IDnaDataReader dataReader = creator.CreateDnaDataReader("getuserreputation"))
            {
                dataReader.AddParameter("userid", userId);
                dataReader.AddParameter("modclassid", modClass.ClassId);
                dataReader.AddIntOutputParameter("@currentStatus");
                dataReader.AddIntOutputParameter("@reputationDeterminedStatus");
                dataReader.Execute();

                if (dataReader.Read())
                {
                    userRep.CurrentStatus = (ModerationStatus.UserStatus)dataReader.GetInt32NullAsZero("currentstatus");
                    userRep.ReputationDeterminedStatus = (ModerationStatus.UserStatus)dataReader.GetInt32NullAsZero("ReputationDeterminedStatus");
                    userRep.ReputationScore = dataReader.GetInt16("accumulativescore");
                    userRep.UserName = dataReader.GetStringNullAsEmpty("username");
                    userRep.LastUpdated = new DateElement(dataReader.GetDateTime("lastupdated"));
                }
            }
            return userRep;
        }
        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;
        }
示例#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));
        }
示例#4
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());
            
        }
示例#5
0
        /// <summary>
        /// Generates user reputation object
        /// </summary>
        /// <param name="creator"></param>
        /// <param name="modClass"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public static UserReputationList GetUserReputationList(IDnaDataReaderCreator creator, int modClassId, int modStatus,
            int days, int startIndex, int itemsPerPage, SortBy sortBy, SortDirection sortDirection)
        {
            UserReputationList userRepList = new UserReputationList()
            {
                days = days,
                modClassId = modClassId,
                modStatus = modStatus,
                startIndex = startIndex,
                itemsPerPage = itemsPerPage,
                sortBy = sortBy,
                sortDirection = sortDirection
            };

            using (IDnaDataReader dataReader = creator.CreateDnaDataReader("getuserreputationlist"))
            {
                dataReader.AddParameter("modClassId", modClassId);
                dataReader.AddParameter("modStatus", modStatus);
                dataReader.AddParameter("startIndex", startIndex);
                dataReader.AddParameter("itemsPerPage", itemsPerPage);
                dataReader.AddParameter("days", days);
                dataReader.AddParameter("sortby", sortBy.ToString());
                dataReader.AddParameter("sortdirection", sortDirection.ToString());
                
                dataReader.Execute();

                while(dataReader.Read())
                {
                    var userRep = new UserReputation();
                    userRep.UserId = dataReader.GetInt32NullAsZero("userid");
                    userRep.ModClass = ModerationClassListCache.GetObject().ModClassList.FirstOrDefault(x => x.ClassId == dataReader.GetInt32NullAsZero("modclassid"));
                    userRep.CurrentStatus = (ModerationStatus.UserStatus)dataReader.GetInt32NullAsZero("currentstatus");
                    userRep.ReputationDeterminedStatus = (ModerationStatus.UserStatus)dataReader.GetInt32NullAsZero("ReputationDeterminedStatus");
                    userRep.ReputationScore = dataReader.GetInt16("accumulativescore");
                    userRep.LastUpdated = new DateElement(dataReader.GetDateTime("lastupdated"));
                    userRep.UserName = dataReader.GetStringNullAsEmpty("UserName");
                    
                    userRepList.Users.Add(userRep);
                    userRepList.totalItems = dataReader.GetInt32NullAsZero("total");
                }
            }
            return userRepList;
        }
        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;
        }