Sfoglia il codice sorgente

Closes #23740: Deprecate direct object access in custom links

Direct access to the in-memory objects provided to custom link
templates as object, user and perms is deprecated as of v4.8.0 and
will be removed in v5.0. Document this on both custom link docs pages
and mark both render sites for removal. Also correct the stale request
description in the model docs, which still described the full WSGI
request.
Jason Novinger 2 giorni fa
parent
commit
0f073aa9eb

+ 3 - 0
docs/customization/custom-links.md

@@ -32,6 +32,9 @@ The following context data is available within the template when rendering a cus
 | `user`    | The current user (if authenticated)                                                                   |
 | `user`    | The current user (if authenticated)                                                                   |
 | `perms`   | The [permissions](https://docs.djangoproject.com/en/stable/topics/auth/default/#permissions) assigned to the user |
 | `perms`   | The [permissions](https://docs.djangoproject.com/en/stable/topics/auth/default/#permissions) assigned to the user |
 
 
+!!! warning "Deprecation Warning"
+    Direct access to the in-memory objects provided as `object`, `user`, and `perms` has been deprecated as of NetBox v4.8.0, and is scheduled for removal in NetBox v5.0. The variable names themselves are not deprecated. Custom links that rely on these objects will need to be updated for NetBox v5.0, although many custom links will continue to work as before. `request` and `debug` are not affected.
+
 !!! note "Changed in NetBox v4.7"
 !!! note "Changed in NetBox v4.7"
     For security, `request` no longer exposes the full WSGI request object. Only a safe subset of attributes is available: `request.id`, `request.path`, `request.path_info`, `request.method`, `request.GET` (the query parameters), and `request.user` (the username). Sensitive data such as cookies, headers, and session state is no longer accessible from within a custom link template.
     For security, `request` no longer exposes the full WSGI request object. Only a safe subset of attributes is available: `request.id`, `request.path`, `request.path_info`, `request.method`, `request.GET` (the query parameters), and `request.user` (the username). Sensitive data such as cookies, headers, and session state is no longer accessible from within a custom link template.
 
 

+ 4 - 1
docs/models/extras/customlink.md

@@ -51,6 +51,9 @@ The following context variables are available in to the text and link templates.
 |-----------|-----------------------------------------------------------------------------|
 |-----------|-----------------------------------------------------------------------------|
 | `object`  | The NetBox object being displayed                                           |
 | `object`  | The NetBox object being displayed                                           |
 | `debug`   | A boolean indicating whether debugging is enabled                           |
 | `debug`   | A boolean indicating whether debugging is enabled                           |
-| `request` | The current WSGI request                                                    |
+| `request` | A sanitized subset of the current request                                   |
 | `user`    | The current user (if authenticated)                                         |
 | `user`    | The current user (if authenticated)                                         |
 | `perms`   | The [permissions](../../administration/permissions.md) assigned to the user |
 | `perms`   | The [permissions](../../administration/permissions.md) assigned to the user |
+
+!!! warning "Deprecation Warning"
+    Direct access to the in-memory objects provided as `object`, `user`, and `perms` has been deprecated as of NetBox v4.8.0, and is scheduled for removal in NetBox v5.0. See the [custom links documentation](../../customization/custom-links.md) for details.

+ 3 - 0
netbox/extras/templatetags/custom_links.py

@@ -42,10 +42,13 @@ def custom_links(context, obj):
 
 
     # Pass select context data when rendering the CustomLink
     # Pass select context data when rendering the CustomLink
     link_context = {
     link_context = {
+        # TODO: Remove in NetBox v5.0
         'object': obj,
         'object': obj,
         'debug': context.get('debug', False),  # django.template.context_processors.debug
         'debug': context.get('debug', False),  # django.template.context_processors.debug
         'request': get_safe_request_context(context['request']),  # Sanitized subset of the request
         'request': get_safe_request_context(context['request']),  # Sanitized subset of the request
+        # TODO: Remove in NetBox v5.0
         'user': context['user'],  # django.contrib.auth.context_processors.auth
         'user': context['user'],  # django.contrib.auth.context_processors.auth
+        # TODO: Remove in NetBox v5.0
         'perms': context['perms'],  # django.contrib.auth.context_processors.auth
         'perms': context['perms'],  # django.contrib.auth.context_processors.auth
     }
     }
     template_code = ''
     template_code = ''

+ 2 - 0
netbox/netbox/tables/columns.py

@@ -720,6 +720,7 @@ class CustomLinkColumn(tables.Column):
 
 
     def _render_customlink(self, record, table):
     def _render_customlink(self, record, table):
         context = {
         context = {
+            # TODO: Remove in NetBox v5.0
             'object': record,
             'object': record,
             'debug': settings.DEBUG,
             'debug': settings.DEBUG,
         }
         }
@@ -727,6 +728,7 @@ class CustomLinkColumn(tables.Column):
             # If the request is available, include a sanitized subset of it as context
             # If the request is available, include a sanitized subset of it as context
             context.update({
             context.update({
                 'request': get_safe_request_context(request),
                 'request': get_safe_request_context(request),
+                # TODO: Remove in NetBox v5.0
                 **auth(request),
                 **auth(request),
             })
             })