code: function role_permissions(roles, callback) {
    var permissions = [],
        fetch = [];
  
    if (roles) {
      // TODO: Here we could do with some caching like Drupal does.
      roles.forEach(function (name, rid) {
        fetch.push(rid);
      });
  
      // Get permissions for the rids.
      if (fetch) {
        db.query("SELECT rid, permission FROM role_permission WHERE rid IN ($1);", [fetch], function (err, rows) {
          if (err) {
            callback(err, null);
          }
  
          if (rows.length > 0) {
            rows.forEach(function (row) {
              permissions.push(row.permission);
            });
          }
  
          callback(null, permissions);
        });
      }
    }
  }
docs: Get all permissions granted to a set of roles.
  
  Like user_role_permissions() in Drupal core.