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.
|
||||
|
|
|
@ -135,6 +135,7 @@ def user_view(user, previous_username=None):
|
|||
'company': user.company,
|
||||
'family_name': user.family_name,
|
||||
'given_name': user.given_name,
|
||||
'location': user.location,
|
||||
})
|
||||
|
||||
analytics_metadata = user_analytics.get_user_analytics_metadata(user)
|
||||
|
@ -246,6 +247,10 @@ class User(ApiResource):
|
|||
'type': 'string',
|
||||
'description': 'The optional entered company for the user',
|
||||
},
|
||||
'location': {
|
||||
'type': 'string',
|
||||
'description': 'The optional entered location for the user',
|
||||
},
|
||||
},
|
||||
},
|
||||
'UserView': {
|
||||
|
@ -362,14 +367,21 @@ class User(ApiResource):
|
|||
model.user.update_email(user, new_email, auto_verify=not features.MAILING)
|
||||
|
||||
if features.USER_METADATA:
|
||||
if 'given_name' in user_data or 'family_name' in user_data or 'company' in user_data:
|
||||
model.user.update_user_metadata(user, user_data.get('given_name'),
|
||||
user_data.get('family_name'), user_data.get('company'))
|
||||
metadata_fields = ('given_name', 'family_name', 'company', 'location')
|
||||
if any(field in user_data for field in metadata_fields):
|
||||
model.user.update_user_metadata(user, {
|
||||
'given_name': user_data.get('given_name'),
|
||||
'family_name': user_data.get('family_name'),
|
||||
'company': user_data.get('company'),
|
||||
'location': user_data.get('location'),
|
||||
})
|
||||
|
||||
ua_mdata_future = user_analytics.change_metadata(
|
||||
user.email,
|
||||
user_data.get('given_name'),
|
||||
user_data.get('family_name'),
|
||||
user_data.get('company'),
|
||||
user_data.get('location'),
|
||||
)
|
||||
ua_mdata_future.add_done_callback(build_error_callback('Change metadata failed'))
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ def common_login(user_uuid, permanent_session=True):
|
|||
user.given_name,
|
||||
user.family_name,
|
||||
user.company,
|
||||
user.location,
|
||||
)
|
||||
create_lead_future.add_done_callback(build_error_callback('Create lead failed'))
|
||||
return True
|
||||
|
|
|
@ -4,7 +4,11 @@ from collections import namedtuple
|
|||
from six import add_metaclass
|
||||
|
||||
|
||||
class User(namedtuple('User', ['uuid', 'username', 'email', 'given_name', 'family_name', 'company'])):
|
||||
USER_FIELDS = ['uuid', 'username', 'email', 'given_name',
|
||||
'family_name', 'company', 'location']
|
||||
|
||||
|
||||
class User(namedtuple('User', USER_FIELDS)):
|
||||
"""
|
||||
User represents a user.
|
||||
"""
|
||||
|
|
|
@ -9,7 +9,8 @@ class EndpointsCommonDataPreOCIModel(EndpointsCommonDataInterface):
|
|||
return None
|
||||
|
||||
return User(uuid=user.uuid, username=user.username, email=user.email,
|
||||
given_name=user.given_name, family_name=user.family_name, company=user.company)
|
||||
given_name=user.given_name, family_name=user.family_name,
|
||||
company=user.company, location=user.location)
|
||||
|
||||
def get_namespace_uuid(self, namespace_name):
|
||||
user = model.user.get_namespace_user(namespace_name)
|
||||
|
|
|
@ -68,6 +68,15 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group nested">
|
||||
<label for="location">Location</label>
|
||||
<div class="field-row">
|
||||
<span class="field-container">
|
||||
<input type="text" class="form-control" placeholder="Location" ng-model="metadata.location" name="location"></span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="margin-top: 20px">
|
||||
<input type="submit" class="btn btn-primary" value="Save Details"
|
||||
ng-disabled="!metadata.name && !metadata.company">
|
||||
|
@ -76,4 +85,4 @@
|
|||
No thanks</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -152,6 +152,12 @@
|
|||
<a class="co-modify-link" ng-click="showChangeMetadata('company', 'company name')">{{ context.viewuser.company || '(None)' }}</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr quay-show="Features.USER_METADATA">
|
||||
<td>Location:</td>
|
||||
<td>
|
||||
<a class="co-modify-link" ng-click="showChangeMetadata('location', 'location')">{{ context.viewuser.location || '(None)' }}</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr quay-show="Config.AUTHENTICATION_TYPE == 'Database'">
|
||||
<td>Password:</td>
|
||||
<td>
|
||||
|
|
Binary file not shown.
|
@ -39,7 +39,7 @@ class _MarketoAnalyticsClient(object):
|
|||
self._munchkin_private_key = munchkin_private_key
|
||||
self._lead_source = lead_source
|
||||
|
||||
def _get_lead_metadata(self, given_name, family_name, company):
|
||||
def _get_lead_metadata(self, given_name, family_name, company, location):
|
||||
metadata = {}
|
||||
if given_name:
|
||||
metadata['firstName'] = given_name
|
||||
|
@ -50,9 +50,12 @@ class _MarketoAnalyticsClient(object):
|
|||
if company:
|
||||
metadata['company'] = company
|
||||
|
||||
if location:
|
||||
metadata['location'] = location
|
||||
|
||||
return metadata
|
||||
|
||||
def create_lead(self, email, username, given_name, family_name, company):
|
||||
def create_lead(self, email, username, given_name, family_name, company, location):
|
||||
lead_data = dict(
|
||||
email=email,
|
||||
Quay_Username__c=username,
|
||||
|
@ -60,7 +63,8 @@ class _MarketoAnalyticsClient(object):
|
|||
Lead_Source_Detail__c=self._lead_source,
|
||||
)
|
||||
|
||||
lead_data.update(self._get_lead_metadata(given_name, family_name, company))
|
||||
lead_data.update(self._get_lead_metadata(given_name, family_name,
|
||||
company, location))
|
||||
|
||||
self._marketo.create_update_leads(
|
||||
action='createOrUpdate',
|
||||
|
@ -93,8 +97,8 @@ class _MarketoAnalyticsClient(object):
|
|||
lookupField='id',
|
||||
)
|
||||
|
||||
def change_metadata(self, email, given_name, family_name, company):
|
||||
lead_data = self._get_lead_metadata(given_name, family_name, company)
|
||||
def change_metadata(self, email, given_name, family_name, company, location):
|
||||
lead_data = self._get_lead_metadata(given_name, family_name, company, location)
|
||||
if not lead_data:
|
||||
return
|
||||
|
||||
|
|
Reference in a new issue