Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.

Commit 2cb01f9

Browse files
WardormeurDanielBrierton
authored andcommitted
Allow mailingList to be saved through the profile to sysUser
1 parent ef7abc8 commit 2cb01f9

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

profiles.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,13 @@ module.exports = function (options) {
9090
function saveProfile (done) {
9191
var userId = args.user ? args.user.id : null;
9292
if (userId !== profile.userId) return done(null, new Error('Profiles can only be saved by the profile user.'));
93+
94+
var cleanedProfile = _.omit(profile, 'user');
95+
// Fields accessible from saveProfile that needs to be passed down to the user entity
9396
if (profile.id) {
94-
profile = _.omit(profile, immutableFields);
97+
cleanedProfile = _.omit(cleanedProfile, immutableFields);
9598
}
96-
97-
seneca.act({role: plugin, cmd: 'save', profile: profile}, function (err, profile) {
99+
seneca.act({role: plugin, cmd: 'save', profile: cleanedProfile}, function (err, retProfile) {
98100
if (err) return done(err);
99101
if (process.env.SALESFORCE_ENABLED === 'true') {
100102
seneca.act({ role: 'cd-profiles', cmd: 'load', id: profile.id }, function (err, fullProfile) {
@@ -105,13 +107,13 @@ module.exports = function (options) {
105107
});
106108
}
107109
// TODO: use seneca-mesh to avoid coupling the integration to the user
108-
if (args.user && !_.isEmpty(profile.email) && args.user.lmsId && args.user.email !== profile.email) {
109-
seneca.act({role: 'cd-users', cmd: 'update_lms_user', lmsId: args.user.lmsId, userEmail: args.user.email, profileEmail: profile.email});
110+
if (args.user && !_.isEmpty(retProfile.email) && args.user.lmsId && args.user.email !== retProfile.email) {
111+
seneca.act({role: 'cd-users', cmd: 'update_lms_user', lmsId: args.user.lmsId, userEmail: args.user.email, profileEmail: retProfile.email});
110112
}
111113
syncUserObj(profile, function (err, res) {
112114
if (err) return done(err);
113115

114-
syncForumProfile(profile, function (err, res) {
116+
syncForumProfile(retProfile, function (err, res) {
115117
if (err) seneca.log.error(err);
116118
var query = {userId: profile.userId};
117119
seneca.act({role: plugin, cmd: 'load'}, query, done);
@@ -123,12 +125,14 @@ module.exports = function (options) {
123125

124126
function syncUserObj (profile, done) {
125127
var updatedFields = {};
128+
var userFields = ['mailingList'];
126129
updatedFields.id = profile.userId;
127130
_.each(syncedFields, function (field) {
128131
updatedFields[field] = profile[field];
129132
});
133+
_.extend(updatedFields, _.pick(profile.user, userFields));
130134
if (updatedFields.email) updatedFields.nick = profile.email;
131-
seneca.act({role: 'cd-users', cmd: 'update', user: updatedFields, id: updatedFields.id}, done);
135+
seneca.act({role: 'cd-users', cmd: 'update', user: updatedFields}, done);
132136
}
133137

134138
function syncForumProfile (profile, done) {

0 commit comments

Comments
 (0)