From 51ef4fb920acd689755af6ea9f7765b341ebfcec Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 13 Oct 2023 16:39:19 -0400 Subject: [PATCH] Closes #13962: Add a copy-to-clipboard button to the key field of the API token creation form --- netbox/project-static/dist/netbox.js | Bin 529868 -> 529867 bytes netbox/project-static/dist/netbox.js.map | Bin 450255 -> 450255 bytes netbox/project-static/src/clipboard.ts | 2 +- netbox/templates/account/token.html | 5 ----- netbox/users/forms/model_forms.py | 3 +++ .../templates/form_helpers/render_field.html | 8 ++++++++ 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/netbox/project-static/dist/netbox.js b/netbox/project-static/dist/netbox.js index 7d16f9916551ad8f5deea05dcc5db33d79d507df..426302ea83c97ad0ae968919b4ede00f323f214e 100644 GIT binary patch delta 33 ocmX@JTH*9+g@zW!7N!>F7M2#)7Pc+yPQvZZ!tC3fg*iHz0MF(MZvX%Q delta 35 qcmX@TTH(xUg@zW!7N!>F7M2#)7Pc+yPQr|d?M}k%+nt0tI++0D;tJ0I diff --git a/netbox/project-static/dist/netbox.js.map b/netbox/project-static/dist/netbox.js.map index 1797f57ceb117de051fd4be372f96b16e715f26f..077c4bcc0b0e1e6c7dbb1eb1722ea94132e260b2 100644 GIT binary patch delta 29 lcmX@VSNi;3>4p}@7N!>F7M2#)Eo@1gjG5b$IoWcq0syPU3TprW delta 29 lcmX@VSNi;3>4p}@7N!>F7M2#)Eo@1gjM>|hIoWcq0syPi3T*%Y diff --git a/netbox/project-static/src/clipboard.ts b/netbox/project-static/src/clipboard.ts index 46ca5e36c..ddcb7b96e 100644 --- a/netbox/project-static/src/clipboard.ts +++ b/netbox/project-static/src/clipboard.ts @@ -2,7 +2,7 @@ import Clipboard from 'clipboard'; import { getElements } from './util'; export function initClipboard(): void { - for (const element of getElements('a.copy-content')) { + for (const element of getElements('.copy-content')) { new Clipboard(element); } } diff --git a/netbox/templates/account/token.html b/netbox/templates/account/token.html index d83e13ff5..57d1de3f4 100644 --- a/netbox/templates/account/token.html +++ b/netbox/templates/account/token.html @@ -15,11 +15,6 @@ {% block content %}
- {% if key and not settings.ALLOW_TOKEN_RETRIEVAL %} - - {% endif %}
{% trans "Token" %}
diff --git a/netbox/users/forms/model_forms.py b/netbox/users/forms/model_forms.py index 5fe84ad5f..1c3233f87 100644 --- a/netbox/users/forms/model_forms.py +++ b/netbox/users/forms/model_forms.py @@ -114,6 +114,9 @@ class UserTokenForm(BootstrapMixin, forms.ModelForm): help_text=_( 'Keys must be at least 40 characters in length. Be sure to record your key prior to ' 'submitting this form, as it may no longer be accessible once the token has been created.' + ), + widget=forms.TextInput( + attrs={'data-clipboard': 'true'} ) ) allowed_ips = SimpleArrayField( diff --git a/netbox/utilities/templates/form_helpers/render_field.html b/netbox/utilities/templates/form_helpers/render_field.html index 379dcc021..e5a564a3d 100644 --- a/netbox/utilities/templates/form_helpers/render_field.html +++ b/netbox/utilities/templates/form_helpers/render_field.html @@ -29,6 +29,14 @@ {{ label }}
+ {# Include a copy-to-clipboard button #} + {% elif 'data-clipboard' in field.field.widget.attrs %} +
+ {{ field }} + +
{# Default field rendering #} {% else %} {{ field }}