Fixes #20476: Prohibit changing a token's owner (#20576)

This commit is contained in:
Jeremy Stretch
2025-10-14 14:12:15 -04:00
committed by GitHub
parent 37a9d03348
commit b7cc4c418b
3 changed files with 42 additions and 3 deletions

View File

@@ -177,6 +177,13 @@ class TokenForm(UserTokenForm):
'version', 'token', 'user', 'write_enabled', 'expires', 'description', 'allowed_ips',
]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# If not creating a new Token, disable the user field
if self.instance and not self.instance._state.adding:
self.fields['user'].disabled = True
class UserForm(forms.ModelForm):
password = forms.CharField(