Meteor + OrionJS: Extend user profile and add an profile picture


#1

Hello guys,

I’m trying to extend Meteor users to be able to upload a profile picture through the OrionJS admin.
When I look up the code in the Accounts update view, I see this:

{{# autoForm id="accountsUpdateProfileForm" schema=profileSchema type="method-update" doc=user meteormethod="orionAccountsUpdateProfile" }}
    {{> afQuickFields name='profile' }}
    <br>
    <button class="btn btn-primary">{{ i18n 'global.save' }}</button>
  {{/ autoForm }}

This means I should be able to extend the profileSchema with an image, but I’m not succeeding…
According to the meteor-collection2 library, I should be able to set a schema and by default it should be merged with the already set schema.

I have this code in a lib JavaScript:

Schema = {};

Schema.UserProfile = new SimpleSchema({
firstName: {
    type: String,
    optional: true
},
lastName: {
    type: String,
    optional: true
},
picture: orion.attribute('image', {
    optional: true,
    label: 'Foto'
})
});

Schema.User = new SimpleSchema({
profile: {
    type: Schema.UserProfile,
    optional: true
}
});

Meteor.users.attachSchema(Schema.User);

However I receive the following error:

Error: When the modifier option is true, validation object must have at least one operator

Probably this error is thrown when I’m adding a default user (which works when I don’t override the schema).

I’ve tried a lot of things. All help is very welcome!
Thanks in advance.


#2

Nevermind, guys.

After digging in the code of OrionJS, I could find that the variable orion.accounts.profileSchema was set in the accounts.js file. By simply overriding it, the new attributes showed up in the view.

Solution:

UserProfileSchema = new SimpleSchema({
name: {
    type: String,
    label: orion.helpers.getTranslation('accounts.schema.profile.name')
},
picture: orion.attribute('image', {
    optional: true,
    label: 'Foto'
}),
bio: {
    type: String,
    label: 'Bio'
}
});

orion.accounts.profileSchema = new SimpleSchema({
profile: {
    type: UserProfileSchema
}
});

Thanks anyway!