Skip to content

Instantly share code, notes, and snippets.

@juniorconte
Created February 19, 2016 01:37
Show Gist options
  • Save juniorconte/f36757c057e298be309c to your computer and use it in GitHub Desktop.
Save juniorconte/f36757c057e298be309c to your computer and use it in GitHub Desktop.
Criar usuários dreamfactory e registrar com diferentes papéis via API
var lodash = require("lodash.min.js");
var role1Id = 1;
var role2Id = 2;
var role3Id = 3;
var appVendorId = 1;
var appCustomerId = 2;
var originAppId = platform.session.app.id;
if (platform.session.user) {
var userObject = platform.api.get('system/user/'+platform.session.user.id+'?related=user_to_app_to_role_by_user_id');
lodash._.each(userObject.content.user_to_app_to_role_by_user_id, function(userApp) {
switch (originAppId) {
case appCustomerId:
if (userApp.app_id === appCustomerId) {
userApp.role_id = role1Id;
}
break;
case appVendorId:
if (userApp.app_id === appVendorId) {
userApp.role_id = role2Id;
}
break;
}
});
platform.api.patch('system/user/'+platform.session.user.id+'?related=user_to_app_to_role_by_user_id', userObject.content);
}
@juniorconte
Copy link
Author

Required setup, and more information on http://goo.gl/tPa4Fa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment