Skip to content
This repository has been archived by the owner on Nov 4, 2022. It is now read-only.

Commit

Permalink
Use a single field for a user's personal name
Browse files Browse the repository at this point in the history
Ref #18
  • Loading branch information
marksparkza committed Jul 1, 2021
1 parent 4945cb4 commit 33e8c10
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Single field for user name
Revision ID: fba3c5e8ab83
Revises: 249e24966335
Create Date: 2021-07-01 10:37:02.780672
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'fba3c5e8ab83'
down_revision = '249e24966335'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic ###
op.add_column('user', sa.Column('name', sa.String(), nullable=True))
op.drop_column('user', 'given_name')
op.drop_column('user', 'family_name')
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic ###
op.add_column('user', sa.Column('family_name', sa.VARCHAR(), autoincrement=False, nullable=True))
op.add_column('user', sa.Column('given_name', sa.VARCHAR(), autoincrement=False, nullable=True))
op.drop_column('user', 'name')
# ### end Alembic commands ###
3 changes: 1 addition & 2 deletions odp/api/models/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ class IDTokenData(BaseModel):
sub: str
email: EmailStr
email_verified: bool
family_name: Optional[str]
given_name: Optional[str]
name: Optional[str]
picture: Optional[str]

# The `role` field is used strictly for the special case of indicating a user's
Expand Down
3 changes: 1 addition & 2 deletions odp/db/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ class User(Base):
superuser = Column(Boolean, nullable=False)
active = Column(Boolean, nullable=False)
verified = Column(Boolean, nullable=False)
family_name = Column(String)
given_name = Column(String)
name = Column(String)
picture = Column(String)

# many-to-many relationship between institution and user represented by member
Expand Down
3 changes: 1 addition & 2 deletions odp/identity/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class AutoLoginForm(FlaskForm):


class ProfileForm(FlaskForm):
given_name = StringField(label='First name')
family_name = StringField(label='Last name')
name = StringField(label='Full name')
picture = StringField(label='Photo URL')
submit = SubmitField(label='Log in')
3 changes: 1 addition & 2 deletions odp/identity/templates/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
{% block content %}
<form action="{{ url_for('account.profile', token=token) }}" method="POST">
{{ form.csrf_token }}
{{ render_field(form.given_name) }}
{{ render_field(form.family_name) }}
{{ render_field(form.name) }}
{{ render_field(form.submit) }}
</form>
{% endblock %}
3 changes: 1 addition & 2 deletions odp/lib/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ def get_token_data(user: User, scopes: List[str]) -> Tuple[AccessTokenData, IDTo
sub=user.id,
email=user.email,
email_verified=user.verified,
family_name=user.family_name,
given_name=user.given_name,
name=user.name,
picture=user.picture,
role=[],
)
Expand Down
4 changes: 2 additions & 2 deletions odp/lib/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def update_user_profile(user_id, **userinfo):
"""
with transaction():
user = User.query.get(user_id)
for attr in 'family_name', 'given_name', 'picture':
for attr in 'name', 'picture':
if attr in userinfo:
setattr(user, attr, userinfo[attr])
user.save()
Expand All @@ -316,6 +316,6 @@ def get_user_profile(user_id):
"""
user = User.query.get(user_id)
info = {}
for attr in 'family_name', 'given_name', 'picture':
for attr in 'name', 'picture':
info[attr] = getattr(user, attr)
return info

0 comments on commit 33e8c10

Please sign in to comment.