Ticket #7150: newforms-admin-view-permission.patch
File newforms-admin-view-permission.patch, 5.5 KB (added by , 17 years ago) |
---|
-
db/models/options.py
292 292 def get_delete_permission(self): 293 293 return 'delete_%s' % self.object_name.lower() 294 294 295 def get_view_permission(self): 296 return 'view_%s' % self.object_name.lower() 297 295 298 def get_all_related_objects(self, local_only=False): 296 299 try: 297 300 self._related_objects_cache -
contrib/admin/options.py
290 290 opts = self.opts 291 291 return request.user.has_perm(opts.app_label + '.' + opts.get_delete_permission()) 292 292 293 def has_view_permission(self, request, obj=None): 294 """ 295 Returns True if the given request has permission to view the given 296 Django model instance. 297 298 If `obj` is None, this should return True if the given request has 299 permission to view *any* object of the given type. 300 """ 301 opts = self.opts 302 return request.user.has_perm(opts.app_label + '.' + opts.get_view_permission()) 303 304 293 305 def queryset(self, request): 294 306 """ 295 307 Returns a QuerySet of all model instances that can be edited by the … … 522 534 # to determine whether a given object exists. 523 535 obj = None 524 536 525 if not self.has_change_permission(request, obj):526 537 if (not self.has_change_permission(request, obj)) and (request.POST or (not self.has_view_permission(request, obj) ) ) : 538 raise PermissionDenied 527 539 528 540 if obj is None: 529 541 raise Http404('%s object with primary key %r does not exist.' % (opts.verbose_name, escape(object_id))) … … 588 600 from django.contrib.admin.views.main import ChangeList, ERROR_FLAG 589 601 opts = self.model._meta 590 602 app_label = opts.app_label 591 if not self.has_change_permission(request, None):592 603 if (not self.has_change_permission(request, None)) and (request.POST or (not self.has_view_permission(request, None) ) ) : 604 raise PermissionDenied 593 605 try: 594 606 cl = ChangeList(request, self.model, self.list_display, self.list_display_links, self.list_filter, 595 607 self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page, self) -
contrib/admin/templates/admin/index.html
22 22 {% if model.perms.change %} 23 23 <th scope="row"><a href="{{ model.admin_url }}">{{ model.name }}</a></th> 24 24 {% else %} 25 {% if model.perms.view %} 26 <th scope="row"><a href="{{ model.admin_url }}">{{ model.name }}</a></th> 27 {% else %} 25 28 <th scope="row">{{ model.name }}</th> 26 {% endif %} 29 {% endif %}{% endif %} 27 30 28 31 {% if model.perms.add %} 29 32 <td><a href="{{ model.admin_url }}add/" class="addlink">{% trans 'Add' %}</a></td> -
contrib/admin/sites.py
268 268 'add': model_admin.has_add_permission(request), 269 269 'change': model_admin.has_change_permission(request), 270 270 'delete': model_admin.has_delete_permission(request), 271 'view': model_admin.has_view_permission(request), 271 272 } 272 273 273 274 # Check whether user has any perm for this module. -
contrib/auth/management.py
12 12 def _get_all_permissions(opts): 13 13 "Returns (codename, name) for all permissions in the given opts." 14 14 perms = [] 15 for action in ('add', 'change', 'delete' ):15 for action in ('add', 'change', 'delete', 'view'): 16 16 perms.append((_get_permission_codename(action, opts), u'Can %s %s' % (action, opts.verbose_name_raw))) 17 17 return perms + list(opts.permissions) 18 18 -
contrib/auth/models.py
65 65 - The "add" permission limits the user's ability to view the "add" form and add an object. 66 66 - The "change" permission limits a user's ability to view the change list, view the "change" form and change an object. 67 67 - The "delete" permission limits the ability to delete an object. 68 - The "view" permission limits the ability to just watch the content of an object. 68 69 69 70 Permissions are set globally per type of object, not per specific object instance. It is possible to say "Mary may change news stories," but it's not currently possible to say "Mary may change news stories, but only the ones she created herself" or "Mary may only change news stories that have a certain status or publication date." 70 71