Merge lp:~stefanor/ibid/accounts-382464 into lp:~ibid-core/ibid/old-trunk-pack-0.92

Proposed by Stefano Rivera
Status: Merged
Approved by: Stefano Rivera
Approved revision: 671
Merged at revision: 683
Proposed branch: lp:~stefanor/ibid/accounts-382464
Merge into: lp:~ibid-core/ibid/old-trunk-pack-0.92
Diff against target: None lines
To merge this branch: bzr merge lp:~stefanor/ibid/accounts-382464
Reviewer Review Type Date Requested Status
Michael Gorven Approve
Jonathan Hitchcock Approve
Review via email: mp+7718@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Jonathan Hitchcock (vhata) :
review: Approve
Revision history for this message
Michael Gorven (mgorven) wrote :

 review approve

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ibid/plugins/auth.py'
2--- ibid/plugins/auth.py 2009-05-31 07:51:10 +0000
3+++ ibid/plugins/auth.py 2009-06-20 15:26:47 +0000
4@@ -28,7 +28,7 @@
5 if not ibid.auth.authenticate(event):
6 event.complain = 'notauthed'
7 return
8- account = event.session.query(Account).filter_by(id=event.account).first()
9+ account = event.session.query(Account).get(event.account)
10
11 else:
12 if not auth_responses(event, 'admin'):
13@@ -122,7 +122,7 @@
14 if not event.account:
15 event.addresponse(u"I don't know who you are")
16 return
17- account = event.session.query(Account).filter_by(id=event.account).first()
18+ account = event.session.query(Account).get(event.account)
19 else:
20 if not auth_responses(event, u'accounts'):
21 return
22
23=== modified file 'ibid/plugins/identity.py'
24--- ibid/plugins/identity.py 2009-05-05 07:58:29 +0000
25+++ ibid/plugins/identity.py 2009-06-20 17:12:43 +0000
26@@ -31,7 +31,7 @@
27 if ibid.auth.authenticate(event) and ibid.auth.authorise(event, 'accounts'):
28 admin = True
29 else:
30- account = event.session.query(Account).filter_by(id=event.account).first()
31+ account = event.session.query(Account).get(event.account)
32 event.addresponse(u'You already have an account called "%s"', account.username)
33 return
34
35@@ -61,7 +61,7 @@
36 log.info(u"Attached identity %s (%s on %s) to account %s (%s)",
37 identity.id, identity.identity, identity.source, account.id, account.username)
38 else:
39- identity = event.session.query(Identity).filter_by(id=event.identity).first()
40+ identity = event.session.query(Identity).get(event.identity)
41 identity.account_id = account.id
42 event.session.save_or_update(identity)
43 event.session.commit()
44@@ -77,7 +77,7 @@
45
46 if own:
47 if event.account:
48- account = event.session.query(Account).filter_by(id=event.account).first()
49+ account = event.session.query(Account).get(event.account)
50 else:
51 event.addresponse(u"You don't have an account")
52 return
53@@ -106,7 +106,7 @@
54
55 if own:
56 if event.account:
57- account = event.session.query(Account).filter_by(id=event.account).first()
58+ account = event.session.query(Account).get(event.account)
59 else:
60 event.addresponse(u"You don't have an account")
61 return
62@@ -148,36 +148,45 @@
63 def identity(self, event, username, identity, source):
64 admin = False
65 identity = identity.replace(' ', '')
66+ reverse_attach = False
67
68 if username.upper() == 'I':
69 if event.account:
70- account = event.session.query(Account).filter_by(id=event.account).first()
71+ account = event.session.query(Account).get(event.account)
72 else:
73- username = event.sender['id']
74-
75- account = event.session.query(Account).filter_by(username=username).first()
76-
77+ account = event.session.query(Account) \
78+ .join(Identity.account) \
79+ .filter(func.lower(Identity.identity) == identity.lower()) \
80+ .filter(func.lower(Identity.source) == source.lower()).first()
81+
82 if account:
83- event.addresponse(u'I tried to create the account %s for you, but it already exists. '
84- u"Please use 'create account <name>'", username)
85- return
86-
87- account = Account(username)
88- event.session.save_or_update(account)
89-
90- currentidentity = event.session.query(Identity).filter_by(id=event.identity).first()
91- currentidentity.account_id = account.id
92- event.session.save_or_update(currentidentity)
93-
94- identify_cache.clear()
95-
96- event.addresponse(u"I've created the account %s for you", username)
97-
98- event.session.commit()
99- log.info(u"Created account %s (%s) by %s/%s (%s)",
100- account.id, account.username, event.account, event.identity, event.sender['connection'])
101- log.info(u"Attached identity %s (%s on %s) to account %s (%s)",
102- currentidentity.id, currentidentity.identity, currentidentity.source, account.id, account.username)
103+ reverse_attach = True
104+ else:
105+ username = event.sender['id']
106+
107+ account = event.session.query(Account).filter_by(username=username).first()
108+
109+ if account:
110+ event.addresponse(u'I tried to create the account %s for you, but it already exists. '
111+ u"Please use 'create account <name>'", username)
112+ return
113+
114+ account = Account(username)
115+ event.session.save_or_update(account)
116+
117+ currentidentity = event.session.query(Identity).get(event.identity)
118+ currentidentity.account_id = account.id
119+ event.session.save_or_update(currentidentity)
120+
121+ identify_cache.clear()
122+
123+ event.addresponse(u"I've created the account %s for you", username)
124+
125+ event.session.commit()
126+ log.info(u"Created account %s (%s) by %s/%s (%s)",
127+ account.id, account.username, event.account, event.identity, event.sender['connection'])
128+ log.info(u"Attached identity %s (%s on %s) to account %s (%s)",
129+ currentidentity.id, currentidentity.identity, currentidentity.source, account.id, account.username)
130
131 else:
132 if not auth_responses(event, 'accounts'):
133@@ -188,9 +197,12 @@
134 event.addresponse(u"I don't know who %s is", username)
135 return
136
137- ident = event.session.query(Identity) \
138- .filter(func.lower(Identity.identity) == identity.lower()) \
139- .filter(func.lower(Identity.source) == source.lower()).first()
140+ if reverse_attach:
141+ ident = event.session.query(Identity).get(event.identity)
142+ else:
143+ ident = event.session.query(Identity) \
144+ .filter(func.lower(Identity.identity) == identity.lower()) \
145+ .filter(func.lower(Identity.source) == source.lower()).first()
146 if ident and ident.account:
147 event.addresponse(u'This identity is already attached to account %s',
148 ident.account.username)
149@@ -204,10 +216,20 @@
150
151 if not admin:
152 token = ''.join([choice(chars) for i in xrange(16)])
153- self.tokens[token] = (account.id, identity, source)
154- response = {'reply': u'Please send me this message from %s on %s: %s' % (identity, source, token)}
155- if event.public:
156- response['target'] = event.sender['id']
157+ if reverse_attach:
158+ self.tokens[token] = (account.id, ident.identity, ident.source)
159+ response = {
160+ 'reply': u'Please send me this message from %s on %s: %s' % (ident.identity, ident.source, token),
161+ 'target': identity,
162+ 'source': source,
163+ }
164+ event.addresponse(True)
165+ else:
166+ self.tokens[token] = (account.id, identity, source)
167+ response = {'reply': u'Please send me this message from %s on %s: %s' % (identity, source, token)}
168+ if event.public:
169+ response['target'] = event.sender['id']
170+ event.addresponse(True)
171 event.addresponse(response)
172 log.info(u"Sent token %s to %s/%s (%s)",
173 token, event.account, event.identity, event.sender['connection'])
174@@ -296,7 +318,7 @@
175 if not event.account:
176 event.addresponse(u"I don't know who you are")
177 return
178- account = event.session.query(Account).filter_by(id=event.account).first()
179+ account = event.session.query(Account).get(event.account)
180 if not account:
181 event.addresponse(u"%s doesn't exist. Please use 'add account' first", username)
182 return
183
184=== modified file 'ibid/source/telnet.py'
185--- ibid/source/telnet.py 2009-02-23 20:29:44 +0000
186+++ ibid/source/telnet.py 2009-06-20 15:57:43 +0000
187@@ -6,6 +6,7 @@
188
189 import ibid
190 from ibid.source import IbidSourceFactory
191+from ibid.config import IntOption
192 from ibid.event import Event
193
194 class TelnetProtocol(telnet.StatefulTelnetProtocol):
195@@ -45,7 +46,7 @@
196 class SourceFactory(protocol.ServerFactory, IbidSourceFactory):
197 protocol = TelnetProtocol
198
199- port = 3000
200+ port = IntOption('port', 'Port to listen on', 3000)
201
202 def __init__(self, name, *args, **kwargs):
203 #protocol.ServerFactory.__init__(self, *args, **kwargs)

Subscribers

People subscribed via source and target branches