Merge lp:~mhall119/loco-team-portal/fixes-639772 into lp:loco-team-portal

Proposed by Michael Hall on 2010-12-21
Status: Merged
Approved by: Chris Johnston on 2011-01-23
Approved revision: 345
Merged at revision: 366
Proposed branch: lp:~mhall119/loco-team-portal/fixes-639772
Merge into: lp:loco-team-portal
Diff against target: 99 lines (+55/-3)
4 files modified
loco_directory/common/launchpad.py (+34/-0)
loco_directory/teams/management/commands/lpupdate.py (+6/-3)
loco_directory/teams/management/commands/update-openids.py (+13/-0)
loco_directory/userprofiles/models.py (+2/-0)
To merge this branch: bzr merge lp:~mhall119/loco-team-portal/fixes-639772
Reviewer Review Type Date Requested Status
LoCo Team Portal Developers 2010-12-21 Pending
Review via email: mp+44311@code.launchpad.net

Description of the change

Adds an API for setting open ids from launchpad, as well as a new update-openids management command that will do this for all users in the system.

To post a comment you must log in.
Ronnie (ronnie.vd.c) wrote :

The command runs here without error

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'loco_directory/common/launchpad.py'
2--- loco_directory/common/launchpad.py 2010-08-24 15:24:40 +0000
3+++ loco_directory/common/launchpad.py 2010-12-21 04:06:49 +0000
4@@ -96,3 +96,37 @@
5 except:
6 pass
7 return timezone
8+
9+
10+def get_permanent_openid_from_username(username):
11+ import urllib
12+ from openid.consumer.discover import OpenIDServiceEndpoint
13+ url = "https://launchpad.net/~%s" % username
14+ f = urllib.urlopen(url)
15+ html = f.read()
16+ services = OpenIDServiceEndpoint().fromHTML(url, html)
17+ if services is not None and len(services) > 0:
18+ return services[0]
19+ else:
20+ return None
21+ # ... or use this line if you want the Ubuntu SSO OpenID:
22+ # return services[0].local_id.replace('launchpad.net', 'ubuntu.com')
23+
24+def set_user_openid(user, force=False):
25+ from django_openid_auth.models import UserOpenID
26+ openids = UserOpenID.objects.filter(user=user)
27+ if len(openids) == 0 or force:
28+ if len(openids) == 0:
29+ openid_assoc = UserOpenID(user=user)
30+ else :
31+ openid_assoc = openids[0]
32+ openid = get_permanent_openid_from_username(user.username)
33+ if openid is not None:
34+ if force:
35+ UserOpenID.objects.filter(claimed_id=openid.local_id).delete()
36+ openid_assoc.claimed_id = openid.local_id
37+ openid_assoc.display_id = openid.local_id
38+ openid_assoc.save()
39+ return True
40+ return False
41+
42
43=== modified file 'loco_directory/teams/management/commands/lpupdate.py'
44--- loco_directory/teams/management/commands/lpupdate.py 2010-09-30 11:56:43 +0000
45+++ loco_directory/teams/management/commands/lpupdate.py 2010-12-21 04:06:49 +0000
46@@ -5,7 +5,7 @@
47 from common import launchpad
48 from teams import models
49 from django.contrib.auth.models import Group
50-from userprofiles.models import create_profile
51+from userprofiles.models import UserProfile, create_profile
52
53 from datetime import datetime
54 import sys
55@@ -24,8 +24,11 @@
56 ld_admin_set = set(ld_admin_names.keys())
57 lp_admin_set = set(lp_admin_names.keys())
58 for admin_name in ld_admin_set.difference(lp_admin_set):
59- admin = ld_team.admin_profiles.get(user__username=admin_name)
60- admin.delete()
61+ try:
62+ admin = ld_team.admin_profiles.get(user__username=admin_name)
63+ admin.delete()
64+ except UserProfile.DoesNotExist:
65+ pass
66 for admin_name in lp_admin_set.difference(ld_admin_set):
67 admin = create_profile(admin_name)
68 admin.realname = lp_admin_names[admin_name]
69
70=== added file 'loco_directory/teams/management/commands/update-openids.py'
71--- loco_directory/teams/management/commands/update-openids.py 1970-01-01 00:00:00 +0000
72+++ loco_directory/teams/management/commands/update-openids.py 2010-12-21 04:06:49 +0000
73@@ -0,0 +1,13 @@
74+#!/usr/bin/python
75+
76+from django.core.management.base import NoArgsCommand
77+
78+from common import launchpad
79+from django.contrib.auth.models import User
80+
81+class Command(NoArgsCommand):
82+ help = "Set openid identity urls from launchpad"
83+
84+ def handle_noargs(self, **options):
85+ for user in User.objects.all():
86+ launchpad.set_user_openid(user, force=True)
87
88=== modified file 'loco_directory/userprofiles/models.py'
89--- loco_directory/userprofiles/models.py 2010-11-27 04:12:57 +0000
90+++ loco_directory/userprofiles/models.py 2010-12-21 04:06:49 +0000
91@@ -71,6 +71,8 @@
92 user, created = auth_models.User.objects.get_or_create(username=username)
93 if created:
94 user.save()
95+ from common import launchpad
96+ launchpad.set_user_openid(user)
97 profile, created = UserProfile.objects.get_or_create(user=user)
98 if created:
99 # set real name as username for now,

Subscribers

People subscribed via source and target branches