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

Update users' current_group on group deletion #16809

Merged
merged 7 commits into from
Jan 17, 2018

Conversation

lgalis
Copy link
Contributor

@lgalis lgalis commented Jan 11, 2018

When deleting a group, update the current_group for users that have the deleted group as the current_group

Links

https://bugzilla.redhat.com/show_bug.cgi?id=1264967

Steps for Testing/QA

  1. Create 1 new group
  2. Create 1 or new 2 users and assign them to the newly created group plus one additional group each.
  3. Make sure the new group is the current group for at least one of the users.
  4. Delete the group create in step1.

The user that had the current_group set to the new group can log in with the changes in this PR, as its new current_group is the second group it belonged to.

@lgalis lgalis force-pushed the update_user_login_group_on_deletion branch from 86363a6 to cccef2d Compare January 11, 2018 21:25
@lgalis lgalis changed the title [WIP] Update user current_group on group deletion [WIP] Update users' current_group on group deletion Jan 11, 2018
@miq-bot miq-bot added the wip label Jan 11, 2018
@lgalis lgalis force-pushed the update_user_login_group_on_deletion branch from cccef2d to 10d2205 Compare January 14, 2018 12:06
@lgalis lgalis changed the title [WIP] Update users' current_group on group deletion Update users' current_group on group deletion Jan 15, 2018
@lgalis lgalis changed the title Update users' current_group on group deletion [WIP] Update users' current_group on group deletion Jan 15, 2018
@lgalis
Copy link
Contributor Author

lgalis commented Jan 15, 2018

@lpichler , @gtanzillo - please review

@lgalis
Copy link
Contributor Author

lgalis commented Jan 15, 2018

@miq-bot add_label bug, gaprindashvili/yes, blocker

@JPrause
Copy link
Member

JPrause commented Jan 16, 2018

@lpichler @gtanzillo as this involves a blocker issue, can this be reviewed asap.

@lpichler
Copy link
Contributor

@JPrause I am working on it 👍

end

def reset_current_group_for_users
User.where(:current_group_id => id).each {|u| u.change_current_group(id)}
Copy link
Contributor

@lpichler lpichler Jan 16, 2018

Choose a reason for hiding this comment

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

it looks like we have method for it already User#current_group_by_description

group2 = FactoryGirl.create(:miq_group)
FactoryGirl.create(:user, :miq_groups => [group, group2], :current_group => group2)
FactoryGirl.create(:user, :miq_groups => [group, group2], :current_group => group)
expect { expect { group.destroy }.to raise_error(RuntimeError, /The group is the login group for at least one user in the group/) }.to_not change { MiqGroup.count }
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't succeed because both users are members of another group and you new logic would switch to current_group to group2 for the second user?

Copy link
Contributor

@lpichler lpichler left a comment

Choose a reason for hiding this comment

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

discussed with @lgalis and LGTM 👍

@lgalis lgalis changed the title [WIP] Update users' current_group on group deletion Update users' current_group on group deletion Jan 16, 2018
@miq-bot miq-bot removed the wip label Jan 16, 2018
def change_current_group(id)
user_groups = miq_group_ids
user_groups.delete(id)
raise _("The user's loging group cannot be changed.") if user_groups.empty?
Copy link
Member

Choose a reason for hiding this comment

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

Is there a typo in this error message?

It looks like this would be the case when the user's only group would be the one deleted.
What is a "loging" group? Even if that's supposed to be "login group" I'm still not sure what that means.

def ensure_can_be_destroyed
raise _("The login group cannot be deleted") if current_user_group?
raise _("The group has users assigned that do not belong to any other group") if single_group_users?
raise _("A tenant default group can not be deleted") if tenant_group? && referenced_by_tenant?
raise _("A read only group cannot be deleted.") if system_group?
reset_current_group_for_users if current_group_for_any_user?
Copy link
Member

@carbonin carbonin Jan 16, 2018

Choose a reason for hiding this comment

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

This is a strange side effect of a method that seems to be checking if a group is allowed to be destroyed.

The way this is written it feels like this should be two separate steps:

  • Ensure that the group in question is not the only group assigned to any user
  • When (or just before) the group is actually being removed (not in this method), reassign the current group.

Copy link
Member

Choose a reason for hiding this comment

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

Ensure that the group in question is not the only group assigned to any user

Ah I see that this check is being done by the line above with if single_group_users?, but I still feel like we could add another hook for this, maybe after_destroy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did consider that, however, the group should not be destroyed if the current_group cannot be changed for any user that has this as the current_group.

Copy link
Member

Choose a reason for hiding this comment

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

As I read it the only reason the current_group would not be able to be changed is if a user had no other group to change to. This case is already covered by another assertion already in this method, so I don't see any reason this can't be moved.

Copy link
Contributor Author

@lgalis lgalis Jan 17, 2018

Choose a reason for hiding this comment

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

I moved the changing of the current_group for the users that requires it to the after_destroy.

@lgalis lgalis force-pushed the update_user_login_group_on_deletion branch 3 times, most recently from dd317da to 105e7a6 Compare January 17, 2018 11:21
@lgalis lgalis force-pushed the update_user_login_group_on_deletion branch from 105e7a6 to e876972 Compare January 17, 2018 14:45
@lgalis lgalis changed the title Update users' current_group on group deletion [WIP]Update users' current_group on group deletion Jan 17, 2018
@lgalis lgalis force-pushed the update_user_login_group_on_deletion branch from e876972 to 2670de6 Compare January 17, 2018 15:02
@lgalis lgalis changed the title [WIP]Update users' current_group on group deletion Update users' current_group on group deletion Jan 17, 2018
@lgalis lgalis force-pushed the update_user_login_group_on_deletion branch from 27caac8 to ab7229b Compare January 17, 2018 16:00
@lgalis lgalis force-pushed the update_user_login_group_on_deletion branch from ab7229b to d029675 Compare January 17, 2018 16:21
@lgalis lgalis force-pushed the update_user_login_group_on_deletion branch from d029675 to a615f97 Compare January 17, 2018 19:16
@miq-bot
Copy link
Member

miq-bot commented Jan 17, 2018

Checked commits lgalis/manageiq@2939ab3~...a615f97 with ruby 2.3.3, rubocop 0.52.0, haml-lint 0.20.0, and yamllint 1.10.0
4 files checked, 0 offenses detected
Everything looks fine. 🍰

Copy link
Member

@gtanzillo gtanzillo left a comment

Choose a reason for hiding this comment

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

👍 LGTM

@gtanzillo
Copy link
Member

@carbonin Are you good with this PR at this point?

Copy link
Member

@carbonin carbonin left a comment

Choose a reason for hiding this comment

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

This looks great! 👍

@gtanzillo gtanzillo added this to the Sprint 78 Ending Jan 29, 2018 milestone Jan 17, 2018
@gtanzillo gtanzillo merged commit abc4775 into ManageIQ:master Jan 17, 2018
@lgalis lgalis deleted the update_user_login_group_on_deletion branch January 17, 2018 20:17
simaishi pushed a commit that referenced this pull request Jan 18, 2018
@simaishi
Copy link
Contributor

Gaprindashvili backport details:

$ git log -1
commit 90adee097c739ce6091f4678a57bd411a31839dd
Author: Gregg Tanzillo <[email protected]>
Date:   Wed Jan 17 15:04:35 2018 -0500

    Merge pull request #16809 from lgalis/update_user_login_group_on_deletion
    
    Update users' current_group on group  deletion
    (cherry picked from commit abc4775d630e06a363827f60a58ecae9b3e68e6f)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1536035

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.

7 participants