Merge lp:~dobey/ubuntuone-credentials/fix-cancel into lp:ubuntuone-credentials

Proposed by dobey
Status: Merged
Approved by: Alejandro J. Cura
Approved revision: 116
Merged at revision: 118
Proposed branch: lp:~dobey/ubuntuone-credentials/fix-cancel
Merge into: lp:ubuntuone-credentials
Prerequisite: lp:~dobey/ubuntuone-credentials/pkg-i18n
Diff against target: 223 lines (+36/-65)
5 files modified
debian/libubuntuoneauth-2.0-0.symbols (+1/-0)
libubuntuoneauth/keyring.cpp (+29/-44)
libubuntuoneauth/keyring.h (+4/-1)
libubuntuoneauth/ssoservice.cpp (+1/-1)
online-accounts-provider/NewAccount.qml (+1/-19)
To merge this branch: bzr merge lp:~dobey/ubuntuone-credentials/fix-cancel
Reviewer Review Type Date Requested Status
Alberto Mardegan (community) Approve
Alejandro J. Cura (community) Approve
PS Jenkins bot continuous-integration Needs Fixing
Review via email: mp+230540@code.launchpad.net

This proposal supersedes a proposal from 2014-07-30.

Commit message

Don't call sync so much.
Don't call resetUI on success or cancel, to avoid popping the keyboard.
Set the displayName of the account internally.
Do not set the display name, or enable or sync the account, in the qml.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
Alejandro J. Cura (alecu) wrote : Posted in a previous version of this proposal

Looks fine, seems to work better on the phone.

review: Approve
Revision history for this message
Alejandro J. Cura (alecu) : Posted in a previous version of this proposal
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
Alejandro J. Cura (alecu) wrote : Posted in a previous version of this proposal

After testing on the device, I can confirm that this branch fixes the cancel button, and fixes the creation of empty accounts. Those are very good and awesome news. Great work!

Unfortunately, this branch also breaks the login flow, so I think we cannot land it as is. We'll find someone to take a look at this next week while dobey is on vacations.

review: Needs Fixing
Revision history for this message
Alberto Mardegan (mardy) wrote : Posted in a previous version of this proposal

I found out what's wrong when the plugin is called from an application (such as the dash): the sync() method is called too early.
It should be called only once, but only when the plugin has finished writing stuff into the account. While this branch improves things by reducing the number of times sync() is being called, it doesn't call sync after _account->setCredentialsId(id) has been called. This results in the account being created with a "credentialsId" field set to 0, and therefore there's no link between the account and the SignOn::Identity objects.

review: Needs Fixing
Revision history for this message
dobey (dobey) wrote : Posted in a previous version of this proposal

> I found out what's wrong when the plugin is called from an application (such
> as the dash): the sync() method is called too early.
> It should be called only once, but only when the plugin has finished writing
> stuff into the account. While this branch improves things by reducing the
> number of times sync() is being called, it doesn't call sync after
> _account->setCredentialsId(id) has been called. This results in the account
> being created with a "credentialsId" field set to 0, and therefore there's no
> link between the account and the SignOn::Identity objects.

Actually, sync() is being called at the end, and only once, already in this branch. The call to sync() is made in NewAccount.qml in the handleSuccess() function, after the display name is updated. Adding another sync() call back to keyring.cpp in handleCredentialsStored() is resulting again in the multiple broken accounts being created, when testing on my phone.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alejandro J. Cura (alecu) wrote :

I've just tested the debs from this branch on the device, works wonderfully.
- login and register from Online Accounts works
- login and register when trying to install an app works
- login and register when trying to purchase an app in staging works (but after this, completing the purchase is blocked by LP: #1355173)

The only issue is that U1 accounts now always show up as "grayed out", but it doesn't seem like a problem attributable to this branch.

big +1, great work.

review: Approve
117. By dobey

Enable the main account first.
Loop through all services and enable them when adding the credentials.

Revision history for this message
Alberto Mardegan (mardy) wrote :

I didn't test it, but code-wise looks OK.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/libubuntuoneauth-2.0-0.symbols'
2--- debian/libubuntuoneauth-2.0-0.symbols 2014-01-16 17:57:14 +0000
3+++ debian/libubuntuoneauth-2.0-0.symbols 2014-08-13 16:11:15 +0000
4@@ -111,6 +111,7 @@
5 (c++)"UbuntuOne::Token::~Token()@Base" 13.08
6 (c++)"UbuntuOne::Token::~Token()@Base" 13.08
7 (c++)"UbuntuOne::Keyring::storeToken(UbuntuOne::Token)@Base" 13.08
8+ (c++)"UbuntuOne::Keyring::storeToken(UbuntuOne::Token, QString const&)@Base" 14.04+14.10.20140812
9 (c++)"UbuntuOne::Keyring::tokenFound(UbuntuOne::Token const&)@Base" 13.08
10 (c++)"UbuntuOne::Keyring::deleteToken()@Base" 13.08
11 (c++)"UbuntuOne::Keyring::handleError(SignOn::Error const&)@Base" 13.08
12
13=== modified file 'libubuntuoneauth/keyring.cpp'
14--- libubuntuoneauth/keyring.cpp 2014-04-15 15:29:51 +0000
15+++ libubuntuoneauth/keyring.cpp 2014-08-13 16:11:15 +0000
16@@ -1,5 +1,5 @@
17 /*
18- * Copyright 2013 Canonical Ltd.
19+ * Copyright 2013-2014 Canonical Ltd.
20 *
21 * This library is free software; you can redistribute it and/or
22 * modify it under the terms of version 3 of the GNU Lesser General Public
23@@ -35,6 +35,7 @@
24 : QObject(parent),
25 _manager()
26 {
27+ _account = nullptr;
28 }
29
30 void Keyring::handleError(const SignOn::Error &error)
31@@ -103,67 +104,51 @@
32 {
33 QString _acctName("ubuntuone");
34 AccountIdList _ids = _manager.accountList(_acctName);
35- Account *account;
36-
37- if (_ids.length() > 0) {
38- if (_ids.length() > 1) {
39- qDebug() << "handleCredentialsStored(): Found '" << _ids.length() << "' accounts. Using first.";
40- }
41- account = _manager.account(_ids[0]);
42- qDebug() << "handleCredentialsStored(): Using Ubuntu One account '" << _ids[0] << "'.";
43- account->selectService();
44- account->setCredentialsId(id);
45-
46- ServiceList services = account->services(_acctName);
47- if (services.length() > 0) {
48- account->selectService(services[0]);
49- } else {
50- QString errMsg("Unable to enable 'ubuntuone' service.");
51- emit keyringError(errMsg);
52- }
53- account->setEnabled(true);
54- account->sync();
55- emit tokenStored();
56- return;
57+
58+ _account->selectService();
59+ _account->setCredentialsId(id);
60+
61+ for (auto service: _account->services()) {
62+ _account->selectService(service);
63+ _account->setEnabled(true);
64 }
65- emit keyringError(QStringLiteral("Could not sync credentials ID."));
66+ _account->sync();
67+ emit tokenStored();
68 }
69
70 void Keyring::storeToken(Token token)
71 {
72+ storeToken(token, "");
73+ }
74+
75+ void Keyring::storeToken(Token token, const QString& displayName)
76+ {
77 QString _acctName("ubuntuone");
78 AccountIdList _ids = _manager.accountList(_acctName);
79 Identity *identity = NULL;
80- Account *account = NULL;
81
82 if (_ids.length() > 0) {
83 if (_ids.length() > 1) {
84 qDebug() << "storeToken(): Found '" << _ids.length() << "' accounts. Using first.";
85 }
86- account = _manager.account(_ids[0]);
87+ _account = _manager.account(_ids[0]);
88 qDebug() << "storeToken(): Using Ubuntu One account '" << _ids[0] << "'.";
89 } else {
90 qDebug() << "in storeToken(): no accounts found in accountList, creating new";
91- account = _manager.createAccount(_acctName);
92-
93- ServiceList services = account->services(_acctName);
94- if (services.length() > 0) {
95- account->selectService(services[0]);
96- } else {
97- QString errMsg("Unable to enable 'ubuntuone' service.");
98- emit keyringError(errMsg);
99- }
100-
101- account->setEnabled(true);
102- account->sync();
103- }
104-
105- if(account->credentialsId() == 0){
106- qDebug() << "storeToken() : creating new Identity for account " << account->id() ;
107+ _account = _manager.createAccount(_acctName);
108+ }
109+ _account->setEnabled(true);
110+
111+ if (!displayName.isEmpty()) {
112+ _account->setDisplayName(displayName);
113+ }
114+
115+ if(_account->credentialsId() == 0) {
116+ qDebug() << "storeToken() : creating new Identity for account " << _account->id() ;
117 identity = Identity::newIdentity();
118- }else{
119+ } else {
120 qDebug() << "storeToken(): identity found.";
121- identity = Identity::existingIdentity(account->credentialsId());
122+ identity = Identity::existingIdentity(_account->credentialsId());
123 }
124
125 Q_ASSERT(identity != NULL);
126
127=== modified file 'libubuntuoneauth/keyring.h'
128--- libubuntuoneauth/keyring.h 2013-08-20 21:15:53 +0000
129+++ libubuntuoneauth/keyring.h 2014-08-13 16:11:15 +0000
130@@ -1,5 +1,5 @@
131 /*
132- * Copyright 2013 Canonical Ltd.
133+ * Copyright 2013-2014 Canonical Ltd.
134 *
135 * This library is free software; you can redistribute it and/or
136 * modify it under the terms of version 3 of the GNU Lesser General Public
137@@ -18,6 +18,7 @@
138 #ifndef _U1_KEYRING_H_
139 #define _U1_KEYRING_H_
140
141+#include <Accounts/Account>
142 #include <Accounts/Manager>
143 #include <SignOn/Identity>
144
145@@ -36,6 +37,7 @@
146
147 void findToken();
148 void storeToken(Token token);
149+ void storeToken(Token token, const QString& displayName);
150 void deleteToken();
151
152 Q_SIGNALS:
153@@ -54,6 +56,7 @@
154
155 private:
156 Accounts::Manager _manager;
157+ Accounts::Account *_account;
158 };
159
160 } /* namespace UbuntuOne */
161
162=== modified file 'libubuntuoneauth/ssoservice.cpp'
163--- libubuntuoneauth/ssoservice.cpp 2014-07-09 20:22:51 +0000
164+++ libubuntuoneauth/ssoservice.cpp 2014-08-13 16:11:15 +0000
165@@ -146,7 +146,7 @@
166 {
167 Token realToken = Token(token.token_key(), token.token_secret(),
168 token.consumer_key(), token.consumer_secret());
169- _keyring->storeToken(realToken);
170+ _keyring->storeToken(realToken, _tempEmail);
171 }
172
173 void SSOService::accountPinged(QNetworkReply*)
174
175=== modified file 'online-accounts-provider/NewAccount.qml'
176--- online-accounts-provider/NewAccount.qml 2014-08-01 19:53:01 +0000
177+++ online-accounts-provider/NewAccount.qml 2014-08-13 16:11:15 +0000
178@@ -41,8 +41,6 @@
179
180 Component.onCompleted: {
181 resetUI();
182- enableAccount();
183- __account.sync()
184 }
185
186 Label {
187@@ -181,7 +179,6 @@
188 console.debug("Removing account ID: " + account.accountId);
189 account.removed.connect(finished);
190 account.remove(Account.RemoveCredentials);
191- resetUI();
192 }
193
194 /* processForm uses a timer to delay calling u1credservice, which can
195@@ -222,11 +219,7 @@
196 function handleSuccess() {
197 loadingOverlay.visible = false;
198 errorLabel.visible = false;
199- account.updateDisplayName(emailTextField.text);
200- account.updateEnabled(true);
201- account.synced.connect(main.finished);
202- account.sync();
203- resetUI();
204+ main.finished();
205 }
206
207 function showTwoFactorUI() {
208@@ -273,15 +266,4 @@
209 includeDisabled: true
210 account: __account.objectHandle
211 }
212-
213- function enableAccount() {
214- for (var i = 0; i < accountServices.count; i++) {
215- var accountServiceHandle = accountServices.get(i, "accountService")
216- var accountService = accountServiceComponent.createObject(null,
217- { "objectHandle": accountServiceHandle })
218- accountService.updateServiceEnabled(true)
219- accountService.destroy(1000)
220- }
221- }
222-
223 }

Subscribers

People subscribed via source and target branches

to all changes: