mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-24 16:26:09 -06:00
8853 hide key on edit
This commit is contained in:
parent
dd48bf5a4c
commit
9a0b8f51bf
@ -1,4 +1,5 @@
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.forms import AuthenticationForm, PasswordChangeForm as DjangoPasswordChangeForm
|
||||
from django.contrib.postgres.forms import SimpleArrayField
|
||||
from django.utils.html import mark_safe
|
||||
@ -117,3 +118,12 @@ class TokenForm(BootstrapMixin, forms.ModelForm):
|
||||
widgets = {
|
||||
'expires': DateTimePicker(),
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
instance = getattr(self, 'instance', None)
|
||||
if instance and instance.id and not settings.ALLOW_TOKEN_RETRIEVAL:
|
||||
keyfield = self.fields['key']
|
||||
keyfield.disabled = True
|
||||
keyfield.required = False
|
||||
keyfield.widget = forms.HiddenInput()
|
||||
|
@ -235,7 +235,7 @@ class Token(models.Model):
|
||||
|
||||
def __str__(self):
|
||||
# Only display the last 24 bits of the token to avoid accidental exposure.
|
||||
return f"{self.key[-6:]} ({self.user})"
|
||||
return f"{self.description or self.key[-6:]} ({self.user})"
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.key:
|
||||
|
Loading…
Reference in New Issue
Block a user