Skip to content

Commit

Permalink
Merge pull request #288 from CaptainN/v2
Browse files Browse the repository at this point in the history
Remove underscore, add ecmascript package
  • Loading branch information
SimonSimCity authored Nov 1, 2019
2 parents fa18a4f + 9f426dd commit 3159f23
Show file tree
Hide file tree
Showing 15 changed files with 241 additions and 203 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ var users = [
{name:"Admin User",email:"[email protected]",roles:['admin']}
];

_.each(users, function (user) {
users.forEach(function (user) {
var id;

id = Accounts.createUser({
Expand All @@ -221,7 +221,7 @@ _.each(users, function (user) {
});

if (user.roles.length > 0) {
_.each(user.roles, function (role) {
user.roles.forEach(function (role) {
Roles.createRole(role, {unlessExists: true});
});
// Need _id of existing user record so this call must come after `Accounts.createUser`.
Expand Down
4 changes: 2 additions & 2 deletions examples/flow-router-advanced/main/client/layouts.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Template.mainLayout.helpers({
notVerified: function () {
notVerified: function () {
var user = Meteor.user()

return !emailVerified(user)
}
})

function emailVerified (user) {
return _.some(user.emails, function (email) {
return user.emails.some(function (email) {
return email.verified
})
}
2 changes: 1 addition & 1 deletion examples/flow-router-advanced/main/client/lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ App = {}

"use strict"

_.extend(App, {
Object.assign(App, {

// Separate routing package details from general app code.
navigateTo: function (path) {
Expand Down
8 changes: 4 additions & 4 deletions examples/flow-router-advanced/main/server/startup/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ function createUsers () {
{name:"Admin User",email:"[email protected]",roles:['admin']}
];

_.each(users, function (userData) {
users.forEach(function (userData) {
var id

console.log(userData);

id = Accounts.createUser({
Expand All @@ -41,12 +41,12 @@ function createUsers () {
Meteor.users.update({_id: id},
{$set:{'emails.0.verified': true}});

_.each(userData.roles, function (role) {
userData.roles.forEach(function (role) {
Roles.createRole(role, {unlessExists: true});
});

Roles.addUsersToRoles(id, userData.roles);

});
}
}
4 changes: 2 additions & 2 deletions examples/flow-router-advanced/secrets/server/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Meteor.startup(function () {

function createSecrets () {
var secrets

if (Meteor.secrets.find().fetch().length === 0) {
console.log('Creating secrets: ');

Expand All @@ -23,7 +23,7 @@ function createSecrets () {
{secret:"domain registration pw: apple3"}
]

_.each(secrets, function (secret) {
secrets.forEach(function (secret) {
console.log(secret)

Meteor.secrets.insert(secret);
Expand Down
4 changes: 2 additions & 2 deletions examples/flow-router/client/layouts.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Template.mainLayout.helpers({
notVerified: function () {
notVerified: function () {
var user = Meteor.user()

return !emailVerified(user)
}
})

function emailVerified (user) {
return _.some(user.emails, function (email) {
return user.emails.some(function (email) {
return email.verified
})
}
12 changes: 6 additions & 6 deletions examples/flow-router/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Meteor.startup(function () {
////////////////////////////////////////////////////////////////////
// Create Test Secrets
//

if (Meteor.secrets.find().fetch().length === 0) {
Meteor.secrets.insert({secret:"ec2 password: apple2"});
Meteor.secrets.insert({secret:"domain registration pw: apple3"});
Expand All @@ -34,10 +34,10 @@ Meteor.startup(function () {
{name:"Admin User",email:"[email protected]",roles:['admin']}
];

_.each(users, function (userData) {
users.forEach(function (userData) {
var id,
user;

console.log(userData);

id = Accounts.createUser({
Expand All @@ -49,12 +49,12 @@ Meteor.startup(function () {
// email verification
Meteor.users.update({_id: id}, {$set:{'emails.0.verified': true}});

_.each(userData.roles, function (role) {
userData.roles.forEach(function (role) {
Roles.createRole(role, {unlessExists: true});
});

Roles.addUsersToRoles(id, userData.roles);

});
}

Expand Down Expand Up @@ -102,7 +102,7 @@ Meteor.publish("users", function () {
if (Roles.userIsInRole(user, ["admin","manage-users"])) {
console.log('publishing users', this.userId);
return Meteor.users.find({}, {fields: {emails: 1, profile: 1, roles: 1}});
}
}

this.stop();
return;
Expand Down
4 changes: 2 additions & 2 deletions examples/iron-router/client/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ Meteor.navigateTo = function (path) {
}

function emailVerified (user) {
return _.some(user.emails, function (email) {
return user.emails.some(function (email) {
return email.verified
})
}

var filters = {

/**
* ensure user is logged in and
* ensure user is logged in and
* email verified
*/
authenticate: function () {
Expand Down
12 changes: 6 additions & 6 deletions examples/iron-router/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Meteor.startup(function () {
////////////////////////////////////////////////////////////////////
// Create Test Secrets
//

if (Meteor.secrets.find().fetch().length === 0) {
Meteor.secrets.insert({secret:"ec2 password: apple2"});
Meteor.secrets.insert({secret:"domain registration pw: apple3"});
Expand All @@ -34,10 +34,10 @@ Meteor.startup(function () {
{name:"Admin User",email:"[email protected]",roles:['admin']}
];

_.each(users, function (userData) {
users.forEach(function (userData) {
var id,
user;

console.log(userData);

id = Accounts.createUser({
Expand All @@ -49,12 +49,12 @@ Meteor.startup(function () {
// email verification
Meteor.users.update({_id: id}, {$set:{'emails.0.verified': true}});

_.each(userData.roles, function (role) {
userData.roles.forEach(function (role) {
Roles.createRole(role, {unlessExists: true});
});

Roles.addUsersToRoles(id, userData.roles);

});
}

Expand Down Expand Up @@ -102,7 +102,7 @@ Meteor.publish("users", function () {
if (Roles.userIsInRole(user, ["admin","manage-users"])) {
console.log('publishing users', this.userId);
return Meteor.users.find({}, {fields: {emails: 1, profile: 1, roles: 1}});
}
}

this.stop();
return;
Expand Down
3 changes: 1 addition & 2 deletions package.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Package.onUse(function (api) {

var both = ['client', 'server'];

api.use(['underscore',
api.use(['ecmascript',
'accounts-base',
'tracker',
'mongo',
Expand All @@ -36,7 +36,6 @@ Package.onTest(function (api) {

api.use(['alanning:roles',
'accounts-password',
'underscore',
'mongo',
'tinytest'], both);

Expand Down
10 changes: 5 additions & 5 deletions roles/client/uiHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//
// Use a semi-private variable rather than declaring UI
// helpers directly so that we can unit test the helpers.
// XXX For some reason, the UI helpers are not registered
// XXX For some reason, the UI helpers are not registered
// before the tests run.
//
Roles._uiHelpers = {
Expand All @@ -40,7 +40,7 @@ Roles._uiHelpers = {
* @param {String} [scope] Optional, name of scope to check.
* @return {Boolean} `true` if current user is in at least one of the target roles.
* @static
* @for UIHelpers
* @for UIHelpers
*/
isInRole: function (role, scope) {
var user = Meteor.user(),
Expand All @@ -51,7 +51,7 @@ Roles._uiHelpers = {
if (!Match.test(role, String)) return false

if (comma !== -1) {
roles = _.reduce(role.split(','), function (memo, r) {
roles = role.split(',').reduce(function (memo, r) {
if (!r || !Roles._trim(r)) {
return memo
}
Expand Down Expand Up @@ -83,10 +83,10 @@ if (Roles.debug && console.log) {
if ('undefined' !== typeof Package.blaze &&
'undefined' !== typeof Package.blaze.Blaze &&
'function' === typeof Package.blaze.Blaze.registerHelper) {
_.each(Roles._uiHelpers, function (func, name) {
Object.entries(Roles._uiHelpers).forEach(([name, func]) => {
if (Roles.debug && console.log) {
console.log("[roles] registering Blaze helper '" + name + "'")
}
Package.blaze.Blaze.registerHelper(name, func)
Package.blaze.Blaze.registerHelper(name, func)
})
}
Loading

0 comments on commit 3159f23

Please sign in to comment.