@@ -90,11 +90,13 @@ module.exports = function (options) {
90
90
function saveProfile ( done ) {
91
91
var userId = args . user ? args . user . id : null ;
92
92
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
93
96
if ( profile . id ) {
94
- profile = _ . omit ( profile , immutableFields ) ;
97
+ cleanedProfile = _ . omit ( cleanedProfile , immutableFields ) ;
95
98
}
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 ) {
98
100
if ( err ) return done ( err ) ;
99
101
if ( process . env . SALESFORCE_ENABLED === 'true' ) {
100
102
seneca . act ( { role : 'cd-profiles' , cmd : 'load' , id : profile . id } , function ( err , fullProfile ) {
@@ -105,13 +107,13 @@ module.exports = function (options) {
105
107
} ) ;
106
108
}
107
109
// 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 } ) ;
110
112
}
111
113
syncUserObj ( profile , function ( err , res ) {
112
114
if ( err ) return done ( err ) ;
113
115
114
- syncForumProfile ( profile , function ( err , res ) {
116
+ syncForumProfile ( retProfile , function ( err , res ) {
115
117
if ( err ) seneca . log . error ( err ) ;
116
118
var query = { userId : profile . userId } ;
117
119
seneca . act ( { role : plugin , cmd : 'load' } , query , done ) ;
@@ -123,12 +125,14 @@ module.exports = function (options) {
123
125
124
126
function syncUserObj ( profile , done ) {
125
127
var updatedFields = { } ;
128
+ var userFields = [ 'mailingList' ] ;
126
129
updatedFields . id = profile . userId ;
127
130
_ . each ( syncedFields , function ( field ) {
128
131
updatedFields [ field ] = profile [ field ] ;
129
132
} ) ;
133
+ _ . extend ( updatedFields , _ . pick ( profile . user , userFields ) ) ;
130
134
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 ) ;
132
136
}
133
137
134
138
function syncForumProfile ( profile , done ) {
0 commit comments