~ci-train-bot/ubuntu-system-settings-online-accounts/ubuntu-system-settings-online-accounts-ubuntu-zesty-2288

« back to all changes in this revision

Viewing changes to online-accounts-ui/qml/ProviderRequest.qml

  • Committer: Bileto Bot
  • Author(s): Alberto Mardegan
  • Date: 2016-09-29 09:07:32 UTC
  • mfrom: (366.1.6 empty-page-1594944)
  • Revision ID: ci-train-bot@canonical.com-20160929090732-ghifxbh27qd8nlrv
Properly handle early termination of account access requests

When a degenerate request (coming from an unconfined process with empty application ID) was received, the allowed() signal was emitted from the Component.onCompleted handler.
However, given that this all was happening inside the QQuickView::setSource() method, the signal was effectively emitted before the C++ code had a chance to setup the signal connections, with the result that such a signal was lost.

To solve this, we export a "request" object to QML, whose methods replace the old signals. (LP: #1594944)

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
MainView {
25
25
    id: root
26
26
 
27
 
    property variant applicationInfo: application
28
 
    property variant providerInfo: provider
29
 
    property bool wasDenied: false
 
27
    property var applicationInfo: request.application
 
28
    property var providerInfo: request.provider
30
29
    property int __createdAccountId: 0
31
30
 
32
 
    signal denied
33
 
    signal allowed(int accountId)
34
 
 
35
31
    width: units.gu(48)
36
32
    height: units.gu(60)
37
33
    automaticOrientation: true
40
36
        i18n.domain = "ubuntu-system-settings-online-accounts"
41
37
        if (accessModel.count === 0 && !accessModel.canCreateAccounts) {
42
38
            /* No accounts to authorize */
43
 
            denied()
 
39
            request.deny()
44
40
            return
45
41
        }
46
 
        if (!application.id && accessModel.count == 1 &&
 
42
        if (!applicationInfo.id && accessModel.count == 1 &&
47
43
            applicationInfo.profile == "unconfined") {
48
44
            /* Degenerate case: unconfined app making requests with no valid
49
45
             * app ID */
50
 
            allowed(accountsModel.get(0, "accountId"))
 
46
            request.allow(accountsModel.get(0, "accountId"))
51
47
            return
52
48
        }
53
49
        loader.active = true
55
51
    }
56
52
 
57
53
    on__CreatedAccountIdChanged: grantAccessIfReady()
58
 
    onDenied: wasDenied = true
59
 
 
60
 
    onAllowed: loader.sourceComponent = spinnerComponent
61
54
 
62
55
    PageStack {
63
56
        id: pageStack
111
104
        AccountCreationPage {
112
105
            providerId: providerInfo.id
113
106
            onFinished: {
114
 
                if (accountId == 0) root.denied()
 
107
                if (accountId == 0) request.deny()
115
108
                /* if an account was created, just remember its ID. when the
116
109
                 * accountsModel will notice it we'll proceed with the access
117
110
                 * grant */
127
120
            application: applicationInfo
128
121
            provider: providerInfo
129
122
            canAddAnotherAccount: accessModel.canCreateAccounts
130
 
            onDenied: root.denied()
 
123
            onDenied: request.deny()
131
124
            onAllowed: root.grantAccess(accountId)
132
125
            onCreateAccount: pageStack.push(createAccountPageComponent)
133
126
        }
198
191
        if (root.__createdAccountId != 0) {
199
192
            // If the request comes from system settings, stop here
200
193
            if (applicationInfo.id === "system-settings") {
201
 
                root.allowed(root.__createdAccountId)
 
194
                request.allow(root.__createdAccountId)
 
195
                loader.sourceComponent = spinnerComponent
202
196
                return
203
197
            }
204
198
 
216
210
        if (i < 0) {
217
211
            // very unlikely; maybe the account has been deleted in the meantime
218
212
            console.log("Account not found:" + accountId)
219
 
            root.denied()
 
213
            request.deny()
220
214
            return
221
215
        }
222
216
 
249
243
 
250
244
    function accountEnablingDone() {
251
245
        console.log("account enabling done")
252
 
        allowed(account.accountId)
 
246
        request.allow(account.accountId)
 
247
        loader.sourceComponent = spinnerComponent
253
248
    }
254
249
}