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):
|
268 | 268 | @wraps(controller) |
269 | 269 | def wrapper(request, *args, **kwargs): |
270 | 270 | media = MediaEntry.query.filter_by( |
271 | | id=request.matchdict['media_id'], |
272 | | state=u'processed').first() |
| 271 | id=request.matchdict['media_id']).first() |
273 | 272 | # Still no media? Okay, 404. |
274 | 273 | if not media: |
275 | 274 | return render_404(request) |
diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py
index b15fb2e79..17aea9229 100644
a
|
b
|
import mimetypes
|
55 | 55 | @get_media_entry_by_id |
56 | 56 | @require_active_login |
57 | 57 | def 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 | |
58 | 62 | if not may_edit_media(request, media): |
59 | 63 | raise Forbidden("User may not edit this media") |
60 | 64 | |
… |
… |
UNSAFE_MIMETYPES = [
|
115 | 119 | @get_media_entry_by_id |
116 | 120 | @require_active_login |
117 | 121 | def 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 | |
118 | 126 | if mg_globals.app_config['allow_attachments']: |
119 | 127 | form = forms.EditAttachmentsForm() |
120 | 128 | |
… |
… |
def change_email(request):
|
499 | 507 | @require_active_login |
500 | 508 | @get_media_entry_by_id |
501 | 509 | def 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 | |
502 | 514 | form = forms.EditMetaDataForm(request.form) |
503 | 515 | if request.method == "POST" and form.validate(): |
504 | 516 | metadata_dict = dict([(row['identifier'],row['value']) |
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):
|
180 | 180 | if not request.method == 'POST': |
181 | 181 | raise MethodNotAllowed() |
182 | 182 | |
| 183 | # If media is not processed, return NotFound. |
| 184 | if not media.state == u'processed': |
| 185 | return render_404(request) |
| 186 | |
183 | 187 | comment = request.db.TextComment() |
184 | 188 | comment.actor = request.user.id |
185 | 189 | comment.content = six.text_type(request.form['comment_content']) |
… |
… |
def media_preview_comment(request):
|
232 | 236 | def media_collect(request, media): |
233 | 237 | """Add media to collection submission""" |
234 | 238 | |
| 239 | # If media is not processed, return NotFound. |
| 240 | if not media.state == u'processed': |
| 241 | return render_404(request) |
| 242 | |
235 | 243 | form = user_forms.MediaCollectForm(request.form) |
236 | 244 | # A user's own collections: |
237 | 245 | form.collection.query = Collection.query.filter_by( |