Last active
June 20, 2016 15:57
-
-
Save elchele/9925867 to your computer and use it in GitHub Desktop.
Sidecar: Retrieving User Roles
This file contains hidden or 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
/* Author: Angel Magaña - [email protected] | |
* | |
* This Gist can be used within a Sugar 7 Controller to retrieve a user's | |
* security Roles | |
* | |
*/ | |
/* To retrieve the Roles, we create a User object then | |
* retrieve the User's related Role records via the default Users <--> Roles relationship | |
*/ | |
var user = app.data.createBean('Users', {id: app.user.id}); //the JSON object contains the ID of the record to load | |
user.fetch(); //this retrieves the record from the Users module with the ID specified in the JSON object | |
//this retrieves the related records for the previously loaded User record, using the 'link' name (from vardefs) | |
var user_roles = user.getRelatedCollection('aclroles'); | |
user_roles.fetch({relate:true}); | |
// At this point, user_roles.models represents all the Role records associated with the given user, in this case, the current user |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you just need the names of the roles for the current user, that's stored in-session at
app.user.attributes.roles