accounts: allow unconditional “title” profile attribute edition (#88833)
gitea/authentic2-cut/pipeline/head This commit looks good
Details
gitea/authentic2-cut/pipeline/head This commit looks good
Details
This edition used to be deactivated for accounts whose owner linked their FranceConnect identity. Only deleting the link allowed for attribute edition, rather inconvenient. Instead we make “title” be a “crown” attribute, as opposed to its earlier “core” attribute role.
This commit is contained in:
parent
7de4b273df
commit
3c6320596e
|
@ -190,7 +190,6 @@ class AppConfig(django.apps.AppConfig):
|
|||
'birthcountry',
|
||||
'birthplace',
|
||||
'gender',
|
||||
'title',
|
||||
'birthdate',
|
||||
]:
|
||||
# del form.fields[field_name]
|
||||
|
@ -451,7 +450,7 @@ class AppConfig(django.apps.AppConfig):
|
|||
|
||||
if view.__class__.__name__ == 'EditProfile':
|
||||
if form.instance and form.instance.attributes.validated:
|
||||
for field in ('first_name', 'last_name', 'birthdate', 'title', 'birthplace', 'birthcountry'):
|
||||
for field in ('first_name', 'last_name', 'birthdate', 'birthplace', 'birthcountry'):
|
||||
form.fields.pop(field, None)
|
||||
for field in form.fields.values():
|
||||
if hasattr(field, 'max_length'):
|
||||
|
|
|
@ -6,9 +6,10 @@ PLATFORM = vars().get('PLATFORM')
|
|||
if PLATFORM not in ['dev', 'test', 'prod']:
|
||||
PLATFORM = 'prod'
|
||||
|
||||
CORE_ATTRIBUTES = ['title', 'first_name', 'last_name', 'birthdate', 'birthplace', 'birthcountry']
|
||||
CORE_ATTRIBUTES = ['first_name', 'last_name', 'birthdate', 'birthplace', 'birthcountry']
|
||||
|
||||
CROWN_ATTRIBUTES = [
|
||||
'title',
|
||||
'preferred_username',
|
||||
'preferred_givenname',
|
||||
'address_number',
|
||||
|
|
|
@ -1 +1 @@
|
|||
{% extends "authentic2/accounts_edit.html %}
|
||||
{% extends "authentic2/accounts_edit.html" %}
|
||||
|
|
|
@ -39,7 +39,6 @@ class EditCoreView(EditProfile):
|
|||
fields = [
|
||||
'first_name',
|
||||
'last_name',
|
||||
'title',
|
||||
'birthdate',
|
||||
'birthplace',
|
||||
'birthcountry',
|
||||
|
@ -61,19 +60,12 @@ edit_core = EditCoreView.as_view()
|
|||
|
||||
class EditCrownView(EditProfile):
|
||||
template_names = ['authentic2/cut-edit-crown.html']
|
||||
fields = [
|
||||
'first_name',
|
||||
'last_name',
|
||||
'title',
|
||||
'birthdate',
|
||||
'birthplace',
|
||||
'birthcountry',
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def get_fields(cls, scopes=None):
|
||||
fields, labels = super().get_fields(scopes=scopes)
|
||||
return [field for field in fields if field not in cls.fields], labels
|
||||
# discard fields accessible from core attributes edit page
|
||||
return [field for field in fields if field not in EditCoreView.fields], labels
|
||||
|
||||
def form_valid(self, form):
|
||||
response = super().form_valid(form)
|
||||
|
|
|
@ -204,3 +204,41 @@ def test_cut_event_fc_unlink(db, rf, app):
|
|||
assert not user.attributes.validation_date
|
||||
assert not user.attributes.validation_partner
|
||||
assert not user.attributes.validated
|
||||
|
||||
|
||||
def test_a2_hook_front_modify_form(db, rf, app, admin):
|
||||
class DummyModule:
|
||||
__path__ = [
|
||||
'./dummy',
|
||||
]
|
||||
|
||||
dummy = DummyModule()
|
||||
title = Attribute.objects.get(name='title')
|
||||
app_config = AppConfig('authentic2_cut', dummy)
|
||||
|
||||
FcAuthenticator.objects.create(enabled=True)
|
||||
User = get_user_model()
|
||||
user = User.objects.create(
|
||||
email='john.doe@example.org', first_name='John', last_name='Doe', username='jdoe'
|
||||
)
|
||||
user.set_password('jdoe')
|
||||
AttributeValue.objects.create(owner=user, attribute=title, content='Mr')
|
||||
FcAccount.objects.create(user=user, sub='sub1')
|
||||
user.attributes.validation_context = 'FC'
|
||||
user.attributes.validation_date = now().date()
|
||||
user.attributes.validation_partner = 'lambda'
|
||||
user.attributes.validated = True
|
||||
user.save()
|
||||
|
||||
login(app, user)
|
||||
response = app.get(reverse('cut-edit-crown'))
|
||||
form = response.form
|
||||
form.set('title', 'Mrs')
|
||||
response = response.form.submit()
|
||||
|
||||
assert response.location == '/accounts/'
|
||||
user.refresh_from_db()
|
||||
assert user.attributes.title == 'Mrs'
|
||||
|
||||
response = app.get(reverse('cut-edit-core'))
|
||||
assert 'title' not in response.form.fields
|
||||
|
|
Loading…
Reference in New Issue