Ticket #7150: newforms-admin-view-permission-r7737.patch
File newforms-admin-view-permission-r7737.patch, 5.7 KB (added by , 16 years ago) |
---|
-
db/models/options.py
296 296 def get_delete_permission(self): 297 297 return 'delete_%s' % self.object_name.lower() 298 298 299 def get_view_permission(self): 300 return 'view_%s' % self.object_name.lower() 301 299 302 def get_all_related_objects(self, local_only=False): 300 303 try: 301 304 self._related_objects_cache -
contrib/admin/options.py
319 319 opts = self.opts 320 320 return request.user.has_perm(opts.app_label + '.' + opts.get_delete_permission()) 321 321 322 def has_view_permission(self, request, obj=None): 323 """ 324 Returns True if the given request has permission to view the given 325 Django model instance. 326 327 If `obj` is None, this should return True if the given request has 328 permission to view *any* object of the given type. 329 """ 330 opts = self.opts 331 return request.user.has_perm(opts.app_label + '.' + opts.get_view_permission()) 332 322 333 def queryset(self, request): 323 334 """ 324 335 Returns a QuerySet of all model instances that can be edited by the … … 557 568 # to determine whether a given object exists. 558 569 obj = None 559 570 560 if not self.has_change_permission(request, obj):571 if not (self.has_change_permission(request, obj) or (not request.POST and self.has_view_permission(request, obj))): 561 572 raise PermissionDenied 562 573 563 574 if obj is None: … … 625 636 from django.contrib.admin.views.main import ChangeList, ERROR_FLAG 626 637 opts = self.model._meta 627 638 app_label = opts.app_label 628 if not self.has_change_permission(request, None):639 if not (self.has_change_permission(request, None) or (not request.POST and self.has_view_permission(request, None))): 629 640 raise PermissionDenied 630 641 try: 631 642 cl = ChangeList(request, self.model, self.list_display, self.list_display_links, self.list_filter, -
contrib/admin/templatetags/admin_modify.py
16 16 'show_save_and_add_another': context['has_add_permission'] and 17 17 not is_popup and (not save_as or context['add']), 18 18 'show_save_and_continue': not is_popup and context['has_change_permission'], 19 'show_save': True19 'show_save': change and context['has_change_permission'] or context['add'] and context['has_add_permission'] 20 20 } 21 21 submit_row = register.inclusion_tag('admin/submit_line.html', takes_context=True)(submit_row) -
contrib/admin/templates/admin/index.html
19 19 <caption>{% blocktrans with app.name as name %}{{ name }}{% endblocktrans %}</caption> 20 20 {% for model in app.models %} 21 21 <tr> 22 {% if model.perms.change %}22 {% if model.perms.change or model.perms.view %} 23 23 <th scope="row"><a href="{{ model.admin_url }}">{{ model.name }}</a></th> 24 24 {% else %} 25 25 <th scope="row">{{ model.name }}</th> -
contrib/admin/sites.py
276 276 'add': model_admin.has_add_permission(request), 277 277 'change': model_admin.has_change_permission(request), 278 278 'delete': model_admin.has_delete_permission(request), 279 'view': model_admin.has_view_permission(request), 279 280 } 280 281 281 282 # Check whether user has any perm for this module. -
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 view the change list and view the object detail page. 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 -
contrib/auth/management/__init__.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