Merge lp:~jamesh/online-accounts-api/all-services into lp:online-accounts-api

Proposed by James Henstridge
Status: Merged
Approved by: Alberto Mardegan
Approved revision: 27
Merged at revision: 23
Proposed branch: lp:~jamesh/online-accounts-api/all-services
Merge into: lp:online-accounts-api
Diff against target: 221 lines (+84/-13)
6 files modified
debian/libonline-accounts-qt1.symbols (+1/-0)
src/lib/OnlineAccounts/manager.cpp (+23/-8)
src/lib/OnlineAccounts/manager.h (+1/-0)
src/lib/OnlineAccounts/manager_p.h (+3/-2)
tests/lib/OnlineAccounts/functional_tests/functional_tests.cpp (+55/-2)
tests/lib/qml_module/tst_qml_module.cpp (+1/-1)
To merge this branch: bzr merge lp:~jamesh/online-accounts-api/all-services
Reviewer Review Type Date Requested Status
Alberto Mardegan (community) Approve
Review via email: mp+299786@code.launchpad.net

Commit message

Expose all serviceIds for each account rather than ignoring all but the first.

Description of the change

Expose all serviceIds for each account rather than ignoring all but the first.

To post a comment you must log in.
26. By James Henstridge

Update symbols file.

27. By James Henstridge

Update multiple services test to properly exercise the "any serviceId"
case.

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

Unfortunately this won't work: the D-Bus interface is built around the assumption that an application can only use a single service for each account.
I'll comment on the linked bug.

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

Let's try this.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/libonline-accounts-qt1.symbols'
2--- debian/libonline-accounts-qt1.symbols 2016-02-25 10:28:39 +0000
3+++ debian/libonline-accounts-qt1.symbols 2016-07-12 10:24:12 +0000
4@@ -98,6 +98,7 @@
5 _ZN14OnlineAccounts7Manager17availableAccountsERK7QString@Base 0.1+16.04.20160212-0ubuntu1
6 _ZN14OnlineAccounts7Manager5readyEv@Base 0.1+16.04.20160212-0ubuntu1
7 _ZN14OnlineAccounts7Manager7accountEj@Base 0.1+16.04.20160212-0ubuntu1
8+ _ZN14OnlineAccounts7Manager7accountEjRK7QString@Base 0replaceme
9 _ZN14OnlineAccounts7ManagerC1ERK7QStringP7QObject@Base 0.1+16.04.20160212-0ubuntu1
10 _ZN14OnlineAccounts7ManagerC2ERK7QStringP7QObject@Base 0.1+16.04.20160212-0ubuntu1
11 _ZN14OnlineAccounts7ManagerD0Ev@Base 0.1+16.04.20160212-0ubuntu1
12
13=== modified file 'src/lib/OnlineAccounts/manager.cpp'
14--- src/lib/OnlineAccounts/manager.cpp 2015-08-28 14:25:23 +0000
15+++ src/lib/OnlineAccounts/manager.cpp 2016-07-12 10:24:12 +0000
16@@ -83,10 +83,11 @@
17 Account *ManagerPrivate::ensureAccount(const AccountInfo &info)
18 {
19 if (Q_UNLIKELY(info.id() == 0)) return 0;
20+ if (Q_UNLIKELY(info.service().isEmpty())) return 0;
21
22- QHash<AccountId,AccountData>::iterator i = m_accounts.find(info.id());
23+ auto i = m_accounts.find({info.id(), info.service()});
24 if (i == m_accounts.end()) {
25- i = m_accounts.insert(info.id(), AccountData(info));
26+ i = m_accounts.insert({info.id(), info.service()}, AccountData(info));
27 }
28
29 AccountData &accountData = i.value();
30@@ -129,7 +130,7 @@
31 } else {
32 QList<AccountInfo> accountInfos = reply.argumentAt<0>();
33 Q_FOREACH(const AccountInfo &info, accountInfos) {
34- m_accounts.insert(info.id(), AccountData(info));
35+ m_accounts.insert({info.id(), info.service()}, AccountData(info));
36 }
37 }
38 m_getAccountsCall->deleteLater();
39@@ -153,7 +154,7 @@
40 * we remove it from our list so that we won't return it to the client
41 * anymore.
42 */
43- m_accounts.remove(info.id());
44+ m_accounts.remove({info.id(), service});
45 }
46
47 /* No need to handle the Update change type: ensureAccount already updates
48@@ -191,8 +192,7 @@
49 Q_D(Manager);
50
51 QList<Account*> result;
52- for (QHash<AccountId,AccountData>::iterator i = d->m_accounts.begin();
53- i != d->m_accounts.end(); i++) {
54+ for (auto i = d->m_accounts.begin(); i != d->m_accounts.end(); i++) {
55 AccountData &accountData = i.value();
56 if (!service.isEmpty() && accountData.info.service() != service) continue;
57
58@@ -209,10 +209,25 @@
59
60 Account *Manager::account(AccountId accountId)
61 {
62+ return account(accountId, QString());
63+}
64+
65+Account *Manager::account(AccountId accountId, const QString &serviceId)
66+{
67 Q_D(Manager);
68
69- QHash<AccountId,AccountData>::iterator i = d->m_accounts.find(accountId);
70- if (Q_UNLIKELY(i == d->m_accounts.end())) return 0;
71+ decltype(d->m_accounts)::iterator i;
72+ if (serviceId.isEmpty()) {
73+ // Any non-empty service ID will sort after the empty string
74+ i = d->m_accounts.lowerBound({accountId, QString()});
75+ if (Q_UNLIKELY(i == d->m_accounts.end() ||
76+ i.key().first != accountId)) {
77+ return 0;
78+ }
79+ } else {
80+ i = d->m_accounts.find({accountId, serviceId});
81+ if (Q_UNLIKELY(i == d->m_accounts.end())) return 0;
82+ }
83
84 AccountData &accountData = i.value();
85 if (!accountData.account) {
86
87=== modified file 'src/lib/OnlineAccounts/manager.h'
88--- src/lib/OnlineAccounts/manager.h 2015-03-04 10:01:32 +0000
89+++ src/lib/OnlineAccounts/manager.h 2016-07-12 10:24:12 +0000
90@@ -48,6 +48,7 @@
91
92 QList<Account*> availableAccounts(const QString &service = QString());
93 Account *account(AccountId accountId);
94+ Account *account(AccountId accountId, const QString &service);
95
96 PendingCall requestAccess(const QString &service,
97 const AuthenticationData &authData);
98
99=== modified file 'src/lib/OnlineAccounts/manager_p.h'
100--- src/lib/OnlineAccounts/manager_p.h 2015-03-04 10:01:32 +0000
101+++ src/lib/OnlineAccounts/manager_p.h 2016-07-12 10:24:12 +0000
102@@ -23,8 +23,9 @@
103
104 #include "manager.h"
105
106-#include <QHash>
107+#include <QMap>
108 #include <QObject>
109+#include <QPair>
110 #include <QPointer>
111 #include "account_info.h"
112 #include "dbus_interface.h"
113@@ -68,7 +69,7 @@
114 QString m_applicationId;
115 DBusInterface m_daemon;
116 QDBusPendingCallWatcher *m_getAccountsCall;
117- QHash<AccountId,AccountData> m_accounts;
118+ QMap<QPair<AccountId,QString>,AccountData> m_accounts;
119 mutable Manager *q_ptr;
120 };
121
122
123=== modified file 'tests/lib/OnlineAccounts/functional_tests/functional_tests.cpp'
124--- tests/lib/OnlineAccounts/functional_tests/functional_tests.cpp 2016-02-11 09:00:13 +0000
125+++ tests/lib/OnlineAccounts/functional_tests/functional_tests.cpp 2016-07-12 10:24:12 +0000
126@@ -87,6 +87,7 @@
127 void testAccountData_data();
128 void testAccountData();
129 void testAccountChanges();
130+ void testMultipleServices();
131 void testPendingCallWatcher();
132 void testAuthentication();
133 void testAuthenticationErrors_data();
134@@ -204,13 +205,13 @@
135 "";
136
137 QTest::newRow("access granted") <<
138- "ret = ((1, {'displayName': 'Bob'}),{'AccessToken':'GoOn'})" <<
139+ "ret = ((1, {'displayName': 'Bob', 'serviceId': 'my-service'}),{'AccessToken':'GoOn'})" <<
140 true <<
141 int(0) <<
142 "Bob" <<
143 "GoOn";
144 QTest::newRow("access granted, no wait") <<
145- "ret = ((1, {'displayName': 'Bob'}),{'AccessToken':'GoOn'})" <<
146+ "ret = ((1, {'displayName': 'Bob', 'serviceId': 'my-service'}),{'AccessToken':'GoOn'})" <<
147 false <<
148 int(0) <<
149 "Bob" <<
150@@ -429,6 +430,58 @@
151 QVERIFY(!account->isValid());
152 }
153
154+void FunctionalTests::testMultipleServices()
155+{
156+ addMockedMethod("GetAccounts", "a{sv}", "a(ua{sv})",
157+ "ret = ["
158+ "(1, {"
159+ " 'displayName': 'One',"
160+ " 'serviceId': 'service2',"
161+ " 'authMethod': 1,"
162+ "}),"
163+ "(2, {"
164+ " 'displayName': 'Two',"
165+ " 'serviceId': 'service1',"
166+ " 'authMethod': 1,"
167+ "}),"
168+ "(2, {"
169+ " 'displayName': 'Two',"
170+ " 'serviceId': 'service2',"
171+ " 'authMethod': 1,"
172+ "}),"
173+ "(4, {"
174+ " 'displayName': 'Three',"
175+ " 'serviceId': 'service1',"
176+ " 'authMethod': 1,"
177+ "}),"
178+ "]");
179+ OnlineAccounts::Manager manager("my-app");
180+ manager.waitForReady();
181+
182+ // All account services are available, including both from account #2
183+ auto accounts = manager.availableAccounts();
184+ QCOMPARE(accounts.count(), 4);
185+
186+ // Picks the first known service for the given account ID.
187+ OnlineAccounts::Account *account = manager.account(2);
188+ QVERIFY(account);
189+ QVERIFY(account->isValid());
190+ QCOMPARE(account->id(), OnlineAccounts::AccountId(2));
191+ QCOMPARE(account->displayName(), QString("Two"));
192+ QCOMPARE(account->serviceId(), QString("service1"));
193+
194+ account = manager.account(2, "service2");
195+ QVERIFY(account);
196+ QCOMPARE(account->id(), OnlineAccounts::AccountId(2));
197+ QCOMPARE(account->serviceId(), QString("service2"));
198+
199+ account = manager.account(2, "service3");
200+ QVERIFY(account == nullptr);
201+
202+ account = manager.account(3);
203+ QVERIFY(account == nullptr);
204+}
205+
206 void FunctionalTests::testAuthentication()
207 {
208 addMockedMethod("GetAccounts", "a{sv}", "a(ua{sv})",
209
210=== modified file 'tests/lib/qml_module/tst_qml_module.cpp'
211--- tests/lib/qml_module/tst_qml_module.cpp 2016-01-18 12:23:07 +0000
212+++ tests/lib/qml_module/tst_qml_module.cpp 2016-07-12 10:24:12 +0000
213@@ -383,7 +383,7 @@
214 authenticationData.clear();
215 authenticationData.insert("AccessToken", "GoOn");
216 QTest::newRow("access granted") <<
217- "ret = ((1, {'displayName': 'Bob'}),{'AccessToken':'GoOn'})" <<
218+ "ret = ((1, {'displayName': 'Bob', 'serviceId': 'bar'}),{'AccessToken':'GoOn'})" <<
219 accessReply <<
220 authenticationData;
221 }

Subscribers

People subscribed via source and target branches