Beispiel #1
0
        public void TestGetMemberListForUser1090558354()
        {
            //Create the mocked inputcontext
            Mockery mock = new Mockery();
            IInputContext mockedInputContext = mock.NewMock<IInputContext>();
            //XmlDocument siteconfig = new XmlDocument();
            //siteconfig.LoadXml("<SITECONFIG />");

            ISite mockedSite = mock.NewMock<ISite>();
            //Stub.On(mockedSite).GetProperty("SiteConfig").Will(Return.Value(siteconfig.FirstChild));
            Stub.On(mockedSite).GetProperty("SiteID").Will(Return.Value(1));

            IUser mockedUser = mock.NewMock<IUser>();
            Stub.On(mockedUser).GetProperty("UserID").Will(Return.Value(1090558354));

            Stub.On(mockedInputContext).GetProperty("ViewingUser").Will(Return.Value(mockedUser));
            Stub.On(mockedInputContext).GetProperty("CurrentSite").Will(Return.Value(mockedSite));

            IInputContext context = DnaMockery.CreateDatabaseInputContext();

            // Create the stored procedure reader for the MemberList object
            using (IDnaDataReader reader = context.CreateDnaDataReader("SearchForUserViaUserID"))
            {
                Stub.On(mockedInputContext).Method("CreateDnaDataReader").With("SearchForUserViaUserID").Will(Return.Value(reader));

                // Create a new MemberList object and get the list of member accounts
                MemberList testMemberList = new MemberList(mockedInputContext);
                testMemberList.GenerateMemberListPageXml(0, "1090558354", true);

                XmlElement xml = testMemberList.RootElement;
                Assert.IsTrue(xml.SelectSingleNode("MEMBERLIST") != null, "The xml is not generated correctly!!!");

                Assert.IsTrue(xml.SelectSingleNode("MEMBERLIST[@USERSEARCHTYPE='0']") != null, "The xml is not generated correctly (UserSearchType)!!!");
                Assert.IsTrue(xml.SelectSingleNode("MEMBERLIST[@SEARCHTEXT='1090558354']") != null, "The xml is not generated correctly (UserSearchUserID)!!!");
                Assert.IsTrue(xml.SelectSingleNode("MEMBERLIST/@COUNT") != null, "The xml is not generated correctly (Count)!!!");
                Assert.IsTrue(xml.SelectSingleNode("MEMBERLIST/USERACCOUNTS/USERACCOUNT/SSOUSERID") != null, "Could not find the users sso userid!!!");
                Assert.IsTrue(xml.SelectSingleNode("MEMBERLIST/USERACCOUNTS/USERACCOUNT/IDENTITYUSERID") != null, "Could not find the users identity userid!!!");
                
                DnaXmlValidator validator = new DnaXmlValidator(xml.InnerXml, _schemaUri);
                validator.Validate();
            }
        }
    /// <summary>
    /// Function that is always called to recreate the table and all the check boxes
    /// </summary>
    private void GetMemberList()
    {
        tblResults.Rows.Clear();
        lblEntryError.Text = String.Empty;
        if (txtEntry.Text != String.Empty)
        {
            int userSearchType = rdSearchType.SelectedIndex;

            int userID = 0;
            string userEmail = String.Empty;
            string userName = String.Empty;
            string userIPAddress = String.Empty;
            string userBBCUID = String.Empty;
            string loginName = String.Empty;

            if (userSearchType == 0)
            {
                try
                {
                    userID = Convert.ToInt32(txtEntry.Text);
                }
                catch (System.FormatException Ex)
                {
                    lblEntryError.Text = "Please enter a valid User ID";
                    System.Console.WriteLine(Ex.Message);
                    return;
                }
            }
            else if (userSearchType == 1)
            {
                userEmail = txtEntry.Text;
            }
            else if (userSearchType == 2)
            {
                userName = txtEntry.Text;
            }
            else if (userSearchType == 3)
            {
                userIPAddress = txtEntry.Text;
            }
            else if (userSearchType == 4)
            {
                userBBCUID = txtEntry.Text;

                try
                {
                    Guid tmpBBCUID = new Guid(userBBCUID);
                }
                catch (System.FormatException Ex)
                {
                    lblEntryError.Text = "Please enter a valid BBC UID";
                    System.Console.WriteLine(Ex.Message);
                    return;
                }
            }
            else if (userSearchType == 5)
            {
                loginName = txtEntry.Text;
            }

            bool checkAllSites = false;
            //Sets the get across all sites for the stored procedures
            if (ViewingUser.IsSuperUser)
            {
                checkAllSites = true;
            }
            else
            {
                checkAllSites = false;
            }

            MemberList memberList = new MemberList(_basePage);
            memberList.GenerateMemberListPageXml(userSearchType, 
                                        txtEntry.Text,
                                        checkAllSites);

            int count = 0;
            TableHeaderRow headerRow = new TableHeaderRow();
            headerRow.BackColor = Color.MistyRose;

            int previousUserID = 0;
            int accountCount = 0;

            foreach (XmlNode node in memberList.RootElement.SelectNodes(@"MEMBERLIST/USERACCOUNTS/USERACCOUNT"))
            {
                if (count == 0)
                {
                    //No header cell for the tickbox
                    TableHeaderCell headerfirstCheckBoxCell = new TableHeaderCell();
                    CheckBox checkBoxApplyAll = new CheckBox();
                    checkBoxApplyAll.ID = "ApplyToAll";
                    checkBoxApplyAll.Text = "Apply To All";
                    checkBoxApplyAll.Checked = ApplyToAllStatus;
                    checkBoxApplyAll.CheckedChanged += new EventHandler(ApplyToAll_CheckedChanged);
                    checkBoxApplyAll.AutoPostBack = true;
                    checkBoxApplyAll.EnableViewState = true;
                    checkBoxApplyAll.Attributes.Add("onfocus", "document.getElementById('__LASTFOCUS').value=this.id;");


                    headerfirstCheckBoxCell.Controls.Add(checkBoxApplyAll);
                    headerRow.Cells.Add(headerfirstCheckBoxCell);

                    TableHeaderCell headerFirstCell = new TableHeaderCell();
                    headerFirstCell.Text = "User ID";
                    headerFirstCell.Scope = TableHeaderScope.Column;
                    headerRow.Cells.Add(headerFirstCell);
                }

                TableRow row = new TableRow();
                TableCell firstCheckBoxCell = new TableCell();
                firstCheckBoxCell.HorizontalAlign = HorizontalAlign.Center;

                CheckBox checkBoxApply = new CheckBox();
                checkBoxApply.ID = "Check" + count.ToString();
                checkBoxApply.CheckedChanged += new EventHandler(ListApply_CheckedChanged);
                checkBoxApply.AutoPostBack = true;
                checkBoxApply.EnableViewState = true;
                checkBoxApply.Attributes.Add("onfocus", "document.getElementById('__LASTFOCUS').value=this.id;");
                firstCheckBoxCell.Controls.Add(checkBoxApply);
                row.Cells.Add(firstCheckBoxCell);

                TableCell firstCell = new TableCell();
                firstCell.HorizontalAlign = HorizontalAlign.Center;

                string userIDText = node.SelectSingleNode(@"@USERID").InnerText;
                firstCell.Text = userIDText;
                int currentUserID = Convert.ToInt32(userIDText);
                if (currentUserID != previousUserID)
                {
                    accountCount++;
                    previousUserID = currentUserID;
                }

                if (accountCount % 2 == 0)
                    row.BackColor = Color.LightGray;
                else
                    row.BackColor = Color.Linen;

                HyperLink link = new HyperLink();
                link.NavigateUrl = "/dna/moderation/MemberDetails?userid=" + userIDText;
                link.Text = "U" + userIDText;
                firstCell.Controls.Add(link);
                row.Cells.Add(firstCell);

                foreach (XmlNode data in node.ChildNodes)
                {
                    TableCell nextCell = new TableCell();

                    if (data.LocalName == "PREFSTATUS")
                    {
                        if (count == 0)
                        {
                            AddHeaderCell(headerRow, "STATUS");
                        }

                        HtmlImage img = new HtmlImage();
                        string path = @"/dnaimages/moderation/images/icons/status" + data.InnerText + ".gif";
                        //img.Src = String.Format("http://ops-dna2.national.core.bbc.co.uk/dnaimages/moderation/images/icons/status{0}.gif", data.InnerText);
                        img.Src = path;
                        img.Alt = data.ParentNode.SelectSingleNode("USERSTATUSDESCRIPTION").InnerText;
                        nextCell.HorizontalAlign = HorizontalAlign.Center;
                        nextCell.Controls.Add(img);
                        row.Cells.Add(nextCell);
                    }

                    else if (data.LocalName == "SITEID")
                    {
                        if (count == 0)
                        {
                            AddHeaderCell(headerRow, "SITEID");
                        }
                        nextCell.HorizontalAlign = HorizontalAlign.Center;
                        nextCell.Text = data.InnerText;
                        row.Cells.Add(nextCell);
                    }
                    else if (data.LocalName == "PREFSTATUSCHANGEDDATE")
                    {
                        if (count == 0)
                        {
                            AddHeaderCell(headerRow, "CHANGEDDATE");
                        }

                        nextCell.HorizontalAlign = HorizontalAlign.Center;

                        DateTime date = new DateTime();
                        string sortDate = String.Empty;

                        if (data.SelectSingleNode("DATE/@SORT") != null)
                        {
                            DateTimeFormatInfo UKDTFI = new CultureInfo("en-GB", false).DateTimeFormat;

                            sortDate = data.SelectSingleNode("DATE/@SORT").InnerText;
                            DateTime.TryParseExact(sortDate, "yyyyMMddHHmmss", UKDTFI, DateTimeStyles.NoCurrentDateDefault, out date);
                            nextCell.Text = date.ToString();
                        }
                        else
                        {
                            nextCell.Text = "";
                        }
                        row.Cells.Add(nextCell);
                    }
                    else if (data.LocalName == "PREFSTATUSDURATION")
                    {
                        if (count == 0)
                        {
                            AddHeaderCell(headerRow, "DURATION");
                        }
                        nextCell.HorizontalAlign = HorizontalAlign.Center;
                        nextCell.Text = memberList.GetPrefStatusDurationDisplayText(data.InnerText);
                        row.Cells.Add(nextCell);
                    }
                    else if (data.LocalName == "SHORTNAME")
                    {
                        if (count == 0)
                        {
                            AddHeaderCell(headerRow, "SITE");
                        }
                        nextCell.HorizontalAlign = HorizontalAlign.Center;
                        nextCell.Text = data.InnerText;
                        row.Cells.Add(nextCell);
                    }
                    else if ( data.LocalName != "USERSTATUSDESCRIPTION" &&
                        data.LocalName != "URLNAME")
                    {
                        if (count == 0)
                        {
                            AddHeaderCell(headerRow, data.LocalName);
                        }

                        nextCell.HorizontalAlign = HorizontalAlign.Center;
                        nextCell.Text = data.InnerText;
                        row.Cells.Add(nextCell);
                    }
                }
                tblResults.Rows.Add(row);
                count++;
            }

            if (count == 0)
            {
                TableRow nodatarow = new TableRow();
                TableCell nodataCell = new TableCell();
                nodataCell.ColumnSpan = 4;
                nodataCell.Text = @"No data for those details";
                nodatarow.Cells.Add(nodataCell);
                tblResults.Rows.Add(nodatarow);
                Count.Text = "";
            }
            else
            {
                Count.Text = String.Format(@"There are {0} entries.", count.ToString());
            }

            tblResults.Rows.AddAt(0, headerRow);

            tblResults.CellSpacing = 5;
            tblResults.BorderWidth = 2;
            tblResults.BorderStyle = BorderStyle.Outset;

        }
    }
/*    protected override object SaveViewState()
    {
        return new Pair(base.SaveViewState(), null);
    }

    protected override void LoadViewState(object savedState)
    {
        base.LoadViewState(((Pair)savedState).First);
        EnsureChildControls();
    }
*/

    /// <summary>
    /// Function that actions the apply action button
    /// </summary>
    private void ApplyActions()
    {
        int rowCount = 0;
        CheckBox applyToAll = (CheckBox) tblResults.Rows[0].FindControl("ApplyToAll");
        MemberList memberList = new MemberList(_basePage);
        List<int> userIDList = new List<int>();
        List<int> siteIDList = new List<int>();
        List<int> deactivatedUsers = new List<int>();

        int newPrefStatusValue = 0;
        bool hideAllPosts = chkHideAllContent.Checked;
        var reason = txtReason.Text;

        memberList.GetPrefStatusValueFromDescription(UserStatusDescription.SelectedValue, ref newPrefStatusValue);
        int newPrefStatusDuration = 0;
        Int32.TryParse(Duration.SelectedValue, out newPrefStatusDuration);

        if (applyToAll != null && applyToAll.Checked)
        {
            if (ViewingUser.IsSuperUser)
            {
               // memberList.UpdateModerationStatus(userID, siteID, newPrefStatusValue, newPrefStatusDuration, 0, 1);
            }
            else
            {
               // memberList.UpdateModerationStatusAcrossAllSites(ViewingUser.UserID, userID, siteID, newPrefStatusValue, newPrefStatusDuration);

            }
        }
        
        foreach (TableRow row in tblResults.Rows)
        {
            if (row.GetType() != typeof(TableHeaderRow))
            {
                CheckBox checkBox = (CheckBox)row.FindControl("Check" + rowCount.ToString());
                if (checkBox.Checked)
                {
                    int userID = 0;
                    int siteID = 0;
                    int deactivated = 0;
                    Int32.TryParse(row.Cells[1].Text, out userID);
                    Int32.TryParse(row.Cells[2].Text, out siteID);

                    userIDList.Add(userID);
                    siteIDList.Add(siteID);
                    if(Int32.TryParse(row.Cells[12].Text, out deactivated) && deactivated == 0)
                    {
                        deactivatedUsers.Add(userID);
                    }
                }
                rowCount++;
            }
        }

        if (userIDList.Count > 0)
        {
            if (newPrefStatusValue == 5)//deactivate in user table)
            {
                ModerationStatus.DeactivateAccount(AppContext.ReaderCreator, userIDList, hideAllPosts, reason, memberList.InputContext.ViewingUser.UserID);
            }
            else
            {
                ModerationStatus.ReactivateAccount(AppContext.ReaderCreator, deactivatedUsers, reason, memberList.InputContext.ViewingUser.UserID);
                ModerationStatus.UpdateModerationStatuses(AppContext.ReaderCreator, userIDList, siteIDList, newPrefStatusValue,
                    newPrefStatusDuration, reason, memberList.InputContext.ViewingUser.UserID);
            }
        }

        UserGroups.GetObject().SendSignal();
        GetMemberList();
    }
Beispiel #4
0
        /// <summary>
        /// Checks if the user exists in Twitter.
        /// If Exists, returns the user details else returns exception
        /// </summary>
        /// <param name="twitterUserScreenName"></param>
        /// <param name="siteId"></param>
        /// <returns></returns>
        private string IsValidTwitterUser(string twitterUserScreenName, int siteId)
        {
            MemberList memberList = null;
            var twitterException = string.Empty;
            var _isValidTwitterScreenName = string.Empty;
            try
            {
                memberList = new MemberList(base.InputContext);

                TweetUsers tweetUser = memberList.RetrieveTweetUserDetails(twitterUserScreenName);
                
                if (tweetUser.TwitterResponseException != null)
                {
                    var twitterRateLimitException = "rate limit exceeded.";
                    var twitterErrorNotFound = "the remote server returned an error: (404) not found.";
                    var twitterUnexpectedResponseException = "the remote server returned an unexpected response: (400) bad request.";

                    if (tweetUser.TwitterResponseException.Message.ToLower().Contains(twitterRateLimitException))
                    {
                        twitterException = "Twitter Exception: Twitter API has reached its rate limit. Please try again later.";
                    }
                    else if (tweetUser.TwitterResponseException.Message.ToLower().Equals(twitterErrorNotFound) ||
                        tweetUser.TwitterResponseException.InnerException.Message.ToLower().Equals(twitterErrorNotFound))
                    {
                        twitterException = "Twitter Error: Searched user not found in Twitter";
                    }
                    else if (tweetUser.TwitterResponseException.Message.ToLower().Equals(twitterUnexpectedResponseException))
                    {
                        twitterException = "Twitter Exception: " + tweetUser.TwitterResponseException.Message + " Please try again in few minutes.";
                    }
                    else
                    {
                        twitterException = "Twitter Exception: " + tweetUser.TwitterResponseException.Message;
                    }

                    _isValidTwitterScreenName = twitterException;
                }
                else
                {
                    _isValidTwitterScreenName = tweetUser.id;

                    //Creating the twitter user in DNA
                    ICacheManager cacheManager = CacheFactory.GetCacheManager();

                    var callingUser = new CallingTwitterUser(this.readerCreator, this.dnaDiagnostic, cacheManager);

                    //Create the twitter user and map it to DNA with the site the profile and the forum is created
                    callingUser.CreateUserFromTwitterUser(siteId, tweetUser);
                    callingUser.SynchroniseSiteSuffix(tweetUser.ProfileImageUrl);
                }
           
            }
            finally
            {
                memberList = null;
            }
            return _isValidTwitterScreenName;
        }