meteor-roles icon indicating copy to clipboard operation
meteor-roles copied to clipboard

Version 4

Open StorytellerCZ opened this issue 2 years ago • 11 comments

  • BREAKING: Synchronous functions are now available only on client side
  • BREAKING: Migration functions for past versions are no longer available
  • UI Helpers now use console.debug for debugging messages
  • RolesCollection and RoleAssignmentsCollection can now be exported in addition to being accessed via Meteor.roles and Meteor.roleAssignment

StorytellerCZ avatar Aug 24 '23 10:08 StorytellerCZ

@StorytellerCZ is there anything that isn't already implemented by the latest release that contains the async counterparts?

jankapunkt avatar Dec 22 '23 08:12 jankapunkt

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 avatar Dec 22 '23 09:12 StorytellerCZ

@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

tchax avatar Dec 27 '23 18:12 tchax

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.

dallman2 avatar Feb 07 '24 20:02 dallman2

Once this is merged: https://github.com/Meteor-Community-Packages/meteor-roles/pull/344

I will release a beta.

StorytellerCZ avatar Feb 09 '24 10:02 StorytellerCZ

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 avatar Mar 05 '24 21:03 dallman2

@dallman2 PRs welcome.

StorytellerCZ avatar Mar 06 '24 17:03 StorytellerCZ

Published alanning:[email protected], please take things out for a spin. It is Meteor 3.0-beta.7 compatible!

StorytellerCZ avatar Apr 08 '24 15:04 StorytellerCZ

Tests fixed, just trying one little thing for better hopefully better performance.

StorytellerCZ avatar Jul 22 '24 13:07 StorytellerCZ