Merge pull request #2999 from bison/user-location

Add user location metadata filed
This commit is contained in:
Brad Ison 2018-02-20 16:48:37 -05:00 committed by GitHub
commit 62971b7f20
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 79 additions and 15 deletions

View file

@ -437,6 +437,7 @@ class User(BaseModel):
given_name = CharField(null=True) given_name = CharField(null=True)
family_name = CharField(null=True) family_name = CharField(null=True)
company = CharField(null=True) company = CharField(null=True)
location = CharField(null=True)
def delete_instance(self, recursive=False, delete_nullable=False): def delete_instance(self, recursive=False, delete_nullable=False):
# If we are deleting a robot account, only execute the subset of queries necessary. # If we are deleting a robot account, only execute the subset of queries necessary.

View file

@ -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')

View file

@ -381,12 +381,15 @@ def list_entity_robot_permission_teams(entity_name, include_permissions=False):
return TupleSelector(query, fields) 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. """ """ Updates the metadata associated with the user, including his/her name and company. """
metadata = metadata if metadata is not None else {}
with db_transaction(): with db_transaction():
user.given_name = given_name or user.given_name user.given_name = metadata.get('given_name') or user.given_name
user.family_name = family_name or user.family_name user.family_name = metadata.get('family_name') or user.family_name
user.company = company or user.company user.company = metadata.get('company') or user.company
user.location = metadata.get('location') or user.location
user.save() user.save()
# Remove any prompts associated with the user's metadata being needed. # Remove any prompts associated with the user's metadata being needed.

View file

@ -135,6 +135,7 @@ def user_view(user, previous_username=None):
'company': user.company, 'company': user.company,
'family_name': user.family_name, 'family_name': user.family_name,
'given_name': user.given_name, 'given_name': user.given_name,
'location': user.location,
}) })
analytics_metadata = user_analytics.get_user_analytics_metadata(user) analytics_metadata = user_analytics.get_user_analytics_metadata(user)
@ -246,6 +247,10 @@ class User(ApiResource):
'type': 'string', 'type': 'string',
'description': 'The optional entered company for the user', 'description': 'The optional entered company for the user',
}, },
'location': {
'type': 'string',
'description': 'The optional entered location for the user',
},
}, },
}, },
'UserView': { 'UserView': {
@ -362,14 +367,21 @@ class User(ApiResource):
model.user.update_email(user, new_email, auto_verify=not features.MAILING) model.user.update_email(user, new_email, auto_verify=not features.MAILING)
if features.USER_METADATA: if features.USER_METADATA:
if 'given_name' in user_data or 'family_name' in user_data or 'company' in user_data: metadata_fields = ('given_name', 'family_name', 'company', 'location')
model.user.update_user_metadata(user, user_data.get('given_name'), if any(field in user_data for field in metadata_fields):
user_data.get('family_name'), user_data.get('company')) 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( ua_mdata_future = user_analytics.change_metadata(
user.email, user.email,
user_data.get('given_name'), user_data.get('given_name'),
user_data.get('family_name'), user_data.get('family_name'),
user_data.get('company'), user_data.get('company'),
user_data.get('location'),
) )
ua_mdata_future.add_done_callback(build_error_callback('Change metadata failed')) ua_mdata_future.add_done_callback(build_error_callback('Change metadata failed'))

View file

@ -51,6 +51,7 @@ def common_login(user_uuid, permanent_session=True):
user.given_name, user.given_name,
user.family_name, user.family_name,
user.company, user.company,
user.location,
) )
create_lead_future.add_done_callback(build_error_callback('Create lead failed')) create_lead_future.add_done_callback(build_error_callback('Create lead failed'))
return True return True

View file

@ -4,7 +4,11 @@ from collections import namedtuple
from six import add_metaclass 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. User represents a user.
""" """

View file

@ -9,7 +9,8 @@ class EndpointsCommonDataPreOCIModel(EndpointsCommonDataInterface):
return None return None
return User(uuid=user.uuid, username=user.username, email=user.email, 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): def get_namespace_uuid(self, namespace_name):
user = model.user.get_namespace_user(namespace_name) user = model.user.get_namespace_user(namespace_name)

View file

@ -68,6 +68,15 @@
</div> </div>
</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"> <div style="margin-top: 20px">
<input type="submit" class="btn btn-primary" value="Save Details" <input type="submit" class="btn btn-primary" value="Save Details"
ng-disabled="!metadata.name && !metadata.company"> ng-disabled="!metadata.name && !metadata.company">
@ -76,4 +85,4 @@
No thanks</button> No thanks</button>
</div> </div>
</form> </form>
</div> </div>

View file

@ -152,6 +152,12 @@
<a class="co-modify-link" ng-click="showChangeMetadata('company', 'company name')">{{ context.viewuser.company || '(None)' }}</a> <a class="co-modify-link" ng-click="showChangeMetadata('company', 'company name')">{{ context.viewuser.company || '(None)' }}</a>
</td> </td>
</tr> </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'"> <tr quay-show="Config.AUTHENTICATION_TYPE == 'Database'">
<td>Password:</td> <td>Password:</td>
<td> <td>

Binary file not shown.

View file

@ -39,7 +39,7 @@ class _MarketoAnalyticsClient(object):
self._munchkin_private_key = munchkin_private_key self._munchkin_private_key = munchkin_private_key
self._lead_source = lead_source 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 = {} metadata = {}
if given_name: if given_name:
metadata['firstName'] = given_name metadata['firstName'] = given_name
@ -50,9 +50,12 @@ class _MarketoAnalyticsClient(object):
if company: if company:
metadata['company'] = company metadata['company'] = company
if location:
metadata['location'] = location
return metadata 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( lead_data = dict(
email=email, email=email,
Quay_Username__c=username, Quay_Username__c=username,
@ -60,7 +63,8 @@ class _MarketoAnalyticsClient(object):
Lead_Source_Detail__c=self._lead_source, 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( self._marketo.create_update_leads(
action='createOrUpdate', action='createOrUpdate',
@ -93,8 +97,8 @@ class _MarketoAnalyticsClient(object):
lookupField='id', lookupField='id',
) )
def change_metadata(self, email, 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) lead_data = self._get_lead_metadata(given_name, family_name, company, location)
if not lead_data: if not lead_data:
return return