@@ -368,7 +368,12 @@ module.exports = function(Role) {
368368 * @param {Error } err Error object.
369369 * @param {String[] } roles An array of role IDs
370370 */
371- Role . getRoles = function ( context , callback ) {
371+ Role . getRoles = function ( context , options , callback ) {
372+ if ( ! callback && typeof options === 'function' ) {
373+ callback = options ;
374+ options = { } ;
375+ }
376+
372377 if ( ! ( context instanceof AccessContext ) ) {
373378 context = new AccessContext ( context ) ;
374379 }
@@ -418,15 +423,24 @@ module.exports = function(Role) {
418423 if ( principalType && principalId ) {
419424 // Please find() treat undefined matches all values
420425 inRoleTasks . push ( function ( done ) {
421- roleMappingModel . find ( { where : { principalType : principalType ,
422- principalId : principalId } } , function ( err , mappings ) {
426+ var filter = { where : { principalType : principalType , principalId : principalId } } ;
427+ if ( options . returnOnlyRoleNames === true ) {
428+ filter . include = [ 'role' ] ;
429+ }
430+ roleMappingModel . find ( filter , function ( err , mappings ) {
423431 debug ( 'Role mappings found: %s %j' , err , mappings ) ;
424432 if ( err ) {
425433 if ( done ) done ( err ) ;
426434 return ;
427435 }
428436 mappings . forEach ( function ( m ) {
429- addRole ( m . roleId ) ;
437+ var role ;
438+ if ( options . returnOnlyRoleNames === true ) {
439+ role = m . toJSON ( ) . role . name ;
440+ } else {
441+ role = m . roleId ;
442+ }
443+ addRole ( role ) ;
430444 } ) ;
431445 if ( done ) done ( ) ;
432446 } ) ;
0 commit comments