Loopback: Feature Request: Return Role Name in Role.getRoles (from principals)

Created on 9 Oct 2014  路  4Comments  路  Source: strongloop/loopback

In the current Roles model, the getRoles method returns the id when fetching role mappings via principal. It would be nice it resolved this to the actual role name.

This requires more callbacks to track in inRoleTasks but shouldn't be too difficult to add the calls in.

Most helpful comment

referring to this url

this simple modification would do the trick

if (principalType && principalId) {
        // Please find() treat undefined matches all values
        inRoleTasks.push(function(done) {
          roleMappingModel.find({
              where: {principalType: principalType, principalId: principalId},
              include: ['role']
          }, function(err, mappings) {
            debug('Role mappings found: %s %j', err, mappings);
            if (err) {
              if (done) done(err);
              return;
            }
            mappings.forEach(function(m) {
              var _m = m.toJSON();
              addRole(_m.role.name);
            });
            if (done) done();
          });
        });
      }

All 4 comments

@greaterweb would you mind submitting a pull request implementing this change?

BTW when building github URLs to code, press "y" before copying the URL. That way a commit sha is appended to the URL and it will keep working even when the file is moved around, as happened in this case. I have fixed the issue description for you, please check that the line numbers are still correct.

Closing.

@batjos: would you know if this feature request has been considered, or will be at some point? It would indeed be nice that getRoles return actual role names rather than their ids

referring to this url

this simple modification would do the trick

if (principalType && principalId) {
        // Please find() treat undefined matches all values
        inRoleTasks.push(function(done) {
          roleMappingModel.find({
              where: {principalType: principalType, principalId: principalId},
              include: ['role']
          }, function(err, mappings) {
            debug('Role mappings found: %s %j', err, mappings);
            if (err) {
              if (done) done(err);
              return;
            }
            mappings.forEach(function(m) {
              var _m = m.toJSON();
              addRole(_m.role.name);
            });
            if (done) done();
          });
        });
      }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

rkmax picture rkmax  路  3Comments

ian-lewis-cs picture ian-lewis-cs  路  4Comments

dyaa picture dyaa  路  4Comments

Overdrivr picture Overdrivr  路  3Comments

crandmck picture crandmck  路  3Comments