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

Add Roles field to OrganizationMember struct #293

Merged

Conversation

renxinhe
Copy link
Contributor

🔧 Changes

  • Added Roles field to OrganizationMember such that fetching roles with organization API /get_members endpoint would also return the user roles when requested.

📚 References

Issue: #291

🔬 Testing

Ran all the existing tests and all passing locally:

[.venv] jim@jim-dev-2-vm:~/go-auth0 (main) 
$ make test
==> Running tests with http recordings...
ok      github.com/auth0/go-auth0       0.014s  coverage: 95.2% of statements
?       github.com/auth0/go-auth0/authentication/database       [no test files]
?       github.com/auth0/go-auth0/authentication/oauth  [no test files]
?       github.com/auth0/go-auth0/authentication/passwordless   [no test files]
ok      github.com/auth0/go-auth0/authentication        0.953s  coverage: 90.4% of statements
ok      github.com/auth0/go-auth0/internal/client       11.888s coverage: 69.4% of statements
ok      github.com/auth0/go-auth0/internal/idtokenvalidator     0.038s  coverage: 95.1% of statements
ok      github.com/auth0/go-auth0/internal/tag  0.004s  coverage: 100.0% of statements
ok      github.com/auth0/go-auth0/management    21.204s coverage: 97.4% of statements

I also tested manually by calling Member() and observed that the new Roles slice is indeed populated with the role name and IDs.

Here is an example HTTP response from Auth0 management API. Note that the field is called roles, and Go's json:roles,omitempty syntax is able to automatically unmarshall it.

[
  {
    "user_id": "google-oauth2|123456789",
    "name": "John Doe",
    "email": "john@example",
    "roles": [
      {
        "id": "rol_exampleRoleID1",
        "name": "Role 1"
      },
      {
        "id": "rol_exampleRoleID2",
        "name": "Role 2"
      }
    ]
  }
]

📝 Checklist

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

@renxinhe renxinhe requested a review from a team as a code owner October 18, 2023 02:19
@ewanharris
Copy link
Contributor

Thanks for the PR @renxinhe! I had started adding this and hadn't got round to the PR yet.

I don't want to close this though so you mind if I push some changes to your PR? It's just some minor changes around the struct (as description is missing) and documentation

@renxinhe
Copy link
Contributor Author

Thanks for the PR @renxinhe! I had started adding this and hadn't got round to the PR yet.

I don't want to close this though so you mind if I push some changes to your PR? It's just some minor changes around the struct (as description is missing) and documentation

Hey not at all! You do whatever you need to; I'm just happy to help. Right now our code is hitting a lot of rate limit issue since we have to fetch all the users' roles one by one. Hope we can patch this one - luckily the Go struct annotation makes this change fairly simple. Thanks a lot! :)

@renxinhe
Copy link
Contributor Author

renxinhe commented Oct 19, 2023

I augmented TestOrganizationManager_Members to also verify that we are fetching the roles correctly in Members(): 9d1d424

All tests still passing:

$ make test
==> Running tests with http recordings...
ok      github.com/auth0/go-auth0       0.007s  coverage: 95.2% of statements
?       github.com/auth0/go-auth0/authentication/database       [no test files]
?       github.com/auth0/go-auth0/authentication/oauth  [no test files]
?       github.com/auth0/go-auth0/authentication/passwordless   [no test files]
ok      github.com/auth0/go-auth0/authentication        1.106s  coverage: 90.4% of statements
ok      github.com/auth0/go-auth0/internal/client       12.223s coverage: 69.4% of statements
ok      github.com/auth0/go-auth0/internal/idtokenvalidator     0.049s  coverage: 95.1% of statements
ok      github.com/auth0/go-auth0/internal/tag  0.031s  coverage: 100.0% of statements
ok      github.com/auth0/go-auth0/management    20.932s coverage: 97.4% of statements

Copy link
Contributor

@ewanharris ewanharris left a comment

Choose a reason for hiding this comment

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

Thanks for this @renxinhe!

We have some other changes that I'd like to release alongside this, but I'm hopeful this should be out mid to late next week.

@ewanharris ewanharris merged commit 6aa68cc into auth0:main Oct 20, 2023
6 checks passed
@renxinhe renxinhe deleted the feature/add-roles-to-organization-member branch October 23, 2023 17:06
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.

2 participants