Skip to content

Commit

Permalink
Added separate permission method for undelete
Browse files Browse the repository at this point in the history
Defaults to simply call has_publish_permission method, but can be
overridden to have different behaviour if need be.  e.g. state of
objects means publishing should be block, but undelete should be allowed
(or vice versa).
  • Loading branch information
johnsensible committed Apr 18, 2012
1 parent a147db9 commit 7f11a4f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion publish/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
VERSION = (0, 3, 5)
VERSION = (0, 3, 6)
__version__ = '.'.join(map(str, VERSION))
3 changes: 2 additions & 1 deletion publish/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def _get_change_view_url(app_label, object_name, pk, levels_to_root):
return '%s%s/%s/%s/' % ('../'*levels_to_root, app_label,
object_name, quote(pk))


def delete_selected(modeladmin, request, queryset):
# wrap regular django delete_selected to check permissions for each object
for obj in queryset:
Expand All @@ -27,7 +28,7 @@ def delete_selected(modeladmin, request, queryset):

def undelete_selected(modeladmin, request, queryset):
for obj in queryset:
if not modeladmin.has_publish_permission(request, obj):
if not modeladmin.has_undelete_permission(request, obj):
raise PermissionDenied
for obj in queryset:
obj.undelete()
Expand Down
5 changes: 4 additions & 1 deletion publish/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ def has_delete_permission(self, request, obj=None):
if obj and obj.is_public:
return False
return super(PublishableAdmin, self).has_delete_permission(request, obj)


def has_undelete_permission(self, request, obj=None):
return self.has_publish_permission(request, obj=obj)

def has_publish_permission(self, request, obj=None):
opts = self.opts
return request.user.has_perm(opts.app_label + '.' + opts.get_publish_permission())
Expand Down

0 comments on commit 7f11a4f

Please sign in to comment.