Ticket #5513: 0001-Fix-5513-Can-t-delete-blog-post-drafts.patch

File 0001-Fix-5513-Can-t-delete-blog-post-drafts.patch, 3.7 KB (added by ayleph, 7 years ago)
  • mediagoblin/decorators.py

    From 182b1b74182eb37c777fb173f0e67c66f897bc1a Mon Sep 17 00:00:00 2001
    From: ayleph <ayleph@thisshitistemp.com>
    Date: Tue, 27 Jun 2017 22:45:42 -0700
    Subject: [PATCH] Fix #5513 - Can't delete blog post drafts
    
    Modify the @get_media_entry_by_id decorator to return media regardless
    of processing state. Separately modify all view functions that use the
    @get_media_entry_by_id decorator to require that the media be in the
    processed state, other than for the media_confirm_delete view. This
    allows blog post drafts to be deleted without returning a 404. Further,
    it adds the ability to delete unprocessed media in the future, which
    would be a nice addition to the user processing panel.
    ---
     mediagoblin/decorators.py       |  3 +--
     mediagoblin/edit/views.py       | 12 ++++++++++++
     mediagoblin/user_pages/views.py |  8 ++++++++
     3 files changed, 21 insertions(+), 2 deletions(-)
    
    diff --git a/mediagoblin/decorators.py b/mediagoblin/decorators.py
    index daeddb3f1..2b8343b85 100644
    a b def get_media_entry_by_id(controller):  
    268268    @wraps(controller)
    269269    def wrapper(request, *args, **kwargs):
    270270        media = MediaEntry.query.filter_by(
    271                 id=request.matchdict['media_id'],
    272                 state=u'processed').first()
     271                id=request.matchdict['media_id']).first()
    273272        # Still no media?  Okay, 404.
    274273        if not media:
    275274            return render_404(request)
  • mediagoblin/edit/views.py

    diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py
    index b15fb2e79..17aea9229 100644
    a b import mimetypes  
    5555@get_media_entry_by_id
    5656@require_active_login
    5757def edit_media(request, media):
     58    # If media is not processed, return NotFound.
     59    if not media.state == u'processed':
     60        return render_404(request)
     61
    5862    if not may_edit_media(request, media):
    5963        raise Forbidden("User may not edit this media")
    6064
    UNSAFE_MIMETYPES = [  
    115119@get_media_entry_by_id
    116120@require_active_login
    117121def edit_attachments(request, media):
     122    # If media is not processed, return NotFound.
     123    if not media.state == u'processed':
     124        return render_404(request)
     125
    118126    if mg_globals.app_config['allow_attachments']:
    119127        form = forms.EditAttachmentsForm()
    120128
    def change_email(request):  
    499507@require_active_login
    500508@get_media_entry_by_id
    501509def edit_metadata(request, media):
     510    # If media is not processed, return NotFound.
     511    if not media.state == u'processed':
     512        return render_404(request)
     513
    502514    form = forms.EditMetaDataForm(request.form)
    503515    if request.method == "POST" and form.validate():
    504516        metadata_dict = dict([(row['identifier'],row['value'])
  • mediagoblin/user_pages/views.py

    diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py
    index 484d27cd9..ab235695e 100644
    a b def media_post_comment(request, media):  
    180180    if not request.method == 'POST':
    181181        raise MethodNotAllowed()
    182182
     183    # If media is not processed, return NotFound.
     184    if not media.state == u'processed':
     185        return render_404(request)
     186
    183187    comment = request.db.TextComment()
    184188    comment.actor = request.user.id
    185189    comment.content = six.text_type(request.form['comment_content'])
    def media_preview_comment(request):  
    232236def media_collect(request, media):
    233237    """Add media to collection submission"""
    234238
     239    # If media is not processed, return NotFound.
     240    if not media.state == u'processed':
     241        return render_404(request)
     242
    235243    form = user_forms.MediaCollectForm(request.form)
    236244    # A user's own collections:
    237245    form.collection.query = Collection.query.filter_by(