Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1604 from Mte90/Mte90/1153120-rebase
Browse files Browse the repository at this point in the history
[bug 1153120] show linkedin username or old url
  • Loading branch information
akatsoulas committed Feb 27, 2017
2 parents ab7d22e + 0bcf7dc commit 77c0dc1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
9 changes: 9 additions & 0 deletions mozillians/phonebook/tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from mozillians.common.tests import TestCase
from mozillians.phonebook.validators import (validate_email, validate_twitter,
validate_linkedin,
validate_username_not_url,
validate_phone_number)

Expand All @@ -19,6 +20,14 @@ def test_twitter_username_parsing(self):
username = '@ValidName'
eq_('ValidName', validate_twitter(username))

def test_linkedin_with_old_url(self):
url = 'https://www.linkedin.com/profile/view?id=409777777'
eq_(url, validate_linkedin(url))

def test_linkedin_with_nick(self):
username = 'username'
eq_(username, validate_linkedin(username))

def test_username_not_url_with_username(self):
username = 'someusername'
eq_(username, validate_username_not_url(username))
Expand Down
10 changes: 10 additions & 0 deletions mozillians/phonebook/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ def validate_twitter(username):
return username


def validate_linkedin(url):
"""Return the linkedin username from the url or the link"""

if 'view?id' not in url:
nick = url.rsplit('/', 1)[-1]
return nick

return url


def validate_username(username):
"""Validate username.
Expand Down
9 changes: 6 additions & 3 deletions mozillians/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
Skill, SkillAlias)
from mozillians.phonebook.validators import (validate_email, validate_twitter,
validate_website, validate_username_not_url,
validate_phone_number)
validate_phone_number, validate_linkedin)
from mozillians.users.es import UserProfileMappingType
from mozillians.users import get_languages_for_locale
from mozillians.users.managers import (EMPLOYEES,
Expand Down Expand Up @@ -805,8 +805,8 @@ class ExternalAccount(models.Model):
TYPE_REMO: {'name': 'Mozilla Reps', 'url': 'https://reps.mozilla.org/u/{identifier}/',
'validator': validate_username_not_url},
TYPE_LINKEDIN: {'name': 'LinkedIn',
'url': '',
'validator': validate_website},
'url': 'https://www.linkedin.com/in/{identifier}/',
'validator': validate_linkedin},
TYPE_JABBER: {'name': 'XMPP/Jabber',
'url': '',
'validator': validate_email},
Expand Down Expand Up @@ -853,6 +853,9 @@ class Meta:

def get_identifier_url(self):
url = self.ACCOUNT_TYPES[self.type]['url'].format(identifier=urlquote(self.identifier))
if self.type == 'LINKEDIN' and '://' in self.identifier:
return self.identifier

return iri_to_uri(url)

def unique_error_message(self, model_class, unique_check):
Expand Down

0 comments on commit 77c0dc1

Please sign in to comment.