Merge lp:~mterry/unity8/set-real-name into lp:unity8

Proposed by Michael Terry on 2016-03-23
Status: Merged
Approved by: Albert Astals Cid on 2016-03-24
Approved revision: 2309
Merged at revision: 2315
Proposed branch: lp:~mterry/unity8/set-real-name
Merge into: lp:unity8
Diff against target: 330 lines (+146/-30)
8 files modified
plugins/AccountsService/AccountsServiceDBusAdaptor.cpp (+12/-2)
tests/plugins/AccountsService/CMakeLists.txt (+2/-1)
tests/plugins/AccountsService/PropertiesServer.cpp (+36/-7)
tests/plugins/AccountsService/PropertiesServer.h (+7/-0)
tests/plugins/AccountsService/client.cpp (+46/-12)
tests/plugins/AccountsService/interfaces.xml (+13/-0)
tests/plugins/AccountsService/types.h (+25/-0)
tests/plugins/IntegratedLightDM/integrated.cpp (+5/-8)
To merge this branch: bzr merge lp:~mterry/unity8/set-real-name
Reviewer Review Type Date Requested Status
Unity8 CI Bot continuous-integration 2016-03-23 Needs Fixing on 2016-03-24
Albert Astals Cid (community) 2016-03-23 Approve on 2016-03-24
Review via email: mp+289973@code.launchpad.net

This proposal supersedes a proposal from 2016-03-16.

Commit message

Fix OOBE wizard not setting your name.

Description of the change

Fix how we set some standard properties of AccountsService (like Email and RealName).

AS does not let you set those properties directly. You must call SetEmail or SetRealName.

I've modified our DBus wrapper to notice such sets and use the right call. I've also updated our test suite to match and added a new test for SetRealName.

= To reproduce =

- Use tablet mode
- Go through the wizard, setting name

When done with wizard, your name should be above the greeter password field, instead of "Ubuntu"

= Checklist =

 * Are there any related MPs required for this MP to build/function as expected? Please list.
 No

 * Did you perform an exploratory manual test run of your code change and any related functionality?
 Yes

 * Did you make sure that your branch does not contain spurious tags?
 Yes

 * If you changed the packaging (debian), did you subscribe the ubuntu-unity team to this MP?
 NA

 * If you changed the UI, has there been a design review?
 NA

To post a comment you must log in.
Albert Astals Cid (aacid) wrote : Posted in a previous version of this proposal

The diff looks weird, i guess launchpad got confused by the prereq? Maybe put this as Work in Progress until the prereq silo lands?

Michael Terry (mterry) wrote : Posted in a previous version of this proposal
Albert Astals Cid (aacid) wrote : Posted in a previous version of this proposal

The code from commit 2297 looks good but i'm afraid you will need to rework this branch since even if i download the current lp:~ci-train-bot/unity8/unity8-ubuntu-xenial-landing-041 and then merge this branch in, i get conflicts, i guess because lp:~ci-train-bot/unity8/unity8-ubuntu-xenial-landing-041 has been changing with time.

So half-approving

review: Approve (code looks good, branch may need rework)
Michael Terry (mterry) wrote : Posted in a previous version of this proposal

OK good point, I'll mark this WIP until we land one of the silos we're waiting on.

Michael Terry (mterry) wrote :

OK, Albert. Rebased on trunk, should be good to go.

lp:~mterry/unity8/set-real-name updated on 2016-03-23
2308. By Michael Terry on 2016-03-23

Add missing file

Michał Sawicz (saviq) wrote :

The following tests FAILED:
   4 - testGreeterIntegrated (Failed)

Albert Astals Cid (aacid) wrote :

As saviq says

4: Test command: /usr/bin/dbus-test-runner "--task" "/home/tsdgeos_work/phablet/unity8/set-real-name/builddir/tests/plugins/AccountsService/mock-server" "--task-name" "server" "--ignore-return" "--task" "/home/tsdgeos_work/phablet/unity8/set-real-name/builddir/tests/plugins/IntegratedLightDM/GreeterIntegratedTestExec" "--task-name" "client" "--wait-for" "org.freedesktop.Accounts" "--parameter" "-o" "--parameter" "/home/tsdgeos_work/phablet/unity8/set-real-name/builddir/tests/plugins/IntegratedLightDM/testGreeterIntegrated.xml,xunitxml" "--parameter" "-o" "--parameter" "-,txt"
4: Test timeout computed to be: 1500
4: DBus daemon: unix:abstract=/tmp/dbus-eV1QCIrOHY,guid=5ecedd4735815462e11add7356f3b0f5
4: server: Started with PID: 4405
4: client: Started with PID: 4410
4: client: ********* Start testing of GreeterIntegratedTest *********
4: client: Config: Using QtTest library 5.5.1, Qt 5.5.1 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 5.3.1 20160225)
4: client: PASS : GreeterIntegratedTest::initTestCase()
4: client: FAIL! : GreeterIntegratedTest::testWatchRealName() 'reply.isValid()' returned FALSE. ()
4: client: Loc: [/home/tsdgeos_work/phablet/unity8/set-real-name/tests/plugins/IntegratedLightDM/integrated.cpp(77)]
4: client: PASS : GreeterIntegratedTest::cleanupTestCase()
4: client: Totals: 2 passed, 1 failed, 0 skipped, 0 blacklisted
4: client: ********* Finished testing of GreeterIntegratedTest *********
4: client: Exited with status 256
4: server: Shutting down
4: client: Shutting down
4: DBus daemon: Shutdown
 4/23 Test #4: testGreeterIntegrated ............***Failed 0.05 sec

review: Needs Fixing
lp:~mterry/unity8/set-real-name updated on 2016-03-24
2309. By Michael Terry on 2016-03-24

Fix integrated test

Michael Terry (mterry) wrote :

Fixed, thanks.

Albert Astals Cid (aacid) wrote :

 * Did you perform an exploratory manual test run of the code change and any related functionality?
Yes

 * Did CI run pass?
Borked CI

 * Did you make sure that the branch does not contain spurious tags?
Yes

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/AccountsService/AccountsServiceDBusAdaptor.cpp'
2--- plugins/AccountsService/AccountsServiceDBusAdaptor.cpp 2016-02-16 14:12:58 +0000
3+++ plugins/AccountsService/AccountsServiceDBusAdaptor.cpp 2016-03-24 13:27:20 +0000
4@@ -57,8 +57,18 @@
5 {
6 QDBusInterface *iface = getUserInterface(user);
7 if (iface != nullptr && iface->isValid()) {
8- // The value needs to be carefully wrapped
9- return iface->asyncCall(QStringLiteral("Set"), interface, property, QVariant::fromValue(QDBusVariant(value)));
10+ if (interface == QStringLiteral("org.freedesktop.Accounts.User")) {
11+ // Standard AccountsService properties use special set methods.
12+ // It will not let you use the usual DBus property setters.
13+ QDBusInterface accountsIface(iface->service(),
14+ iface->path(),
15+ interface,
16+ iface->connection());
17+ return accountsIface.asyncCall(QStringLiteral("Set") + property, value);
18+ } else {
19+ // The value needs to be carefully wrapped
20+ return iface->asyncCall(QStringLiteral("Set"), interface, property, QVariant::fromValue(QDBusVariant(value)));
21+ }
22 }
23 return QDBusPendingCall::fromCompletedCall(QDBusMessage::createError(QDBusError::Other, QStringLiteral("Invalid Interface")));
24 }
25
26=== modified file 'tests/plugins/AccountsService/CMakeLists.txt'
27--- tests/plugins/AccountsService/CMakeLists.txt 2016-02-25 10:57:17 +0000
28+++ tests/plugins/AccountsService/CMakeLists.txt 2016-03-24 13:27:20 +0000
29@@ -5,7 +5,7 @@
30 endif()
31 macro(make_dbus_class NAME INTERFACE)
32 if(${CMAKE_CURRENT_SOURCE_DIR}/interfaces.xml IS_NEWER_THAN ${CMAKE_CURRENT_BINARY_DIR}/${NAME}Adaptor.h)
33- execute_process(COMMAND ${QDBUSXML2CPP_EXECUTABLE} -c ${NAME}Adaptor -a ${CMAKE_CURRENT_BINARY_DIR}/${NAME}Adaptor ${CMAKE_CURRENT_SOURCE_DIR}/interfaces.xml ${INTERFACE})
34+ execute_process(COMMAND ${QDBUSXML2CPP_EXECUTABLE} -c ${NAME}Adaptor -i types.h -a ${CMAKE_CURRENT_BINARY_DIR}/${NAME}Adaptor ${CMAKE_CURRENT_SOURCE_DIR}/interfaces.xml ${INTERFACE})
35 endif()
36 endmacro(make_dbus_class)
37
38@@ -20,6 +20,7 @@
39
40 include_directories(
41 ${CMAKE_CURRENT_BINARY_DIR}
42+ ${CMAKE_CURRENT_SOURCE_DIR}
43 ${CMAKE_SOURCE_DIR}/plugins/AccountsService
44 )
45
46
47=== modified file 'tests/plugins/AccountsService/PropertiesServer.cpp'
48--- tests/plugins/AccountsService/PropertiesServer.cpp 2016-03-23 09:50:10 +0000
49+++ tests/plugins/AccountsService/PropertiesServer.cpp 2016-03-24 13:27:20 +0000
50@@ -25,9 +25,7 @@
51 #include <QDBusMessage>
52 #include <QDBusMetaType>
53
54-using StringMap = QMap<QString,QString>;
55-using StringMapList = QList<StringMap>;
56-Q_DECLARE_METATYPE(StringMapList)
57+#define IFACE_ACCOUNTS_USER QStringLiteral("org.freedesktop.Accounts.User")
58
59 PropertiesServer::PropertiesServer(QObject *parent)
60 : QObject(parent)
61@@ -62,6 +60,38 @@
62 {
63 QVariant newValue = variant.variant();
64
65+ if (interface == IFACE_ACCOUNTS_USER) {
66+ sendErrorReply(QDBusError::InvalidArgs, QStringLiteral("Property is not writable"));
67+ return;
68+ }
69+
70+ internalSet(interface, property, newValue);
71+}
72+
73+void PropertiesServer::SetBackgroundFile(const QString &backgroundFile)
74+{
75+ internalSet(IFACE_ACCOUNTS_USER, QStringLiteral("BackgroundFile"), backgroundFile);
76+}
77+
78+void PropertiesServer::SetEmail(const QString &email)
79+{
80+ internalSet(IFACE_ACCOUNTS_USER, QStringLiteral("Email"), email);
81+}
82+
83+void PropertiesServer::SetInputSources(const StringMapList &inputSources)
84+{
85+ internalSet(IFACE_ACCOUNTS_USER, QStringLiteral("InputSources"), QVariant::fromValue(inputSources));
86+}
87+
88+void PropertiesServer::SetRealName(const QString &realName)
89+{
90+ internalSet(IFACE_ACCOUNTS_USER, QStringLiteral("RealName"), realName);
91+}
92+
93+void PropertiesServer::internalSet(const QString &interface, const QString &property, const QVariant &variant)
94+{
95+ QVariant newValue = variant;
96+
97 if (m_properties[interface].contains(property)) {
98 QVariant& oldValue = m_properties[interface][property];
99 if (oldValue != newValue) {
100@@ -69,14 +99,12 @@
101 if (interface == QStringLiteral("com.canonical.unity.AccountsService") &&
102 property == QStringLiteral("LauncherItems")) {
103 newValue = QVariant::fromValue(qdbus_cast<QList<QVariantMap>>(newValue.value<QDBusArgument>()));
104- } else if (interface == "org.freedesktop.Accounts.User" && property == "InputSources") {
105- newValue = QVariant::fromValue(qdbus_cast<StringMapList>(newValue.value<QDBusArgument>()));
106 }
107
108 oldValue = newValue;
109
110 // Special case for user properties.
111- if (interface == "org.freedesktop.Accounts.User") {
112+ if (interface == IFACE_ACCOUNTS_USER) {
113 Q_EMIT Changed();
114 } else {
115 QVariantMap propertyChanges;
116@@ -108,6 +136,7 @@
117 m_properties["com.ubuntu.location.providers.here.AccountsService"]["LicenseAccepted"] = false;
118 m_properties["com.ubuntu.location.providers.here.AccountsService"]["LicenseBasePath"] = "";
119 m_properties["org.freedesktop.Accounts.User"]["BackgroundFile"] = "";
120+ m_properties["org.freedesktop.Accounts.User"]["Email"] = "";
121+ m_properties["org.freedesktop.Accounts.User"]["InputSources"] = QVariant::fromValue(StringMapList());
122 m_properties["org.freedesktop.Accounts.User"]["RealName"] = "";
123- m_properties["org.freedesktop.Accounts.User"]["InputSources"] = QVariant::fromValue(StringMapList());
124 }
125
126=== modified file 'tests/plugins/AccountsService/PropertiesServer.h'
127--- tests/plugins/AccountsService/PropertiesServer.h 2016-03-11 12:54:58 +0000
128+++ tests/plugins/AccountsService/PropertiesServer.h 2016-03-24 13:27:20 +0000
129@@ -24,6 +24,7 @@
130 #include <QDBusVariant>
131 #include <QObject>
132 #include <QString>
133+#include "types.h"
134
135 class PropertiesServer: public QObject, protected QDBusContext
136 {
137@@ -36,6 +37,10 @@
138 QDBusVariant Get(const QString &interface, const QString &property) const;
139 QVariantMap GetAll(const QString &interface) const;
140 void Set(const QString &interface, const QString &property, const QDBusVariant &variant);
141+ void SetBackgroundFile(const QString &backgroundFile);
142+ void SetEmail(const QString &email);
143+ void SetInputSources(const StringMapList &inputSources);
144+ void SetRealName(const QString &realName);
145
146 // mock only.
147 void Reset();
148@@ -45,6 +50,8 @@
149 void Changed();
150
151 private:
152+ void internalSet(const QString &interface, const QString &property, const QVariant &variant);
153+
154 QHash<QString, QVariantMap> m_properties;
155 };
156
157
158=== modified file 'tests/plugins/AccountsService/client.cpp'
159--- tests/plugins/AccountsService/client.cpp 2016-03-23 09:50:10 +0000
160+++ tests/plugins/AccountsService/client.cpp 2016-03-24 13:27:20 +0000
161@@ -19,16 +19,13 @@
162
163 #include "AccountsService.h"
164 #include "AccountsServiceDBusAdaptor.h"
165+#include "types.h"
166 #include <QSignalSpy>
167 #include <QTest>
168 #include <QDebug>
169 #include <QDBusReply>
170 #include <QDBusMetaType>
171
172-using StringMap = QMap<QString,QString>;
173-using StringMapList = QList<StringMap>;
174-Q_DECLARE_METATYPE(StringMapList)
175-
176 template <class T>
177 QVariant dbusVariant(const T& value) { return QVariant::fromValue(QDBusVariant(value)); }
178
179@@ -263,10 +260,13 @@
180 AccountsService session(this, QTest::currentTestFunction());
181
182 QCOMPARE(session.backgroundFile(), QString());
183- ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
184- "org.freedesktop.Accounts.User",
185- "BackgroundFile",
186- dbusVariant("/test/BackgroundFile")));
187+
188+ QDBusInterface accountsIface(m_userInterface->service(),
189+ m_userInterface->path(),
190+ "org.freedesktop.Accounts.User");
191+ ASSERT_DBUS_CALL(accountsIface.asyncCall("SetBackgroundFile",
192+ "/test/BackgroundFile"));
193+
194 QTRY_COMPARE(session.backgroundFile(), QString("/test/BackgroundFile"));
195 }
196
197@@ -311,6 +311,39 @@
198 QCOMPARE(arguments.at(0).toInt(), 0);
199 }
200
201+ void testSetRealName()
202+ {
203+ AccountsService session(this, QTest::currentTestFunction());
204+
205+ // Just confirm that we can't set normal way
206+ auto message = m_userInterface->call("Set",
207+ "org.freedesktop.Accounts.User",
208+ "RealName",
209+ dbusVariant("Stallman"));
210+ QCOMPARE(message.type(), QDBusMessage::ErrorMessage);
211+ QCOMPARE(message.errorName(), QStringLiteral("org.freedesktop.DBus.Error.InvalidArgs"));
212+
213+ message = m_userInterface->call("Get",
214+ "org.freedesktop.Accounts.User",
215+ "RealName");
216+ QCOMPARE(message.type(), QDBusMessage::ReplyMessage);
217+ auto response = message.arguments().first().value<QDBusVariant>().variant().toString();
218+ QCOMPARE(response, QStringLiteral(""));
219+
220+ // Now try it via our AS wrapper and confirm it did get through, unlike above
221+ session.setRealName("Stallman");
222+
223+ QCOMPARE(session.realName(), QStringLiteral("Stallman"));
224+
225+ message = m_userInterface->call("Get",
226+ "org.freedesktop.Accounts.User",
227+ "RealName");
228+ QCOMPARE(message.type(), QDBusMessage::ReplyMessage);
229+ response = message.arguments().first().value<QDBusVariant>().variant().toString();
230+ QCOMPARE(response, QStringLiteral("Stallman"));
231+
232+ }
233+
234 void testAsynchronousChangeForKeymaps()
235 {
236 AccountsService session(this, QTest::currentTestFunction());
237@@ -325,10 +358,11 @@
238 map2.insert("xkb", "fr");
239 inputSources.append(map2);
240
241- ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
242- "org.freedesktop.Accounts.User",
243- "InputSources",
244- QVariant::fromValue(QDBusVariant(QVariant::fromValue(inputSources)))));
245+ QDBusInterface accountsIface(m_userInterface->service(),
246+ m_userInterface->path(),
247+ "org.freedesktop.Accounts.User");
248+ ASSERT_DBUS_CALL(accountsIface.asyncCall("SetInputSources",
249+ QVariant::fromValue(inputSources)));
250 QStringList result = {"cz+qwerty", "fr"};
251 QTRY_COMPARE(session.keymaps(), result);
252 }
253
254=== modified file 'tests/plugins/AccountsService/interfaces.xml'
255--- tests/plugins/AccountsService/interfaces.xml 2016-02-25 10:57:17 +0000
256+++ tests/plugins/AccountsService/interfaces.xml 2016-03-24 13:27:20 +0000
257@@ -42,6 +42,19 @@
258 <interface name="com.ubuntu.location.providers.here.AccountsService" />
259 <interface name="org.freedesktop.Accounts.User">
260 <signal name="Changed" />
261+ <method name="SetBackgroundFile">
262+ <arg name="backgroundFile" type="s" direction="in" />
263+ </method>
264+ <method name="SetEmail">
265+ <arg name="email" type="s" direction="in" />
266+ </method>
267+ <method name="SetInputSources">
268+ <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="StringMapList"/>
269+ <arg name="inputSources" type="aa{ss}" direction="in" />
270+ </method>
271+ <method name="SetRealName">
272+ <arg name="realName" type="s" direction="in" />
273+ </method>
274 </interface>
275 <interface name="com.canonical.unity.AccountsService.Private" />
276
277
278=== added file 'tests/plugins/AccountsService/types.h'
279--- tests/plugins/AccountsService/types.h 1970-01-01 00:00:00 +0000
280+++ tests/plugins/AccountsService/types.h 2016-03-24 13:27:20 +0000
281@@ -0,0 +1,25 @@
282+/*
283+ * Copyright 2016 Canonical Ltd.
284+ *
285+ * This program is free software: you can redistribute it and/or modify it
286+ * under the terms of the GNU General Public License version 3, as published
287+ * by the Free Software Foundation.
288+ *
289+ * This program is distributed in the hope that it will be useful, but
290+ * WITHOUT ANY WARRANTY; without even the implied warranties of
291+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
292+ * PURPOSE. See the GNU General Public License for more details.
293+ *
294+ * You should have received a copy of the GNU General Public License
295+ * version 3 along with this program. If not, see
296+ * <http://www.gnu.org/licenses/>
297+ */
298+
299+#ifndef UNITY_ASMOCKTYPES_H
300+#define UNITY_ASMOCKTYPES_H
301+
302+using StringMap = QMap<QString,QString>;
303+using StringMapList = QList<StringMap>;
304+Q_DECLARE_METATYPE(StringMapList)
305+
306+#endif
307
308=== modified file 'tests/plugins/IntegratedLightDM/integrated.cpp'
309--- tests/plugins/IntegratedLightDM/integrated.cpp 2016-03-08 18:07:38 +0000
310+++ tests/plugins/IntegratedLightDM/integrated.cpp 2016-03-24 13:27:20 +0000
311@@ -66,14 +66,11 @@
312 QCOMPARE(m_model->data(index, QLightDM::UsersModel::RealNameRole).toString(),
313 QStringLiteral(""));
314
315- // The real AccountsService doesn't let you set via dbus properties. You
316- // have to call SetRealName instead (so that they can protect the call
317- // via policykit). But our test server does let us.
318- QVariant wrapped = QVariant::fromValue(QDBusVariant(QStringLiteral("Test User")));
319- QDBusReply<void> reply = m_user->call(QStringLiteral("Set"),
320- QStringLiteral("org.freedesktop.Accounts.User"),
321- QStringLiteral("RealName"),
322- wrapped);
323+ QDBusInterface accountsIface(m_user->service(),
324+ m_user->path(),
325+ "org.freedesktop.Accounts.User");
326+ QDBusReply<void> reply = accountsIface.call(QStringLiteral("SetRealName"),
327+ QStringLiteral("Test User"));
328 QVERIFY(reply.isValid());
329
330 QTRY_COMPARE(m_model->data(index, QLightDM::UsersModel::RealNameRole).toString(),

Subscribers

People subscribed via source and target branches