Skip to content

Version 4#379

Merged
jankapunkt merged 55 commits intomasterfrom
v4
Sep 5, 2024
Merged

Version 4#379
jankapunkt merged 55 commits intomasterfrom
v4

Conversation

@StorytellerCZ
Copy link
Copy Markdown
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
Copy Markdown
Member

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

@StorytellerCZ
Copy link
Copy Markdown
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
Copy Markdown

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
Copy Markdown

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
Copy Markdown
Member Author

Once this is merged:
#344

I will release a beta.

@dallman2
Copy link
Copy Markdown

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
Copy Markdown
Member Author

@dallman2 PRs welcome.

@StorytellerCZ StorytellerCZ force-pushed the v4 branch 2 times, most recently from 30b4352 to 4bb9684 Compare July 22, 2024 14:28
@StorytellerCZ StorytellerCZ requested a review from harryadel July 22, 2024 16:14
Comment thread roles/roles_client.js Outdated
}, options)

const result = Meteor.roles.upsert({ _id: roleName }, { $setOnInsert: { children: [] } })
const result = RolesCollection.upsert({ _id: roleName }, { $setOnInsert: { children: [] } })
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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!

Comment thread package.js Outdated
Comment thread roles/roles_server.js
@StorytellerCZ
Copy link
Copy Markdown
Member Author

Anything else for release? @jankapunkt @harryadel

Comment thread .github/workflows/testsuite.yml Outdated
Copy link
Copy Markdown
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.

Comment thread testapp/.meteor/release
@jankapunkt jankapunkt merged commit f7827cf into master Sep 5, 2024
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