Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 4 #379

Draft
wants to merge 31 commits into
base: master
Choose a base branch
from
Draft

Version 4 #379

wants to merge 31 commits into from

Conversation

StorytellerCZ
Copy link
Member

@StorytellerCZ StorytellerCZ commented Aug 24, 2023

  • 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 StorytellerCZ added this to the Release 4.0 milestone Sep 23, 2023
@jankapunkt
Copy link
Member

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

@StorytellerCZ
Copy link
Member Author

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?

@tchax
Copy link

tchax commented Dec 27, 2023

@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

@dallman2
Copy link

dallman2 commented Feb 7, 2024

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.

@StorytellerCZ
Copy link
Member Author

Once this is merged:
#344

I will release a beta.

@dallman2
Copy link

dallman2 commented Mar 5, 2024

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.

@StorytellerCZ
Copy link
Member Author

@dallman2 PRs welcome.

@StorytellerCZ
Copy link
Member Author

Published alanning:roles@4.0.0-alpha.1, please take things out for a spin. It is Meteor 3.0-beta.7 compatible!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants