Last active
November 19, 2018 14:13
-
-
Save programaths/26e24b663082ddec2bce6194768a8529 to your computer and use it in GitHub Desktop.
fixing roles & Users
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @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