All files / universal.klown/gpii/node_modules/flowManager/src UntrustedFlowManager.js

100% Statements 9/9
100% Branches 0/0
100% Functions 1/1
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89                              1x 1x   1x 1x                       1x                                         1x 17x 17x       1x                                                            
/**
 * GPII Untrusted Local FlowManager
 *
 * Copyright 2015 OCAD University
 * Copyright 2017 OCAD University
 *
 * Licensed under the New BSD license. You may not use this file except in
 * compliance with this License.
 *
 * You may obtain a copy of the License at
 * https://github.com/GPII/universal/blob/master/LICENSE.txt
 */
 
"use strict";
 
var fluid = require("infusion"),
    gpii = fluid.registerNamespace("gpii");
 
require("accessRequester");
fluid.require("%gpii-universal/gpii/node_modules/gpii-oauth2/gpii-oauth2-utilities/src/OAuth2Utilities.js");
 
// The Untrusted or Hybrid (Local) FlowManager is a Local FlowManager which defers to the cloud for the matchMaking
// and Preferences fetch process. The architectural goal of the untrusted FlowManager is that the unfiltered
// user preferences never reach the local device. Therefore the userLogon stages of the "gpii.flowManager.matchMakingRequest"
// are all abridged, and instead we simply receive a final settings payload from a cloudBased flowManager which are
// then directly applied to the local device.
 
// Described at https://issues.gpii.net/browse/GPII-1224
 
// Overrides request handlers in "gpii.flowManager.local"
 
fluid.defaults("gpii.flowManager.untrusted", {
    components: {
        untrustedSettingsDataSource: {
            type: "gpii.flowManager.untrustedSettingsDataSource"
            // untrustedSettingsUrl: distributed down from, e.g., gpii.flowManager.untrusted.config.development
            // accessTokenUrl: distributed down from, e.g., gpii.flowManager.untrusted.config.development
            // clientCredentialFilePath: distributed down from, e.g., gpii.flowManager.untrusted.config.development
        }
    },
    requestHandlers: {
        userLogin: {
            // NOTE that these gradesNames do not merge as with standard components
            gradeNames: "gpii.flowManager.untrusted.stateChangeHandler"
        },
        proximityTriggered: {
            gradeNames: "gpii.flowManager.untrusted.stateChangeHandler"
        }
    }
});
 
 
gpii.flowManager.untrusted.getSettings = function (untrustedSettingsDataSource, userToken, deviceReporterData, onMatchDone, onError) {
    var settings = untrustedSettingsDataSource.get(userToken, deviceReporterData);
    settings.then(onMatchDone.fire, onError.fire);
};
 
 
fluid.defaults("gpii.flowManager.untrusted.stateChangeHandler", {
    gradeNames: ["fluid.component", "gpii.flowManager.userLogonHandling.stateChangeHandler"],
    invokers: {
        getSettings: {
            funcName: "gpii.flowManager.untrusted.getSettings",
            args: [
                "{flowManager}.untrustedSettingsDataSource",
                "{that}.userToken",
                "{arguments}.0", // device reporter data
                "{that}.events.onMatchDone",
                "{that}.events.onError"
            ]
        }
    },
    events: {
        onUserToken: null,
        onDeviceContext: null
    },
    listeners: {
        "onUserToken.setUserToken": {
            listener: "gpii.flowManager.setUserToken",
            args: ["{that}", "{arguments}.0"]
        },
        "onUserToken.getDeviceContext": {
            func: "{that}.getDeviceContext",
            priority: "after:setUserToken"
        },
        "onDeviceContext.getSettings": "{that}.getSettings"
    }
});