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

Merged
merged 55 commits into from
Sep 5, 2024
Merged

Version 4 #379

merged 55 commits into from
Sep 5, 2024

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
  • Removed deprecated publication of legacy role assignments
  • 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
  • Support for Meteor 3

@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.

@@ -69,7 +65,7 @@ Object.assign(Roles, {
unlessExists: false
}, options)

const result = Meteor.roles.upsert({ _id: roleName }, { $setOnInsert: { children: [] } })
const result = RolesCollection.upsert({ _id: roleName }, { $setOnInsert: { children: [] } })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is breaking all our tests:

  1. If we directly replace Meteor.Roles it will not apply this internal collection. We also can no longer check if a role is created using Meteor.roles.countDocuments
  2. If we use hwillston:stub-collections we can only test for integration and not manully stub specific methods for unit tests. This was possible when Meteor.roles was used.

Copy link
Member Author

@StorytellerCZ StorytellerCZ Jul 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Meteor.roles is still applied and unchanged, but you can now import he RolesCollection as well from the package. See roles_common_async.js.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jankapunkt please give this a look in the latest push, I have reverted to using the Meteor object for collection access.

@StorytellerCZ
Copy link
Member Author

StorytellerCZ commented Aug 30, 2024

@jankapunkt @harryadel can I get a check on this from you, so that we can do the release? Many thanks!

package.js Outdated Show resolved Hide resolved
roles/roles_server.js Show resolved Hide resolved
@StorytellerCZ
Copy link
Member Author

Anything else for release? @jankapunkt @harryadel

Copy link
Member

@harryadel harryadel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very few nitpicks, feel free to disregard if you don't agree.

testapp/.meteor/release Show resolved Hide resolved
@jankapunkt jankapunkt merged commit f7827cf into master Sep 5, 2024
5 checks passed
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.

5 participants