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

fix(current-user): allow custom fields in getUserGroups (DHIS2-10625) #280

Merged
merged 3 commits into from
Mar 9, 2021

Conversation

edoardo
Copy link
Member

@edoardo edoardo commented Mar 5, 2021

Improvement proposal for fixing DHIS2-10625.

This allows to override fields=:all to reduce the response size.
One example is the Interpretations component, where only the group ids
are actually needed.

See dhis2/d2-ui#685.

This allows to override fields=:all to reduce the response size.
One example is the Interpretations component, where only the group ids
are actually needed.
@edoardo edoardo removed the request for review from ismay March 8, 2021 09:20
Copy link
Contributor

@HendrikThePendric HendrikThePendric left a comment

Choose a reason for hiding this comment

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

Fixing things this way doesn't introduce breaking changes, so that's a good thing. However, this does obviously mean that everywhere in our code base we will have to start adding a fields arg to the call to getCurrentUser, because we should assume that getting all the users for a number of userGroups is going to cause a performance issue.

Perhaps we should include !users in the default fields filter?

(I'm just leaving a neutral review, because I'm not sure what would be best here)

@varl
Copy link
Contributor

varl commented Mar 8, 2021

I don't understand why the support for optional params means we have to start to add the fields arg to the getCurrentUser?

It looks like everything will work the same as it does today if listOptions isn't passed along as an argument.

Comment on lines +167 to +169
Object.assign({ paging: false }, listOptions, {
filter: [`id:in:[${userGroupIds.join(',')}]`],
})
Copy link
Contributor

Choose a reason for hiding this comment

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

If the intention is to allow overwriting the filter property, then the listOptions should be the last argument in the assign.

Copy link
Member Author

Choose a reason for hiding this comment

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

True, I used the same approach already in place for getOrganisationUnits.
I don't think the filter should be overridden, these methods are called like d2.currentUser.getUserGroups() which implies the groups returned are the ones where the current user belongs.

Copy link
Contributor

@HendrikThePendric HendrikThePendric Mar 8, 2021

Choose a reason for hiding this comment

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

I think you make a good point, but we probably need a slightly more nuanced solution:

{
    paging: false,
    ...listOptions,
    filter: [
        ...listOptions.filter,
        `id:in:[${userGroupIds.join(',')}]`,
     ]
 }   

My point: the part where we filter the userGroups on the user's userGroups should not be overwritten.

Note: when I wrote the above, Edoardo's comment was not visible yet.

@edoardo
Copy link
Member Author

edoardo commented Mar 8, 2021

Fixing things this way doesn't introduce breaking changes, so that's a good thing. However, this does obviously mean that everywhere in our code base we will have to start adding a fields arg to the call to getCurrentUser, because we should assume that getting all the users for a number of userGroups is going to cause a performance issue.

My approach here is to not introduce any breaking changes, as I don't know where and how these methods on d2.currentUser are used.

Perhaps we should include !users in the default fields filter?

That would be a breaking change.

@edoardo
Copy link
Member Author

edoardo commented Mar 8, 2021

BTW, I just came to realise that for the specific problem of the interpretations panel, the group ids required are already in d2.currentUser just hidden behind a Symbol.
I'm going to add a new method getUserGroupIds which simply returns that list:

getUserGroupIds() { return this[propertySymbols.userGroups]; }

I will update the Interpretation component and replace d2.currentUser.getUserGroups() with d2.currentUser.getUserGroupIds() and all the request to userGroups should be gone from that component.

@HendrikThePendric
Copy link
Contributor

My approach here is to not introduce any breaking changes, as I don't know where and how these methods on d2.currentUser are used.

Yeah, this was also why I didn't approve or request changes, I'm simply not sure what is best here.... Obviously not introducing breaking changes is a good thing. But in this case that actually means that everywhere we use this method without any fields as arg, we run the risk of crashing the server if there are many users.

Current user group ids are already available from the /me response.
Add a method for accessing them directly without making any api request.
In some cases the ids are all is needed (ie. Interpretations component).

Related to DHIS2-10625.
Copy link
Contributor

@janhenrikoverland janhenrikoverland left a comment

Choose a reason for hiding this comment

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

Looks like a good solution for now

@edoardo edoardo merged commit d3e84a6 into master Mar 9, 2021
@edoardo edoardo deleted the fix/allow-custom-fields-usergroups branch March 9, 2021 09:17
dhis2-bot added a commit that referenced this pull request Mar 9, 2021
## [31.9.1](v31.9.0...v31.9.1) (2021-03-09)

### Bug Fixes

* **current-user:** add getUserGroupIds, allow custom fields in getUserGroups (DHIS2-10625) ([#280](#280)) ([d3e84a6](d3e84a6))
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 31.9.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

5 participants