Esempio n. 1
0
        /// <summary>
        /// Checks to see if the article needs to be placed in the moderation system
        /// </summary>
        /// <param name="articleOwner">The user who owns the article.</param>
        /// <param name="site">The site that the article was created in</param>
        /// <param name="h2g2ID">The h2g2id of the article you want to moderate</param>
        /// <param name="profanitiesFound">A flag that states whether or not a profanity was found</param>
        /// <returns>True if the article was placed in the moderation queue, False if not</returns>
        public bool ModerateArticle(IUser articleOwner, ISite site, int h2g2ID, bool profanitiesFound)
        {
            // Check to see if the user is immune from moderation
            if (!articleOwner.HasSpecialEditPermissions(h2g2ID))
            {
                // Now do some simple checks on the site and user
                bool siteModerated = (int)site.ModerationStatus > 1;
                bool userModerated = articleOwner.IsPreModerated;
                bool userInSinBin = articleOwner.IsAutoSinBin;
                bool articleModerated = IsArticleModerated(h2g2ID);

                // If anything came back as being moderated, then queue the article for moderation
                if (siteModerated || userInSinBin || userModerated || articleModerated || profanitiesFound)
                {
                    // Queue the article for moderation
                    using (IDnaDataReader reader = _appContext.CreateDnaDataReader("QueueArticleForModeration"))
                    {
                        // Check to see what triggered the moderation
                        int triggerID = (int)ModerationTriggers.Automatic;
                        if (profanitiesFound)
                        {
                            triggerID = (int)ModerationTriggers.Profanities;
                        }

                        // Create the notes for the moderation decision
                        string notes = "Created/Edited by user U" + articleOwner.UserID.ToString();

                        // Add the article to the queue
                        reader.AddParameter("h2g2ID", h2g2ID);
                        reader.AddParameter("TriggerID", triggerID);
                        reader.AddParameter("TriggeredBy", articleOwner.UserID);
                        reader.AddParameter("Notes", notes);
                        reader.AddIntOutputParameter("ModID");
                        reader.Execute();
                        while (reader.Read()) { }

                        // Get the new mod id for the article
                        int modID = 0;
                        reader.TryGetIntOutputParameter("ModeID", out modID);
                    }

                    // Article was moderated
                    return true;
                }
            }

            // Article was not moderated
            return false;
        }
Esempio n. 2
0
        /// <summary>
        /// Checks to see if a user has edit permissions for the current guide entry
        /// </summary>
        /// <param name="user">The user you want to check against</param>
        /// <returns>True if they are able to edit, false if not</returns>
        public bool HasEditPermission(IUser user)
        {
            // Check to see if we've got special permissions
            bool editable = user.HasSpecialEditPermissions(_h2g2ID);

            // Make sure the h2g2id is valid
            if (!editable && ValidateH2G2ID())
            {
                // Guide Entry is editable if it is a valid article, the user is the same as the
                // editor, and the status of the entry is either 2, 3, 4, or 7 => i.e. it is a
                // user entry that is private or public, or is awaiting consideration or has been
                // deleted
                // only give editors edit permission on all entries on the admin version
                // give moderators edit permission if they have entry locked for moderation

                if (Status == 1 && user.IsGuardian)
                {
                    editable = true;
                }

                // If the user is the editor of the entry and the status is correct, then they can edit
                if (AuthorsUserID == user.UserID)
                {
                    if ((Status > 1 && Status < 5) || Status == 7)
                    {
                        editable = true;
                    }
                }
            }

            return editable;
        }