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

Fixes #31165 - sync usergroups only for given user #8204

Merged
merged 1 commit into from
Dec 24, 2020

Conversation

ezr-ondrej
Copy link
Member

@ezr-ondrej ezr-ondrej commented Dec 15, 2020

In 17c4b47 we've disabled synchronization of groups for user from different auth sources.
That gave us oportunity to sync the groups directly from fetched groups.

This is changing the Auditing of group membership, as of now it is being audited as User update, not Usergroup update.

See #6388 for previous change - we kept back there and didn't want to regress usage of synchronization of groups from two authsources for given user, but that should not be a valid case and the speedup is significat if we don't support it.

@ezr-ondrej ezr-ondrej changed the title Fixes #31165 - sync usergroups only for given user 🐎 Fixes #31165 - sync usergroups only for given user Dec 15, 2020
@theforeman-bot
Copy link
Member

Issues: #31165

@@ -134,15 +134,14 @@ def update_usergroups(login)
.where(ExternalUsergroup.arel_table[:auth_source_id].eq(id))
.pluck(:id)
Copy link
Member

Choose a reason for hiding this comment

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

Non blocking suggestion:
perhaps this should be called current_external_ids so it's clearer?
You could get rid of the joins and arel here with something like:

current_external_ids = user.usergroups
                            .where(id: ExternalUsergroup.where(auth_source_id: id).select(:usergroup_id))
                            .pluck(:id)

Usergroup.where(id: usergroup_ids.uniq).find_each do |usergroup|
refresh_usergroup_members(usergroup)
end
external_mapping_ids = ExternalUsergroup.where(auth_source_id: id)
Copy link
Member

Choose a reason for hiding this comment

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

if we rename the variables to be more descriptive, this would perhaps be updated_external_ids?

Copy link
Member Author

Choose a reason for hiding this comment

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

updated dosn't sound correct as those are ALL not just UPDATED ids 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

I went with actual_external_ids ... ?

Copy link
Member Author

Choose a reason for hiding this comment

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

OR correct_external_ids ?

Comment on lines 141 to 142
user.usergroup_ids -= (usergroup_ids - external_mapping_ids)
user.usergroup_ids += (external_mapping_ids - usergroup_ids)
Copy link
Member

Choose a reason for hiding this comment

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

How about:

Suggested change
user.usergroup_ids -= (usergroup_ids - external_mapping_ids)
user.usergroup_ids += (external_mapping_ids - usergroup_ids)
user.usergroup_ids = user.usergroup_ids - current_external_ids + updated_external_ids

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice 👍

app/models/auth_sources/auth_source_ldap.rb Outdated Show resolved Hide resolved
@ezr-ondrej
Copy link
Member Author

Note I've added one more test to cover the auditing (as I was not 100% sure it works without validation) :)

In @17c4b47 we've disabled synchronization of groups for user from different auth sources.
That gave us oportunity to sync the groups directly from fetched groups.

This is changing the Auditing of group membership, as of now it is being audited as User update, not Usergroup update.
Copy link
Member

@tbrisker tbrisker left a comment

Choose a reason for hiding this comment

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

Thanks @ezr-ondrej !

@tbrisker tbrisker merged commit db56f2a into theforeman:develop Dec 24, 2020
@ezr-ondrej ezr-ondrej deleted the ldap_sync_slow_on_login branch December 24, 2020 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants