Letractively / dotnetkicks

Automatically exported from code.google.com/p/dotnetkicks
1 stars 0 forks source link

Undelete deleted story #183

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Open a story as a moderator
2. Delete it
3. Realize you screwed up heartily

Change story deletion to match the functionality of user banning.  

Something tells me that some hoodoo happens in the background that will 
make this harder to accomplish than
if(Story.IsDeleted)
  button.Text = "Undelete"; 
else
  button.Text = "Delete";

Original issue reported on code.google.com by yesthatm...@gmail.com on 2 Jan 2008 at 6:26

GoogleCodeExporter commented 9 years ago
Not that hard to do.  Deleting the story is the same as marking it as spam.

In StoryBR.cs Add:
        public static void UnMarkAsSpam(int storyID, int hostID, User moderator)
        {
            Story story = Story.FetchByID(storyID);
            if (story.HostID != hostID)
                throw new ArgumentException("The story does not belong to the host");
            else
            {
                story.IsSpam = false;
                story.UpdatedOn = DateTime.Now;
                story.Save();
// Might want to delete the RecordStoryDeletion action // TODO
//                UserAction.RecordStoryDeletion(hostID, story, moderator);
//                EmailHelper.SendStoryDeletedEmail(Story.FetchByID(storyID),
HostCache.GetHost(hostID));
            }
        }

In ajaxServices.ashx add:
        [JsonRpcMethod("moderatorUnMarkAsSpam")]
        public void ModeratorUnMarkAsSpam(int storyID)
        {
            DemandModeratorRole();
            StoryBR.UnMarkAsSpam(storyID, HostProfile.HostID, KickUserProfile);
        }

In hostmoderator.js add:
function UnDelete(storyID) {
    if(confirm("Are you sure you want to undelete this story?")) {
        StartLoading();
        ajaxServices.moderatorUnMarkAsSpam(storyID, function(response) {
FinishLoading(); });
    }
}

Now comes the harder part, if story==null or story.IsSpam the view page 
redirects
you, so it now needs some rewiring:
Change View.aspx.cs _load
            if (story == null || story.IsSpam && !this.KickUserProfile.IsModerator)
                Response.Redirect("/missingstory");

This will allow the story to always load if you are a moderator.

In StorySummary.cs - Change Render delete link to:
 // Render delete story link
            if(KickPage.IsHostModerator)
            {
                string deleteText = "delete";
                if(_story.SpamCount > 0)
                    deleteText += " (spam count is " + _story.SpamCount + ")";
                if (_story.IsSpam)
                {
                    writer.WriteLine(
                        @" |
                    <span class=""ModeratorLink""><a
href=""javascript:UnDelete({0});"">{1}</a></span>
                    ",
                        _story.StoryID, "un" + deleteText);
                }
                else
                {
                    writer.WriteLine(
                     @" |
                    <span class=""ModeratorLink""><a
href=""javascript:Delete({0});"">{1}</a></span>
                    ",
                     _story.StoryID, deleteText);
                }
            }

Works for me.  :)

Since the stories are cached it takes a few minutes to reflect the change.

Original comment by DustinBr...@gmail.com on 8 Jan 2008 at 9:23

GoogleCodeExporter commented 9 years ago

Original comment by DustinBr...@gmail.com on 17 Jan 2008 at 8:15

GoogleCodeExporter commented 9 years ago
Checked in after downloading latest revision - also added plusviewcount on image
clicks (icon aarow out and preview img) and read more clicks.  Also in this 
revision
is the fade out div/delete after using delete or report as spam.

Original comment by DustinBr...@gmail.com on 17 Jan 2008 at 9:59