Closed StorytellerCZ closed 4 weeks ago
@StorytellerCZ is there anything that isn't already implemented by the latest release that contains the async counterparts?
Not 100% sure, but I think we have everything. I will remove the sync MongoDB calls in this branch. Or maybe for the client we can leave the sync methods? Thoughts?
@StorytellerCZ I think it would make sense to leave sync methods for the client. This is consistent with other packages like Accounts isn't it ? Thanks
Synchronous Mongo calls on the client side are alright in Meteor 3.0, IIRC. When is this PR expected to be merged in and published? I would love to test this in my application.
Once this is merged: https://github.com/Meteor-Community-Packages/meteor-roles/pull/344
I will release a beta.
I would suggest updating the userIsInRole
function on like 658 of roles_common.js
to:
userIsInRole: async function (user, roles, options) {
let id
options = Roles._normalizeOptions(options)
// ensure array to simplify code
if (!Array.isArray(roles)) roles = [roles]
roles = roles.filter(r => r != null)
if (!roles.length) return false
Roles._checkScopeName(options.scope)
options = Object.assign({
anyScope: false
}, options)
if (user && typeof user === 'object') {
id = user._id
} else {
id = user
}
if (!id) return false
if (typeof id !== 'string') return false
const selector = { 'user._id': id }
if (!options.anyScope) {
selector.scope = { $in: [options.scope, null] }
}
const promises = roles.map((roleName) => {
selector['inheritedRoles._id'] = roleName
return Meteor.roleAssignment.find(selector, { limit: 1 }).countAsync() > 0
})
await Promise.all(promises)
return promises.some(p => p)
},
For obvious reasons, the method needs to become async to be able to count how many records are in the collection.
@dallman2 PRs welcome.
Published alanning:roles@4.0.0-alpha.1, please take things out for a spin. It is Meteor 3.0-beta.7 compatible!
Tests fixed, just trying one little thing for better hopefully better performance.
@jankapunkt @harryadel can I get a check on this from you, so that we can do the release? Many thanks!
Anything else for release? @jankapunkt @harryadel
console.debug
for debugging messagesRolesCollection
andRoleAssignmentsCollection
can now be exported in addition to being accessed viaMeteor.roles
andMeteor.roleAssignment