Opened 7 years ago

Closed 7 years ago

#5513 closed defect (fixed)

Can't delete draft blog posts

Reported by: ayleph Owned by:
Priority: major Milestone: 0.10.0
Component: programming Keywords: blog, delete
Cc: Parent Tickets:

Description

Draft blog posts are set to the 'failed' state. The generated blogpost_delete_url link for a draft gets routed to a 404 page.

Attachments (1)

0001-Fix-5513-Can-t-delete-blog-post-drafts.patch (3.7 KB ) - added by ayleph 7 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 by ayleph, 7 years ago

And here's why. First, the deletion URL is created using the media_confirm_delete generator.

blogpost_delete_url = request.urlgen('mediagoblin.user_pages.media_confirm_delete',                                 
              user= blog_post.get_actor.username,
              media_id=blog_post.id)

The media_confirm_delete view is decorated by @get_media_entry_by_id.

@get_media_entry_by_id
@require_active_login
@user_may_delete_media
def media_confirm_delete(request, media):               

The @get_media_entry_by_id generator returns a 404 for media that aren't in the processed state.

def get_media_entry_by_id(controller):
    """
    Pass in a MediaEntry based off of a url component
    """
    @wraps(controller)
    def wrapper(request, *args, **kwargs):
        media = MediaEntry.query.filter_by(
                id=request.matchdict['media_id'],
                state=u'processed').first()
        # Still no media?  Okay, 404.
        if not media:
            return render_404(request)

Since blog post drafts aren't processed, the delete URL returns a 404.

comment:2 by ayleph, 7 years ago

I've attached a patch which I think addresses this issue. I removed the requirement from @get_media_entry_by_id for the media to be processed. This allows unprocessed media to be deleted. For all of the other views which used the decorator, I added constraints that the media must be processed.

comment:3 by ayleph, 7 years ago

Status: newreview

comment:4 by ayleph, 7 years ago

Keywords: delete added

comment:5 by ayleph, 7 years ago

Milestone: 0.10.0

comment:6 by ayleph, 7 years ago

Resolution: fixed
Status: reviewclosed

I've been using this patch for weeks without issue. Pushed to master in 2f2b4cb.

Note: See TracTickets for help on using tickets.