Started adding async calls for upgrading to Meteor 3.0. Numerous other fixes.
This commit is contained in:
@@ -9,6 +9,7 @@ let PREFIX = "UserManagement";
|
||||
|
||||
Tracker.autorun(function() {
|
||||
Meteor.subscribe("users", Session.get(PREFIX + 'searchQuery'));
|
||||
Meteor.subscribe("roleAssignments");
|
||||
Meteor.subscribe("roles");
|
||||
});
|
||||
|
||||
@@ -132,6 +133,15 @@ Template.User.helpers({
|
||||
let editedUser = Session.get(PREFIX + "editedUser");
|
||||
|
||||
return editedUser == this._id;
|
||||
},
|
||||
roles: function() {
|
||||
let roles = Meteor.roleAssignment.find({"user._id": this._id}, {"sort": [["role._id", "asc"]]}).fetch();
|
||||
let result = []
|
||||
|
||||
for(let next of roles)
|
||||
result.push(next.role._id)
|
||||
|
||||
return result
|
||||
}
|
||||
});
|
||||
|
||||
@@ -145,7 +155,15 @@ Template.UserEditor.helpers({
|
||||
getRoleState: function(role) {
|
||||
let user = Template.parentData(1);
|
||||
|
||||
return !user.isNew && user.roles.includes(role.name) ? "selected" : "";
|
||||
//Debug code...
|
||||
// console.log("GetRoleState")
|
||||
// console.log(role._id)
|
||||
// console.log(user._id)
|
||||
// console.log(Meteor.roleAssignment.find({"user._id": user._id, "role._id": role._id}).count())
|
||||
//console.log("Role: " + role._id + " === " + Roles.userIsInRole(user._id, [role._id]))
|
||||
|
||||
// Note: Meteor.roleAssignment.countDocuments({...}) returns a Promise and not a count. Cannot use that here.
|
||||
return Roles.userIsInRole(user._id, [role._id]) ? "selected" : ""
|
||||
}
|
||||
});
|
||||
Template.UserEditor.events({
|
||||
@@ -166,10 +184,10 @@ Template.UserEditor.events({
|
||||
roles.push($(roleSpans[i]).text());
|
||||
}
|
||||
|
||||
user.roles = roles;
|
||||
//user.roles = roles;
|
||||
|
||||
if(Session.get(PREFIX + 'displayNewUser')) {
|
||||
Meteor.call('insertUser', user, function(error, result) {
|
||||
Meteor.call('insertUser', user, roles, function(error, result) {
|
||||
if(error) {
|
||||
sAlert.error(error);
|
||||
}
|
||||
@@ -182,7 +200,7 @@ Template.UserEditor.events({
|
||||
}
|
||||
else {
|
||||
user._id = this._id;
|
||||
Meteor.call("updateUser", user, function(error, result) {
|
||||
Meteor.call("updateUser", user, roles, function(error, result) {
|
||||
if(error) sAlert.error(error);
|
||||
else {
|
||||
sAlert.success("User updated.");
|
||||
|
||||
Reference in New Issue
Block a user