aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/decorators.py
diff options
context:
space:
mode:
authorJoar Wandborg <git@wandborg.com>2011-08-30 23:16:46 +0200
committerJoar Wandborg <git@wandborg.com>2011-08-30 23:16:46 +0200
commit502073f2bf65380be18b349a678ac075777889a4 (patch)
tree9472a0644926b2df8316d1f92fee53ebe58ae15c /mediagoblin/decorators.py
parent7d0efbae2955cf58eed86daa30cd3507c9088269 (diff)
downloadmediagoblin-502073f2bf65380be18b349a678ac075777889a4.tar.lz
mediagoblin-502073f2bf65380be18b349a678ac075777889a4.tar.xz
mediagoblin-502073f2bf65380be18b349a678ac075777889a4.zip
Feature #403 - Ability to delete media entries - Fixes according to feedback
* Moved `mediagoblin.confirm` stuff to `mediagoblin.user_pages`, templates too. * Removed route extension for `mediagoblin.confirm` * Created `delete_media_files` which deletes all media files on the public_store when the entry is deleted * Created a new decorator to check if a user has the permission to delete an entry.
Diffstat (limited to 'mediagoblin/decorators.py')
-rw-r--r--mediagoblin/decorators.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/mediagoblin/decorators.py b/mediagoblin/decorators.py
index c66049ca..c3d64327 100644
--- a/mediagoblin/decorators.py
+++ b/mediagoblin/decorators.py
@@ -51,6 +51,31 @@ def require_active_login(controller):
return _make_safe(new_controller_func, controller)
+def user_may_delete_media(controller):
+ """
+ Require user ownership of the MediaEntry
+
+ Originally:
+def may_delete_media(request, media):
+ \"\"\"
+ Check, if the request's user may edit the media details
+ \"\"\"
+ if media['uploader'] == request.user['_id']:
+ return True
+ if request.user['is_admin']:
+ return True
+ return False
+ """
+ def wrapper(request, *args, **kwargs):
+ if not request.user['_id'] == request.db.MediaEntry.find_one(
+ {'_id': ObjectId(
+ request.matchdict['media'])}).uploader()['_id']:
+ return exc.HTTPForbidden()
+
+ return controller(request, *args, **kwargs)
+
+ return _make_safe(wrapper, controller)
+
def uses_pagination(controller):
"""
@@ -122,3 +147,4 @@ def get_media_entry_by_id(controller):
return controller(request, media=media, *args, **kwargs)
return _make_safe(wrapper, controller)
+