Skip to content

Commit

Permalink
Merge 41c94fe into 3a9e5b5
Browse files Browse the repository at this point in the history
  • Loading branch information
typerandom committed Sep 27, 2016
2 parents 3a9e5b5 + 41c94fe commit c41de36
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
55 changes: 53 additions & 2 deletions lib/strategy/EnrichIntegrationFromRemoteConfigStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var async = require('async');
var extend = require('../helpers/clone-extend').extend;
var strings = require('../strings');
var util = require('util');

/**
* Retrieves Stormpath settings from the API service, and ensures the local
Expand Down Expand Up @@ -206,12 +207,61 @@ EnrichIntegrationFromRemoteConfigStrategy.prototype._enrichWithDirectoryPolicies

config.passwordPolicy = strength;

callback(null, null);
callback(null, directory);
}));
}));
}));
};

EnrichIntegrationFromRemoteConfigStrategy.prototype._enrichWithDirectoryAccountModel = function (client, config, directory, callback) {
if (!directory) {
return callback(null, null);
}

// Returns the callback immediately if there is an error.
// Continues processing if there isn't.
var stopIfError = function (process) {
return function (err, result) {
if (err) {
callback(err);
} else {
process(result);
}
};
};

var webConfig = config.web;

// Map the registration fields defined in the account schema.
directory.getAccountSchema(stopIfError(function (accountSchema) {
accountSchema.getFields(stopIfError(function (fields) {
fields.each(function (field, next) {

var fieldToConfigure = webConfig.register.form.fields[field.name];

if (field.name in webConfig.register.form.fields) {

var localValue = webConfig.register.form.fields[field.name].required;
var remoteValue = field.required;

if (localValue === false && remoteValue === true){
console.warn(util.format(strings.ACCOUNT_SCHEMA_REMOTE_FIELD_REQUIRED_WARNING,directory.name,field.name));
fieldToConfigure.required = true;
}

if (localValue === true && remoteValue === false){
console.warn(util.format(strings.ACCOUNT_SCHEMA_LOCAL_FIELD_REQUIRED_WARNING,directory.name,field.name));
}
}

next();
}, function (err) {
callback(err, null);
});
}));
}));
};

EnrichIntegrationFromRemoteConfigStrategy.prototype.process = function (config, callback) {
var tasks = [];

Expand All @@ -228,7 +278,8 @@ EnrichIntegrationFromRemoteConfigStrategy.prototype.process = function (config,
this._enrichWithOAuthPolicy.bind(this),
this._enrichWithSocialProviders.bind(this, config),
this._resolveDirectoryHref.bind(this),
this._enrichWithDirectoryPolicies.bind(this, client, config)
this._enrichWithDirectoryPolicies.bind(this, client, config),
this._enrichWithDirectoryAccountModel.bind(this, client, config)
]);
}

Expand Down
2 changes: 2 additions & 0 deletions lib/strings.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -333,4 +333,11 @@ describe('EnrichIntegrationFromRemoteConfigStrategy', function () {
});
});
});

describe.skip('when parsing the directory account schema', function() {
it('fields should still be required by remote config, even if disabled locally', function(done){
});
it('fields should still be required by remote config, even if disabled locally', function(done){
});
});
});

0 comments on commit c41de36

Please sign in to comment.