Merge pull request #2999 from bison/user-location
Add user location metadata filed
This commit is contained in:
commit
62971b7f20
11 changed files with 79 additions and 15 deletions
|
@ -437,6 +437,7 @@ class User(BaseModel):
|
|||
given_name = CharField(null=True)
|
||||
family_name = CharField(null=True)
|
||||
company = CharField(null=True)
|
||||
location = CharField(null=True)
|
||||
|
||||
def delete_instance(self, recursive=False, delete_nullable=False):
|
||||
# If we are deleting a robot account, only execute the subset of queries necessary.
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
"""Add user location field
|
||||
|
||||
Revision ID: cbc8177760d9
|
||||
Revises: 7367229b38d9
|
||||
Create Date: 2018-02-02 17:39:16.589623
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'cbc8177760d9'
|
||||
down_revision = '7367229b38d9'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import mysql
|
||||
from util.migrate import UTF8CharField
|
||||
|
||||
def upgrade(tables):
|
||||
op.add_column('user', sa.Column('location', UTF8CharField(length=255), nullable=True))
|
||||
|
||||
|
||||
def downgrade(tables):
|
||||
op.drop_column('user', 'location')
|
|
@ -381,12 +381,15 @@ def list_entity_robot_permission_teams(entity_name, include_permissions=False):
|
|||
return TupleSelector(query, fields)
|
||||
|
||||
|
||||
def update_user_metadata(user, given_name=None, family_name=None, company=None):
|
||||
def update_user_metadata(user, metadata=None):
|
||||
""" Updates the metadata associated with the user, including his/her name and company. """
|
||||
metadata = metadata if metadata is not None else {}
|
||||
|
||||
with db_transaction():
|
||||
user.given_name = given_name or user.given_name
|
||||
user.family_name = family_name or user.family_name
|
||||
user.company = company or user.company
|
||||
user.given_name = metadata.get('given_name') or user.given_name
|
||||
user.family_name = metadata.get('family_name') or user.family_name
|
||||
user.company = metadata.get('company') or user.company
|
||||
user.location = metadata.get('location') or user.location
|
||||
user.save()
|
||||
|
||||
# Remove any prompts associated with the user's metadata being needed.
|
||||
|
|
Reference in a new issue