Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPII-3594: Replace lifecycle manager dynamic session components with standard subcomponents. #727

Merged
merged 6 commits into from Jan 16, 2019

GPII-3594: Improvements based on code review.

  • Loading branch information...
cindyli committed Jan 14, 2019
commit c988c014553a297c964a8d05efd1e90c6d517ad1
@@ -162,7 +162,7 @@ gpii.contextManager.stopTemporalEnvironmentReporter = function (that) {
gpii.contextManager.contextChanged = function (that, lifecycleManager, forceContextName) {
// find logged in users
var activeSession = lifecycleManager.getSession();
var activeGpiiKey = activeSession.options.gpiiKey;
var activeGpiiKey = activeSession.model.gpiiKey;

// if no one is logged in, or, a system reserved key is logged in, do nothing
if (!activeGpiiKey || gpii.isReservedGpiiKey(activeGpiiKey)) {
@@ -132,7 +132,7 @@ gpii.metrics.trackContextChange = function (that, lifecycleManager) {
var userSession = lifecycleManager.getSession();
userSession.applier.modelChanged.addListener({
path: "preferences.contexts",
excludeSource: "SESSIONCLEANUP"
excludeSource: "SessionCleanup"
}, function (newValue, oldValue) {
var current = newValue && newValue[userSession.model.activeContextName];
current = current && current.preferences;
@@ -129,7 +129,7 @@ gpii.pspChannel.filterSolution = function (solution) {
gpii.pspChannel.savePreferences = function (flowManager, lifecycleManager, preferencesAppliedLocalEvent) {
// Grab current active lifecycle manager session
var userSession = lifecycleManager.getSession();
var gpiiKey = userSession.options.gpiiKey;
var gpiiKey = userSession.model.gpiiKey;
var preferences = userSession.model.preferences;
fluid.log("PSPChannel: explicit save for gpiiKey (", gpiiKey, "), with preferences: ", preferences);
flowManager.savePreferences(gpiiKey, preferences);
@@ -212,7 +212,7 @@ gpii.pspChannel.sessionToPSP = function (model, transformSpec) {

gpii.pspChannel.modelChangeListener = function (handler, pspChannel, value, oldValue, path, transaction) {
fluid.log("PSPChannel's PSP-facing modelChangeListener, sources are ", fluid.keys(transaction.sources));
if (!transaction.sources.PSP && !transaction.sources.SESSIONCLEANUP) {
if (!transaction.sources.PSP && !transaction.sources.SessionCleanup) {
fluid.log("Model change source is not PSP - candidate for update message");
if (pspChannel.outputBlocked) {
// Ensure that we queue just a single outgoing message for when the channel unblocks
@@ -43,15 +43,15 @@
gpii.flowManager.sessionAware.withSession = function (that, lifecycleManager, onSuccess, failMessage, onError) {
onError = onError || that.events.onError.fire;
var userSession = lifecycleManager.getSession();
if (!userSession.options.gpiiKey) {
if (!userSession.model.gpiiKey) {
failMessage = failMessage || "Error handling request which required active session, but none was active";
onError({
isError: true,
statusCode: 401,
message: failMessage
});
} else {
onSuccess(userSession, userSession.options.gpiiKey);
onSuccess(userSession, userSession.model.gpiiKey);
}
};

@@ -203,7 +203,7 @@ gpii.journal.writeJournal = function (that, session, snapshot, closed) {
var dir = that.settingsDir.getGpiiSettingsDir();
var filename = "journal-" + gpii.journal.formatTimestamp(session.createTime) + ".json";
var payload = {
gpiiKey: session.options.gpiiKey,
gpiiKey: session.model.gpiiKey,
closed: closed,
createTime: session.createTime,
originalSettings: snapshot
@@ -538,7 +538,7 @@ var gpii = fluid.registerNamespace("gpii");
* @return {String} The GPII key of the active session.
*/
gpii.lifecycleManager.getActiveSessionGpiiKey = function (userSession) {
return userSession.options.gpiiKey;
return userSession.model.gpiiKey;
};

/**
@@ -556,7 +556,7 @@ var gpii = fluid.registerNamespace("gpii");
* gpii.lifecycleManager.restoreSession or undefined.
*/
gpii.lifecycleManager.getSession = function (userSession, restoreSession, gpiiKey) {
return gpiiKey ? userSession.options.gpiiKey === gpiiKey ? userSession :
return gpiiKey ? userSession.model.gpiiKey === gpiiKey ? userSession :
gpiiKey === "restore" ? restoreSession : undefined
: userSession;
};
@@ -1145,7 +1145,7 @@ var gpii = fluid.registerNamespace("gpii");
*/
gpii.lifecycleManager.processStop = function (that, options) {
var userSession = that.userSession;
if (userSession.options.gpiiKey !== options.gpiiKey) {
if (!userSession.model.gpiiKey) {
var failPromise = fluid.promise();
failPromise.reject("No session was found when attempting keyout");
return failPromise;
@@ -1156,14 +1156,14 @@ var gpii = fluid.registerNamespace("gpii");
that.events.onSessionStop.fire(that, userSession);

// Clean up and reinitialize session.model in preparation for the the next key in
fluid.set(userSession, ["options", "gpiiKey"], undefined);
userSession.createTime = undefined;
userSession.applier.change("", null, "DELETE", "SESSIONCLEANUP");
userSession.applier.change("", null, "DELETE", "SessionCleanup");

This comment has been minimized.

Copy link
@amb26

amb26 Jan 14, 2019

Member

Do this in a transaction so that listeners don't receive multiple notifications

userSession.applier.change("", {
gpiiKey: undefined,
actionResults: {},
originalSettings: {},
appliedSolutions: {}
}, "ADD", "SESSIONCLEANUP");
}, "ADD", "SessionCleanup");
});
return restorePromise;
};
@@ -1201,17 +1201,16 @@ var gpii = fluid.registerNamespace("gpii");
var gpiiKey = finalPayload.gpiiKey,
lifecycleInstructions = finalPayload.activeConfiguration.lifecycleInstructions;

if (userSession.options.gpiiKey === gpiiKey) {
if (userSession.model.gpiiKey === gpiiKey) {
var failPromise = fluid.promise();
failPromise.reject("User already logged in when processing start item in action queue. Aborting");
return failPromise;
}
fluid.set(userSession, ["options", "gpiiKey"], gpiiKey);
userSession.createTime = Date.now();
userSession.localFetcher = gpii.lifecycleManager.computeLocalFetcher(userSession);
that.events.onSessionStart.fire("gpii.lifecycleManager.userSession", gpiiKey);
var filteredPayload = fluid.filterKeys(finalPayload, ["gpiiKey", "preferences", "activeContextName", "activeConfiguration", "solutionsRegistryEntries", "matchMakerOutput"]);
userSession.applier.change("", filteredPayload); // TODO: One day after the applier is refactored this will explicitly need to be a "MERGE"
userSession.createTime = Date.now();
userSession.localFetcher = gpii.lifecycleManager.computeLocalFetcher(userSession);

// This "start" action will result in the original settings of the system (i.e. those that
// were on the system before the user logged in) being stored inside userSession.model.originalSettings.
@@ -25,7 +25,7 @@ var fluid = fluid || require("infusion"),
gradeNames: "fluid.component",
modelListeners: {
"originalSettings": {
excludeSource: ["init", "SESSIONCLEANUP"],
excludeSource: ["init", "SessionCleanup"],
func: "{gpii.lifecycleManager}.events.onSessionSnapshotUpdate.fire",
args: ["{gpii.lifecycleManager}", "{that}", "{change}.value"]
}
@@ -114,8 +114,8 @@ var fluid = fluid || require("infusion"),
var prefsForAutoSave = gpii.lifecycleManager.session.filterPrefsByAutoSave(prefsInActiveContext, metadata);
if (prefsForAutoSave) {
fluid.set(autoSavePrefs, ["contexts", that.model.activeContextName, "preferences"], prefsForAutoSave);
fluid.log("Lifecycle Manager Session: auto save for gpiiKey (", that.options.gpiiKey, "), with preferences: ", autoSavePrefs);
preferencesUserUpdated.fire(that.options.gpiiKey, autoSavePrefs);
fluid.log("Lifecycle Manager Session: auto save for gpiiKey (", that.model.gpiiKey, "), with preferences: ", autoSavePrefs);
preferencesUserUpdated.fire(that.model.gpiiKey, autoSavePrefs);
}
}
};
@@ -140,7 +140,7 @@ var fluid = fluid || require("infusion"),
// let the user's token as well as anything else in the session be resolvable (this latter is
// intended only for use in test cases)
return gpii.resolversToFetcher({
gpiiKey: session.options.gpiiKey,
gpiiKey: session.model.gpiiKey,
session: function (path) {
return fluid.get(session.model, path);
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.