Skip to content

Instantly share code, notes, and snippets.

@programaths
Last active November 19, 2018 14:13
Show Gist options
  • Save programaths/26e24b663082ddec2bce6194768a8529 to your computer and use it in GitHub Desktop.
Save programaths/26e24b663082ddec2bce6194768a8529 to your computer and use it in GitHub Desktop.
fixing roles & Users
/**
*
* @param {Array<{name:string}>} schema
*/
function fixSchema(schema) {
let fixedSchema = [];
let hasUser = false;
let hasSysRole = false;
let hasRole = false;
for(let item of schema){
switch (item.name) {
case 'User':
fixedSchema.push(item);
hasUser = true;
break;
case '__User':
// Nothing to do
break;
case 'Role':
fixedSchema.push(item);
hasRole = true;
break;
case '__Role':
hasSysRole = true;
break;
default:
fixedSchema.push(item);
}
}
if(hasRole && !hasSysRole){
fixedSchema.push(Realm.Permissions.Role.schema);
}
if(hasUser){
fixedSchema.push(Realm.Permissions.User.schema);
}
return fixedSchema;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment