switch from first_name and last_name to name

This commit is contained in:
Jens Langhammer 2019-02-27 15:09:05 +01:00
parent 2db1738e4a
commit 5b771da972
22 changed files with 78 additions and 39 deletions

View file

@ -105,10 +105,9 @@ data:
email: mail # or userPrincipalName email: mail # or userPrincipalName
user_attribute_map: user_attribute_map:
active_directory: active_directory:
sAMAccountName: username username: "%(sAMAccountName)s"
mail: email email: "%(mail)s"
given_name: first_name name: "%(displayName)"
name: last_name
# # Create new users in LDAP upon sign-up # # Create new users in LDAP upon sign-up
# create_users: true # create_users: true
# # Reset LDAP password when user reset their password # # Reset LDAP password when user reset their password

View file

@ -11,7 +11,7 @@ class UserSerializer(ModelSerializer):
class Meta: class Meta:
model = User model = User
fields = ['is_superuser', 'username', 'first_name', 'last_name', 'email', 'date_joined', fields = ['is_superuser', 'username', 'name', 'email', 'date_joined',
'uuid'] 'uuid']

View file

@ -11,8 +11,7 @@
<thead> <thead>
<tr> <tr>
<th>{% trans 'Username' %}</th> <th>{% trans 'Username' %}</th>
<th>{% trans 'First Name' %}</th> <th>{% trans 'Name' %}</th>
<th>{% trans 'Last Name' %}</th>
<th>{% trans 'Active' %}</th> <th>{% trans 'Active' %}</th>
<th>{% trans 'Last Login' %}</th> <th>{% trans 'Last Login' %}</th>
<th></th> <th></th>
@ -22,8 +21,7 @@
{% for user in object_list %} {% for user in object_list %}
<tr> <tr>
<td>{{ user.username }}</td> <td>{{ user.username }}</td>
<td>{{ user.first_name|default:'-' }}</td> <td>{{ user.name|default:'-' }}</td>
<td>{{ user.last_name|default:'-' }}</td>
<td>{{ user.is_active }}</td> <td>{{ user.is_active }}</td>
<td>{{ user.last_login }}</td> <td>{{ user.last_login }}</td>
<td> <td>

View file

@ -14,8 +14,8 @@ class OpenIDUserInfoView(ScopedResourceMixin, View):
payload = { payload = {
'sub': request.user.uuid.int, 'sub': request.user.uuid.int,
'name': request.user.get_full_name(), 'name': request.user.get_full_name(),
'given_name': request.user.first_name, 'given_name': request.user.name,
'family_name': request.user.last_name, 'family_name': '',
'preferred_username': request.user.username, 'preferred_username': request.user.username,
'email': request.user.email, 'email': request.user.email,
} }

View file

@ -38,10 +38,8 @@ class SignUpForm(forms.Form):
"""SignUp Form""" """SignUp Form"""
title = _('Sign Up') title = _('Sign Up')
first_name = forms.CharField(label=_('First Name'), name = forms.CharField(label=_('Name'),
widget=forms.TextInput(attrs={'placeholder': _('First Name')})) widget=forms.TextInput(attrs={'placeholder': _('Name')}))
last_name = forms.CharField(label=_('Last Name'),
widget=forms.TextInput(attrs={'placeholder': _('Last Name')}))
username = forms.CharField(label=_('Username'), username = forms.CharField(label=_('Username'),
widget=forms.TextInput(attrs={'placeholder': _('Username')})) widget=forms.TextInput(attrs={'placeholder': _('Username')}))
email = forms.EmailField(label=_('E-Mail'), email = forms.EmailField(label=_('E-Mail'),

View file

@ -13,7 +13,10 @@ class UserDetailForm(forms.ModelForm):
class Meta: class Meta:
model = User model = User
fields = ['username', 'first_name', 'last_name', 'email'] fields = ['username', 'name', 'email']
widgets = {
'name': forms.TextInput
}
class PasswordChangeForm(forms.Form): class PasswordChangeForm(forms.Form):
"""Form to update password""" """Form to update password"""

View file

@ -0,0 +1,38 @@
# Generated by Django 2.1.7 on 2019-02-27 13:55
from django.db import migrations, models
def migrate_names(apps, schema_editor):
"""migrate first_name and last_name to name"""
User = apps.get_model("passbook_core", "User")
for user in User.objects.all():
user.name = '%s %s' % (user.first_name, user.last_name)
user.save()
class Migration(migrations.Migration):
dependencies = [
('passbook_core', '0015_passwordpolicy_error_message'),
]
operations = [
migrations.AddField(
model_name='user',
name='name',
field=models.TextField(default=''),
preserve_default=False,
),
migrations.RunPython(migrate_names),
migrations.AlterField(
model_name='user',
name='name',
field=models.TextField(),
preserve_default=False,
),
migrations.AlterField(
model_name='fieldmatcherpolicy',
name='user_field',
field=models.TextField(choices=[('username', 'Username'), ('name', 'Name'), ('email', 'E-Mail'), ('is_staff', 'Is staff'), ('is_active', 'Is active'), ('data_joined', 'Date joined')]),
),
]

View file

@ -44,6 +44,8 @@ class User(AbstractUser):
"""Custom User model to allow easier adding o f user-based settings""" """Custom User model to allow easier adding o f user-based settings"""
uuid = models.UUIDField(default=uuid4, editable=False) uuid = models.UUIDField(default=uuid4, editable=False)
name = models.TextField()
sources = models.ManyToManyField('Source', through='UserSourceConnection') sources = models.ManyToManyField('Source', through='UserSourceConnection')
applications = models.ManyToManyField('Application') applications = models.ManyToManyField('Application')
groups = models.ManyToManyField('Group') groups = models.ManyToManyField('Group')
@ -253,8 +255,7 @@ class FieldMatcherPolicy(Policy):
USER_FIELDS = ( USER_FIELDS = (
('username', _('Username'),), ('username', _('Username'),),
('first_name', _('First Name'),), ('name', _('Name'),),
('last_name', _('Last Name'),),
('email', _('E-Mail'),), ('email', _('E-Mail'),),
('is_staff', _('Is staff'),), ('is_staff', _('Is staff'),),
('is_active', _('Is active'),), ('is_active', _('Is active'),),

View file

@ -15,8 +15,7 @@ class TestAuthenticationViews(TestCase):
def setUp(self): def setUp(self):
super().setUp() super().setUp()
self.sign_up_data = { self.sign_up_data = {
'first_name': 'Test', 'name': 'Test',
'last_name': 'User',
'username': 'beryjuorg', 'username': 'beryjuorg',
'email': 'unittest@passbook.beryju.org', 'email': 'unittest@passbook.beryju.org',
'password': 'B3ryju0rg!', 'password': 'B3ryju0rg!',

View file

@ -204,8 +204,7 @@ class SignUpView(UserPassesTestMixin, FormView):
new_user = User.objects.create( new_user = User.objects.create(
username=data.get('username'), username=data.get('username'),
email=data.get('email'), email=data.get('email'),
first_name=data.get('first_name'), name=data.get('name'),
last_name=data.get('last_name'),
) )
new_user.is_active = True new_user.is_active = True
try: try:

View file

@ -1,8 +1,10 @@
"""passbook core user views""" """passbook core user views"""
from django.contrib import messages from django.contrib import messages
from django.contrib.auth import logout, update_session_auth_hash from django.contrib.auth import logout, update_session_auth_hash
from django.contrib.messages.views import SuccessMessageMixin
from django.forms.utils import ErrorList from django.forms.utils import ErrorList
from django.shortcuts import redirect, reverse from django.shortcuts import redirect, reverse
from django.urls import reverse_lazy
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from django.views.generic import DeleteView, FormView, UpdateView from django.views.generic import DeleteView, FormView, UpdateView
@ -11,12 +13,15 @@ from passbook.core.forms.users import PasswordChangeForm, UserDetailForm
from passbook.lib.config import CONFIG from passbook.lib.config import CONFIG
class UserSettingsView(UpdateView): class UserSettingsView(SuccessMessageMixin, UpdateView):
"""Update User settings""" """Update User settings"""
template_name = 'user/settings.html' template_name = 'user/settings.html'
form_class = UserDetailForm form_class = UserDetailForm
success_message = _('Successfully updated user.')
success_url = reverse_lazy('passbook_core:user-settings')
def get_object(self): def get_object(self):
return self.request.user return self.request.user

View file

@ -129,7 +129,7 @@ class LDAPConnector:
# Create the user data. # Create the user data.
field_map = { field_map = {
'username': '%(' + USERNAME_FIELD + ')s', 'username': '%(' + USERNAME_FIELD + ')s',
'first_name': '%(givenName)s %(sn)s', 'name': '%(givenName)s %(sn)s',
'email': '%(mail)s', 'email': '%(mail)s',
} }
user_fields = {} user_fields = {}
@ -224,9 +224,9 @@ class LDAPConnector:
'cn': str(username), 'cn': str(username),
'description': str('t=' + time()), 'description': str('t=' + time()),
'sAMAccountName': str(username_trunk), 'sAMAccountName': str(username_trunk),
'givenName': str(user.first_name), 'givenName': str(user.name),
'displayName': str(user.username), 'displayName': str(user.username),
'name': str(user.first_name), 'name': str(user.name),
'mail': str(user.email), 'mail': str(user.email),
'userPrincipalName': str(username + '@' + self._source.domain), 'userPrincipalName': str(username + '@' + self._source.domain),
'objectClass': ['top', 'person', 'organizationalPerson', 'user'], 'objectClass': ['top', 'person', 'organizationalPerson', 'user'],

View file

@ -77,10 +77,9 @@ ldap:
email: mail # or userPrincipalName email: mail # or userPrincipalName
user_attribute_map: user_attribute_map:
active_directory: active_directory:
sAMAccountName: username username: "%(sAMAccountName)s"
mail: email email: "%(mail)s"
given_name: first_name name: "%(displayName)"
name: last_name
oauth_client: oauth_client:
# List of python packages with sources types to load. # List of python packages with sources types to load.
types: types:

View file

@ -52,7 +52,7 @@ class DiscordOAuth2Callback(OAuthCallback):
user_data = { user_data = {
'username': info.get('username'), 'username': info.get('username'),
'email': info.get('email', 'None'), 'email': info.get('email', 'None'),
'first_name': info.get('username'), 'name': info.get('username'),
'password': None, 'password': None,
} }
discord_user = user_get_or_create(**user_data) discord_user = user_get_or_create(**user_data)

View file

@ -23,7 +23,7 @@ class FacebookOAuth2Callback(OAuthCallback):
user_data = { user_data = {
'username': info.get('name'), 'username': info.get('name'),
'email': info.get('email', ''), 'email': info.get('email', ''),
'first_name': info.get('name'), 'name': info.get('name'),
'password': None, 'password': None,
} }
fb_user = user_get_or_create(**user_data) fb_user = user_get_or_create(**user_data)

View file

@ -13,7 +13,7 @@ class GitHubOAuth2Callback(OAuthCallback):
user_data = { user_data = {
'username': info.get('login'), 'username': info.get('login'),
'email': info.get('email', ''), 'email': info.get('email', ''),
'first_name': info.get('name'), 'name': info.get('name'),
'password': None, 'password': None,
} }
gh_user = user_get_or_create(**user_data) gh_user = user_get_or_create(**user_data)

View file

@ -22,7 +22,7 @@ class GoogleOAuth2Callback(OAuthCallback):
user_data = { user_data = {
'username': info.get('email'), 'username': info.get('email'),
'email': info.get('email', ''), 'email': info.get('email', ''),
'first_name': info.get('name'), 'name': info.get('name'),
'password': None, 'password': None,
} }
google_user = user_get_or_create(**user_data) google_user = user_get_or_create(**user_data)

View file

@ -61,7 +61,7 @@ class RedditOAuth2Callback(OAuthCallback):
user_data = { user_data = {
'username': info.get('name'), 'username': info.get('name'),
'email': None, 'email': None,
'first_name': info.get('name'), 'name': info.get('name'),
'password': None, 'password': None,
} }
reddit_user = user_get_or_create(**user_data) reddit_user = user_get_or_create(**user_data)

View file

@ -46,7 +46,7 @@ class SupervisrOAuthCallback(OAuthCallback):
user_data = { user_data = {
'username': info.get('username'), 'username': info.get('username'),
'email': info.get('email', ''), 'email': info.get('email', ''),
'first_name': info.get('first_name'), 'name': info.get('first_name'),
'password': None, 'password': None,
} }
sv_user = user_get_or_create(**user_data) sv_user = user_get_or_create(**user_data)

View file

@ -38,7 +38,7 @@ class TwitterOAuthCallback(OAuthCallback):
user_data = { user_data = {
'username': info.get('screen_name'), 'username': info.get('screen_name'),
'email': info.get('email', ''), 'email': info.get('email', ''),
'first_name': info.get('name'), 'name': info.get('name'),
'password': None, 'password': None,
} }
tw_user = user_get_or_create(**user_data) tw_user = user_get_or_create(**user_data)

View file

@ -27,7 +27,7 @@ class GitHubUserView(View):
"received_events_url": "", "received_events_url": "",
"type": "User", "type": "User",
"site_admin": False, "site_admin": False,
"name": "%s %s" % (request.user.first_name, request.user.last_name), "name": request.user.name,
"company": "", "company": "",
"blog": "", "blog": "",
"location": "", "location": "",

View file

@ -157,7 +157,7 @@ class Processor:
{ {
'FriendlyName': 'cn', 'FriendlyName': 'cn',
'Name': 'urn:oid:2.5.4.3', 'Name': 'urn:oid:2.5.4.3',
'Value': self._django_request.user.first_name, 'Value': self._django_request.user.name,
}, },
{ {
'FriendlyName': 'mail', 'FriendlyName': 'mail',