0007-auth_saml-move-role-choice-field-outside-of-module-5.patch
src/authentic2/forms/fields.py | ||
---|---|---|
19 | 19 | |
20 | 20 |
import PIL.Image |
21 | 21 |
from django.core.files import File |
22 |
from django.forms import CharField, EmailField, FileField, ValidationError |
|
22 |
from django.forms import CharField, EmailField, FileField, ModelChoiceField, ValidationError
|
|
23 | 23 |
from django.forms.fields import FILE_INPUT_CONTRADICTION |
24 | 24 |
from django.utils.translation import ugettext_lazy as _ |
25 | 25 | |
26 | 26 |
from authentic2 import app_settings |
27 |
from authentic2.a2_rbac.models import Role |
|
27 | 28 |
from authentic2.forms.widgets import ( |
28 | 29 |
CheckPasswordInput, |
29 | 30 |
EmailInput, |
... | ... | |
31 | 32 |
PasswordInput, |
32 | 33 |
ProfileImageInput, |
33 | 34 |
) |
35 |
from authentic2.manager.utils import label_from_role |
|
34 | 36 |
from authentic2.passwords import validate_password |
35 | 37 |
from authentic2.validators import email_validator |
36 | 38 | |
... | ... | |
115 | 117 |
class ValidatedEmailField(EmailField): |
116 | 118 |
default_validators = [email_validator] |
117 | 119 |
widget = EmailInput |
120 | ||
121 | ||
122 |
class RoleChoiceField(ModelChoiceField): |
|
123 |
def __init__(self, *args, **kwargs): |
|
124 |
super().__init__(*args, **kwargs) |
|
125 |
self.queryset = Role.objects.exclude(slug__startswith='_') |
|
126 | ||
127 |
def label_from_instance(self, obj): |
|
128 |
return label_from_role(obj) |
src/authentic2_auth_saml/forms.py | ||
---|---|---|
16 | 16 | |
17 | 17 |
from django import forms |
18 | 18 | |
19 |
from authentic2.a2_rbac.models import Role
|
|
19 |
from authentic2.forms.fields import RoleChoiceField
|
|
20 | 20 |
from authentic2.forms.widgets import SelectAttributeWidget |
21 |
from authentic2.manager.utils import label_from_role |
|
22 | 21 | |
23 | 22 |
from .models import SAMLAuthenticator |
24 | 23 | |
... | ... | |
59 | 58 |
del self.fields['metadata_http_timeout'] |
60 | 59 | |
61 | 60 | |
62 |
class RoleChoiceField(forms.ModelChoiceField): |
|
63 |
def __init__(self, *args, **kwargs): |
|
64 |
super().__init__(*args, **kwargs) |
|
65 |
self.queryset = Role.objects.exclude(slug__startswith='_') |
|
66 | ||
67 |
def label_from_instance(self, obj): |
|
68 |
return label_from_role(obj) |
|
69 | ||
70 | ||
71 | 61 |
class SAMLRelatedObjectForm(forms.ModelForm): |
72 | 62 |
class Meta: |
73 | 63 |
exclude = ('authenticator',) |
74 |
- |