Merge lp:~alecu/unity-lens-music/rework-credentials-check into lp:~unity-team/unity-lens-music/libunity7-compatible

Proposed by Alejandro J. Cura
Status: Merged
Approved by: Michal Hruby
Approved revision: 149
Merged at revision: 149
Proposed branch: lp:~alecu/unity-lens-music/rework-credentials-check
Merge into: lp:~unity-team/unity-lens-music/libunity7-compatible
Diff against target: 222 lines (+84/-18)
6 files modified
configure.ac (+3/-0)
src/Makefile.am (+2/-0)
src/config.vala.in (+2/-0)
src/musicstore-scope.vala (+57/-15)
src/ubuntuone-webservices.vala (+11/-2)
tests/unit/test-ubuntuone-purchases.vala (+9/-1)
To merge this branch: bzr merge lp:~alecu/unity-lens-music/rework-credentials-check
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Michal Hruby (community) Approve
Review via email: mp+160758@code.launchpad.net

Commit message

- Move account checking to payment preview (LP: #1170773).

Description of the change

* Credentials check was moved from search to the payment preview (LP: #1170773)
* Fixed the path and parameters for the new login ui

To post a comment you must log in.
Revision history for this message
dobey (dobey) wrote :

The autotools portions (which alecu asked me to review) look good to me.

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

fix for the tests

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
149. By Alejandro J. Cura

fix formatting issue

Revision history for this message
Michal Hruby (mhr3) wrote :

Looks reasonable to me.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'configure.ac'
2--- configure.ac 2013-04-23 08:09:36 +0000
3+++ configure.ac 2013-04-25 16:47:27 +0000
4@@ -116,6 +116,9 @@
5 AS_AC_EXPAND(DATADIR, $datarootdir)
6 AC_SUBST(DATADIR)
7
8+AS_AC_EXPAND(LIBEXECDIR, $libexecdir)
9+AC_SUBST(LIBEXECDIR)
10+
11 #####################################################
12 # Look for dbus service dir
13 #####################################################
14
15=== modified file 'src/Makefile.am'
16--- src/Makefile.am 2013-04-17 15:02:43 +0000
17+++ src/Makefile.am 2013-04-25 16:47:27 +0000
18@@ -4,6 +4,7 @@
19 EXTRA_DIST =
20
21 DATADIR = $(datadir)
22+LIBEXECDIR = $(libexecdir)
23
24 # we're using Vala, C warnings are useless
25 AM_CFLAGS = -w
26@@ -70,6 +71,7 @@
27 $(NULL)
28
29 unity_musicstore_daemon_CPPFLAGS = \
30+ -DLIBEXECDIR=\"$(LIBEXECDIR)\" \
31 $(unity_music_daemon_CPPFLAGS)
32
33 unity_musicstore_daemon_VALAFLAGS = \
34
35=== modified file 'src/config.vala.in'
36--- src/config.vala.in 2013-03-13 12:14:27 +0000
37+++ src/config.vala.in 2013-04-25 16:47:27 +0000
38@@ -8,6 +8,8 @@
39
40 const string BINDIR = "@prefix@/bin";
41
42+ const string LIBEXECDIR = "@LIBEXECDIR@";
43+
44 const string LOCALEDIR = "@DATADIR@/locale";
45
46 const string PACKAGE = "@PACKAGE@";
47
48=== modified file 'src/musicstore-scope.vala'
49--- src/musicstore-scope.vala 2013-04-22 09:02:29 +0000
50+++ src/musicstore-scope.vala 2013-04-25 16:47:27 +0000
51@@ -29,7 +29,7 @@
52 private const string ERROR_MESSAGE_NOT_LOGGED_IN = _("It seems you don't have an Ubuntu One account, or you are not logged in. To continue, please login and visit the Ubuntu One online store.");
53 private const string ERROR_MESSAGE_NO_PAYMENT_METHOD = _("It seems you haven't set yet your preferred Ubuntu One payment method. To add a payment method, please visit the Ubuntu One online store.");
54 private const string ERROR_MESSAGE_TECHNICAL_PROBLEM = _("Sorry, we have encountered a technical problem. No money has been taken from your account. To try your purchase again, please visit the Ubuntu One online store.");
55- private const string U1_SSO_UI = "u1_login_register";
56+ private const string UBUNTUONE_MUSIC_LOGIN = Config.LIBEXECDIR + "/ubuntuone-credentials/ubuntuone-music-login";
57
58 public class MusicStoreScopeProxy : SimpleScope
59 {
60@@ -164,12 +164,6 @@
61 warning ("Failed to search for '%s': %s", search.search_string, e.message);
62 }
63
64- try {
65- yield purchase_service.fetch_account_info ();
66- debug ("retrieved account info: %s %s", purchase_service.nickname, purchase_service.email);
67- } catch (PurchaseError e) {
68- debug ("can't get account info: %s", e.message);
69- }
70 }
71
72 delegate Unity.ActivationResponse LinkHandler (string uri);
73@@ -211,15 +205,16 @@
74 SList<Track> tracks = null;
75 collection.get_album_details (uri, out album, out tracks);
76
77- var ui_path = Environment.find_program_in_path (U1_SSO_UI);
78+ debug ("Finding %s", UBUNTUONE_MUSIC_LOGIN);
79+ var ui_path = Environment.find_program_in_path (UBUNTUONE_MUSIC_LOGIN);
80 GLib.Pid child_pid;
81- string argv[11] = {
82+ string argv[6] = {
83 ui_path,
84- "--album", album.title,
85- "--artist", album.artist,
86- "--price", album.formatted_price,
87- "--picture", album.artwork_path,
88- "--url", uri
89+ "--album=" + album.title,
90+ "--artist=" + album.artist,
91+ "--price=" + album.formatted_price,
92+ "--picture=" + album.artwork_path,
93+ "--url=" + uri
94 };
95 if (ui_path != null) {
96 try {
97@@ -229,14 +224,61 @@
98 return new Unity.ActivationResponse (Unity.HandledType.HIDE_DASH);
99 }
100 } catch (GLib.SpawnError e) {
101- debug ("Failed to start u1_sso_ui for uri %s", uri);
102+ debug ("Failed to start ubuntuone-music-login for uri %s", uri);
103 }
104 }
105 return open_uri (uri);
106 }
107
108+ bool run_with_timeout (MainLoop ml, uint timeout_ms)
109+ {
110+ bool timeout_reached = false;
111+ var t_id = Timeout.add (timeout_ms, () => {
112+ timeout_reached = true;
113+ debug ("Timeout reached");
114+ ml.quit ();
115+ return false;
116+ });
117+
118+ ml.run ();
119+
120+ if (!timeout_reached) {
121+ Source.remove (t_id);
122+ }
123+
124+ return !timeout_reached;
125+ }
126+
127+ void fetch_account_info_sync () throws PurchaseError
128+ {
129+ PurchaseError failure = null;
130+ MainLoop mainloop = new MainLoop ();
131+ purchase_service.fetch_account_info.begin((obj, res) => {
132+ mainloop.quit ();
133+ try {
134+ purchase_service.fetch_account_info.end (res);
135+ } catch (PurchaseError e) {
136+ failure = e;
137+ }
138+ });
139+ if (!run_with_timeout (mainloop, 10000)) {
140+ throw new PurchaseError.MISSING_CREDENTIALS_ERROR ("Timeout getting credentials.");
141+ }
142+ if (failure != null) {
143+ throw failure;
144+ }
145+ }
146+
147 public Unity.ActivationResponse show_purchase_preview (string uri)
148 {
149+
150+ try {
151+ fetch_account_info_sync ();
152+ debug ("retrieved account info: %s %s", purchase_service.nickname, purchase_service.email);
153+ } catch (PurchaseError e) {
154+ debug ("can't get account info: %s", e.message);
155+ }
156+
157 if (purchase_service.got_credentials () == false)
158 {
159 debug ("no credentials available, opening sso login. %s", uri);
160
161=== modified file 'src/ubuntuone-webservices.vala'
162--- src/ubuntuone-webservices.vala 2013-04-17 19:25:40 +0000
163+++ src/ubuntuone-webservices.vala 2013-04-25 16:47:27 +0000
164@@ -22,7 +22,9 @@
165 [DBus (name = "com.ubuntuone.CredentialsManagement")]
166 interface CredentialsManagement : GLib.Object {
167 public signal void credentials_found (HashTable <string, string> info);
168- public signal void credentials_error ();
169+ public signal void credentials_not_found ();
170+ public signal void credentials_error (HashTable <string, string> error_dict);
171+
172
173 [DBus (name = "find_credentials")]
174 public abstract void find_credentials () throws Error;
175@@ -176,8 +178,14 @@
176 debug ("got credentials");
177 fetch_credentials.callback ();
178 });
179- ulong error_handler = credentials_management.credentials_error.connect (() => {
180+ ulong not_found_handler = credentials_management.credentials_not_found.connect (() => {
181+ error = new PurchaseError.MISSING_CREDENTIALS_ERROR ("No Ubuntu One tokens.");
182+ debug ("not found handler");
183+ fetch_credentials.callback ();
184+ });
185+ ulong error_handler = credentials_management.credentials_error.connect ((error_dict) => {
186 error = new PurchaseError.MISSING_CREDENTIALS_ERROR ("Can't get Ubuntu One tokens.");
187+ debug ("error handler");
188 fetch_credentials.callback ();
189 });
190
191@@ -189,6 +197,7 @@
192 }
193
194 credentials_management.disconnect (found_handler);
195+ credentials_management.disconnect (not_found_handler);
196 credentials_management.disconnect (error_handler);
197
198 if (error != null) {
199
200=== modified file 'tests/unit/test-ubuntuone-purchases.vala'
201--- tests/unit/test-ubuntuone-purchases.vala 2013-03-19 21:41:57 +0000
202+++ tests/unit/test-ubuntuone-purchases.vala 2013-04-25 16:47:27 +0000
203@@ -201,10 +201,18 @@
204
205 class FailingCredentialsManagement : GLib.Object, CredentialsManagement
206 {
207+ private HashTable <string, string> fake_error_info;
208+
209+ construct
210+ {
211+ fake_error_info = new HashTable <string, string> (str_hash, str_equal);
212+ fake_error_info["error"] = "fake_error";
213+ }
214+
215 public void find_credentials () throws IOError
216 {
217 Idle.add (() => {
218- credentials_error ();
219+ credentials_error (fake_error_info);
220 return false;
221 });
222 }

Subscribers

People subscribed via source and target branches

to all changes: