Admin interface for users and roles


#1

Is there something like Django admin for Meteor where I could list all users and see their roles and assign them and so on?


#2

I’m looking for something similar I think. I implemented the alanning:meteor-roles package, create a couple of roles and manually assigned them. The next logical step was to want to build a UI to set roles and that’s where I’ve been struggling. I feel like I’m semi-close but just can’t make the connection to take it all the way.

I’m pretty new to Meteor, but here’s what I’ve got so far. The code below ends up showing me a table of all my users and the all roles I’d created. I’m unsure how to have it check off the roles that are already applied and make it update if I select new roles.

userAdmin.html:

<div class="table-responsive">
  <table class="table table-bordered">
    <thead>
      <tr>
        <th>User</th>
        <th>Roles</th>
        <th>Notes</th>
        <th>Admin</th>
      </tr>
    </thead>
    <tbody>
      {{> userList }}
    </tbody>
  </table>
</div>

<template name="userList">
  {{#each allUsers}}
    <tr>
      <td>{{username}}</td>
      <input type="hidden" id="roles_{{username}}" value="{{userRoles}}">
      <td>
        {{#each allRoles}}
          {{userName}}
          <input type="checkbox" name="roles" value="{{name}}">{{name}}
        {{/each}}
      </td>
    </tr>
  {{/each}}
</template>

Then in my userAdmin.js:

if (Meteor.isClient) {
    // This code only runs on the client
    Meteor.subscribe("userList");
    Meteor.subscribe("allRoles");
    Template.userList.helpers({
        allUsers: function() {
          return Meteor.users.find();
        },
        userRoles: function() {
          return this.roles;
        },
        allRoles: function() {
          return Roles.getAllRoles();
        },
    });
}

if(Meteor.isServer) {
  Meteor.publish("userList", function() {
    return Meteor.users.find({}, {fields: {username: 1, profile: 1, roles: 1}});
  });
  Meteor.publish("allRoles", function(){
    return Roles.getAllRoles();
  });
}

#3

Beyond @shifter’s beautiful snippet,
is there a package that provides these types of admin interfaces for alanning:roles? :smile: