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.
This commit is contained in:
parent
1f8c877d74
commit
2f2b4cbacb
@ -268,8 +268,7 @@ def get_media_entry_by_id(controller):
|
|||||||
@wraps(controller)
|
@wraps(controller)
|
||||||
def wrapper(request, *args, **kwargs):
|
def wrapper(request, *args, **kwargs):
|
||||||
media = MediaEntry.query.filter_by(
|
media = MediaEntry.query.filter_by(
|
||||||
id=request.matchdict['media_id'],
|
id=request.matchdict['media_id']).first()
|
||||||
state=u'processed').first()
|
|
||||||
# Still no media? Okay, 404.
|
# Still no media? Okay, 404.
|
||||||
if not media:
|
if not media:
|
||||||
return render_404(request)
|
return render_404(request)
|
||||||
|
@ -55,6 +55,10 @@ import mimetypes
|
|||||||
@get_media_entry_by_id
|
@get_media_entry_by_id
|
||||||
@require_active_login
|
@require_active_login
|
||||||
def edit_media(request, media):
|
def edit_media(request, media):
|
||||||
|
# If media is not processed, return NotFound.
|
||||||
|
if not media.state == u'processed':
|
||||||
|
return render_404(request)
|
||||||
|
|
||||||
if not may_edit_media(request, media):
|
if not may_edit_media(request, media):
|
||||||
raise Forbidden("User may not edit this media")
|
raise Forbidden("User may not edit this media")
|
||||||
|
|
||||||
@ -115,6 +119,10 @@ UNSAFE_MIMETYPES = [
|
|||||||
@get_media_entry_by_id
|
@get_media_entry_by_id
|
||||||
@require_active_login
|
@require_active_login
|
||||||
def edit_attachments(request, media):
|
def edit_attachments(request, media):
|
||||||
|
# If media is not processed, return NotFound.
|
||||||
|
if not media.state == u'processed':
|
||||||
|
return render_404(request)
|
||||||
|
|
||||||
if mg_globals.app_config['allow_attachments']:
|
if mg_globals.app_config['allow_attachments']:
|
||||||
form = forms.EditAttachmentsForm()
|
form = forms.EditAttachmentsForm()
|
||||||
|
|
||||||
@ -499,6 +507,10 @@ def change_email(request):
|
|||||||
@require_active_login
|
@require_active_login
|
||||||
@get_media_entry_by_id
|
@get_media_entry_by_id
|
||||||
def edit_metadata(request, media):
|
def edit_metadata(request, media):
|
||||||
|
# If media is not processed, return NotFound.
|
||||||
|
if not media.state == u'processed':
|
||||||
|
return render_404(request)
|
||||||
|
|
||||||
form = forms.EditMetaDataForm(request.form)
|
form = forms.EditMetaDataForm(request.form)
|
||||||
if request.method == "POST" and form.validate():
|
if request.method == "POST" and form.validate():
|
||||||
metadata_dict = dict([(row['identifier'],row['value'])
|
metadata_dict = dict([(row['identifier'],row['value'])
|
||||||
|
@ -180,6 +180,10 @@ def media_post_comment(request, media):
|
|||||||
if not request.method == 'POST':
|
if not request.method == 'POST':
|
||||||
raise MethodNotAllowed()
|
raise MethodNotAllowed()
|
||||||
|
|
||||||
|
# If media is not processed, return NotFound.
|
||||||
|
if not media.state == u'processed':
|
||||||
|
return render_404(request)
|
||||||
|
|
||||||
comment = request.db.TextComment()
|
comment = request.db.TextComment()
|
||||||
comment.actor = request.user.id
|
comment.actor = request.user.id
|
||||||
comment.content = six.text_type(request.form['comment_content'])
|
comment.content = six.text_type(request.form['comment_content'])
|
||||||
@ -232,6 +236,10 @@ def media_preview_comment(request):
|
|||||||
def media_collect(request, media):
|
def media_collect(request, media):
|
||||||
"""Add media to collection submission"""
|
"""Add media to collection submission"""
|
||||||
|
|
||||||
|
# If media is not processed, return NotFound.
|
||||||
|
if not media.state == u'processed':
|
||||||
|
return render_404(request)
|
||||||
|
|
||||||
form = user_forms.MediaCollectForm(request.form)
|
form = user_forms.MediaCollectForm(request.form)
|
||||||
# A user's own collections:
|
# A user's own collections:
|
||||||
form.collection.query = Collection.query.filter_by(
|
form.collection.query = Collection.query.filter_by(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user