From ec52ec1c78845040a5355bddc5b363a630612be2 Mon Sep 17 00:00:00 2001 From: Ilya Shakhat Date: Fri, 16 Jan 2015 17:41:38 +0300 Subject: [PATCH] Support for alternative user ids Do not restrict on launchpad id only. Also allow github_id (for complimentary projects) and ldap_id (for OpenDayLight community) Closes bug 1411678 Change-Id: Ia811092cb6754e9d1dc28b0f3b55ccb1d04809b9 --- etc/default_data.json | 11 +++++++++++ etc/default_data.schema.json | 8 +++++++- .../templates/_macros/user_profile.html | 6 ++++++ stackalytics/processor/normalizer.py | 4 +++- stackalytics/processor/record_processor.py | 4 ++-- stackalytics/processor/user_processor.py | 19 +++++++++++++++++-- tests/unit/test_config_files.py | 6 ++++-- 7 files changed, 50 insertions(+), 8 deletions(-) diff --git a/etc/default_data.json b/etc/default_data.json index 793d70a22..73d1e88e5 100644 --- a/etc/default_data.json +++ b/etc/default_data.json @@ -1623,6 +1623,17 @@ "user_name": "Cindy Pallares", "emails": ["cindy.pallaresq@gmail.com", "cpallares@redhat.com", "cpallare@redhat.com"] }, + { + "github_id": "cpuguy83", + "companies": [ + { + "company_name": "Docker", + "end_date": null + } + ], + "user_name": "Brian Goff", + "emails": ["cpuguy83@gmail.com"] + }, { "launchpad_id": "craige", "companies": [ diff --git a/etc/default_data.schema.json b/etc/default_data.schema.json index fe0050443..785709a00 100644 --- a/etc/default_data.schema.json +++ b/etc/default_data.schema.json @@ -12,9 +12,15 @@ "type": "string", "pattern": "^[a-z\\d\\.-]+$" }, + "github_id": { + "type": "string" + }, "gerrit_id": { "type": "string" }, + "ldap_id": { + "type": "string" + }, "user_name": { "type": "string" }, @@ -44,7 +50,7 @@ "minItems": 1 } }, - "required": ["launchpad_id", "user_name", "emails"], + "required": ["user_name", "emails"], "additionalProperties": false } }, diff --git a/stackalytics/dashboard/templates/_macros/user_profile.html b/stackalytics/dashboard/templates/_macros/user_profile.html index 70fe1c20a..14bea575b 100644 --- a/stackalytics/dashboard/templates/_macros/user_profile.html +++ b/stackalytics/dashboard/templates/_macros/user_profile.html @@ -35,6 +35,12 @@ {%if gerrit_id %}
Gerrit: ${gerrit_id}
{%/if%} + {%if github_id %} +
Github: ${github_id}
+ {%/if%} + {%if ldap_id %} +
LDAP: ${ldap_id}
+ {%/if%} {%if core %}
Core in: {%each( index, value ) core %} diff --git a/stackalytics/processor/normalizer.py b/stackalytics/processor/normalizer.py index 7a8615d14..37ea16784 100644 --- a/stackalytics/processor/normalizer.py +++ b/stackalytics/processor/normalizer.py @@ -40,7 +40,9 @@ def _normalize_user(user): user['user_id'] = user_processor.make_user_id( launchpad_id=user.get('launchpad_id'), emails=user.get('emails'), - gerrit_id=user.get('gerrit_id')) + gerrit_id=user.get('gerrit_id'), + github_id=user.get('user_id'), + ldap_id=user.get('ldap_id')) def _normalize_users(users): diff --git a/stackalytics/processor/record_processor.py b/stackalytics/processor/record_processor.py index e54198e1d..47dd1481b 100644 --- a/stackalytics/processor/record_processor.py +++ b/stackalytics/processor/record_processor.py @@ -180,8 +180,8 @@ class RecordProcessor(object): merged_user = {} # merged user profile # collect ordinary fields - for key in ['seq', 'user_name', 'user_id', 'gerrit_id', - 'launchpad_id', 'companies', 'static']: + for key in ['seq', 'user_name', 'user_id', 'gerrit_id', 'github_id', + 'launchpad_id', 'companies', 'static', 'ldap_id']: value = next((v.get(key) for v in user_profiles if v.get(key)), None) if value: diff --git a/stackalytics/processor/user_processor.py b/stackalytics/processor/user_processor.py index 0110d3b5f..99e87281f 100644 --- a/stackalytics/processor/user_processor.py +++ b/stackalytics/processor/user_processor.py @@ -20,13 +20,17 @@ LOG = logging.getLogger(__name__) def make_user_id(emails=None, launchpad_id=None, gerrit_id=None, - member_id=None): + member_id=None, github_id=None, ldap_id=None): if launchpad_id or emails: return launchpad_id or emails[0] if gerrit_id: return 'gerrit:%s' % gerrit_id if member_id: return 'member:%s' % member_id + if github_id: + return 'github:%s' % github_id + if ldap_id: + return 'ldap:%s' % ldap_id def store_user(runtime_storage_inst, user): @@ -54,16 +58,27 @@ def store_user(runtime_storage_inst, user): if user.get('gerrit_id'): runtime_storage_inst.set_by_key('user:gerrit:%s' % user['gerrit_id'], user) + if user.get('github_id'): + runtime_storage_inst.set_by_key('user:github:%s' % user['github_id'], + user) + if user.get('ldap_id'): + runtime_storage_inst.set_by_key('user:ldap:%s' % user['ldap_id'], + user) for email in user.get('emails') or []: runtime_storage_inst.set_by_key('user:%s' % email, user) def load_user(runtime_storage_inst, seq=None, user_id=None, email=None, - launchpad_id=None, gerrit_id=None, member_id=None): + launchpad_id=None, gerrit_id=None, member_id=None, + github_id=None, ldap_id=None): if gerrit_id: key = 'gerrit:%s' % gerrit_id elif member_id: key = 'member:%s' % member_id + elif github_id: + key = 'github:%s' % github_id + elif ldap_id: + key = 'ldap:%s' % ldap_id else: key = seq or user_id or launchpad_id or email if key: diff --git a/tests/unit/test_config_files.py b/tests/unit/test_config_files.py index e5de38608..42ba07242 100644 --- a/tests/unit/test_config_files.py +++ b/tests/unit/test_config_files.py @@ -80,8 +80,10 @@ class TestConfigFiles(testtools.TestCase): def _verify_users_in_alphabetical_order(self, file_name): users = self._read_file(file_name)['users'] self._verify_ordering( - users, key=lambda x: x['launchpad_id'], - msg='List of users should be ordered by launchpad id') + users, key=lambda x: (x.get('launchpad_id') or x.get('ldap_id') or + x.get('github_id')), + msg='List of users should be ordered by launchpad id or ldap id ' + 'or github id') def test_users_in_alphabetical_order(self): self._verify_users_in_alphabetical_order('etc/default_data.json')