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

Allow deletion of groups with users belonging to other groups #15041

Merged
merged 3 commits into from
May 24, 2017

Conversation

lgalis
Copy link
Contributor

@lgalis lgalis commented May 9, 2017

Allow deletion of groups when all users within the group also belong to other groups.

Links

https://bugzilla.redhat.com/show_bug.cgi?id=1264967
https://www.pivotaltracker.com/n/projects/1613907/stories/131568585

@miq-bot miq-bot added the wip label May 9, 2017
@lgalis lgalis force-pushed the allow_not_empty_group_deletion branch 5 times, most recently from 5595336 to 9b3fa7b Compare May 11, 2017 20:11
@lgalis
Copy link
Contributor Author

lgalis commented May 11, 2017

@miq-bot add_label enhancement

@lgalis
Copy link
Contributor Author

lgalis commented May 11, 2017

@lpichler, @gtanzillo - please review

@lgalis lgalis changed the title [WIP] Allow deletion of groups with users belonging to other groups Allow deletion of groups with users belonging to other groups May 16, 2017
@miq-bot miq-bot removed the wip label May 16, 2017
own_users = []
users.each { |user| own_users << user if user.miq_groups.count == 1 }
own_users
end
Copy link
Member

Choose a reason for hiding this comment

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

I believe this can be more eloquent as

def own_users
  users.select { |user| user.miq_groups.count == 1 }
end

Copy link
Member

Choose a reason for hiding this comment

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

  def has_single_group_user?
    users.any? { |user| user.miq_groups.count == 1 }
  end

Naming is hard. Then below...

raise _("Still has users assigned.") if has_single_group_user? 

Copy link
Contributor

@lpichler lpichler May 17, 2017

Choose a reason for hiding this comment

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

I believe that we can remove N+1 here by this query:

  def users_assigned_to_other_groups?
    group_user_ids = user_ids
    User.includes(:miq_groups).where(:id => group_user_ids).where.not(:miq_groups => {:id => id}).count == group_user_ids.size
  end

which means:
select users of the group and elimited the users with the our group(which we want to delete)
and if all (comparing with == group_user_ids.size)users will belongs to any other groups than we can delete it.

also, I would like to change message to something more descriptive.

  raise _("All users don't belong to other groups  ") unless users_assigned_to_other_groups?

What do you think?

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.

@lgalis Tested with LDAP and works well and I added other suggestions.

Also, I found a bug.
When you are deleting group which is current group of users than the application is broken. After re-login application works and the other group is assigned as default.

But I am not sure what to do in this case:

  1. We can just refuse to delete of such group.
  2. We can reassign the other group to logged user.
  3. Logout.

thanks

@chrispy1
Copy link

@miq-bot add_label euwe/yes
@miq-bot add_label blocker

@chrispy1
Copy link

@miq-bot add_label fine/yes

@simaishi simaishi removed the blocker label May 17, 2017
@lgalis lgalis changed the title Allow deletion of groups with users belonging to other groups [WIP]Allow deletion of groups with users belonging to other groups May 18, 2017
@miq-bot miq-bot added the wip label May 18, 2017
@lgalis lgalis force-pushed the allow_not_empty_group_deletion branch 3 times, most recently from 17cc7f7 to 7eff596 Compare May 22, 2017 17:14
@lgalis lgalis changed the title [WIP]Allow deletion of groups with users belonging to other groups Allow deletion of groups with users belonging to other groups May 22, 2017
@lgalis
Copy link
Contributor Author

lgalis commented May 22, 2017

@lpichler, @jrafanie - please review again

@miq-bot miq-bot removed the wip label May 22, 2017
@@ -230,8 +230,18 @@ def validate_default_tenant
end
end

def single_group_users?
group_user_ids = user_ids
users.includes(:miq_groups).where(:id => group_user_ids).where.not(:miq_groups => {:id => id}).count != group_user_ids.size
Copy link
Member

Choose a reason for hiding this comment

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

Looks good to me, but we might want tests just for this method to ensure it does the right thing in a few different scenarios.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok - there are specs that cover different scenarios for deletion - but I can add specs for just this method as well.

@lgalis lgalis changed the title Allow deletion of groups with users belonging to other groups [WIP] Allow deletion of groups with users belonging to other groups May 22, 2017
@miq-bot miq-bot added the wip label May 22, 2017
@lgalis lgalis force-pushed the allow_not_empty_group_deletion branch 2 times, most recently from 6c88998 to bc7b891 Compare May 23, 2017 21:30
@lgalis lgalis force-pushed the allow_not_empty_group_deletion branch from bc7b891 to 18e29cc Compare May 24, 2017 03:28
@miq-bot
Copy link
Member

miq-bot commented May 24, 2017

Checked commits lgalis/manageiq@7558f9f~...18e29cc with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
3 files checked, 0 offenses detected
Everything looks fine. ⭐

@lgalis lgalis changed the title [WIP] Allow deletion of groups with users belonging to other groups Allow deletion of groups with users belonging to other groups May 24, 2017
@miq-bot miq-bot removed the wip label May 24, 2017
@lgalis
Copy link
Contributor Author

lgalis commented May 24, 2017

@lpichler , @jrafanie - requested changes made

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.

LGTM thanks @lgalis!

@@ -458,4 +467,35 @@
expect(group.user_count).to eq(2)
end
end

describe "#single_group_users?" do
it "returns false if all users in the group belong to an additional group" do
Copy link
Member

Choose a reason for hiding this comment

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

returns false if any users... right?

If it makes sense, please reword that in a followup PR.

Copy link
Contributor Author

@lgalis lgalis May 24, 2017

Choose a reason for hiding this comment

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

@jrafanie - all users need to belong to an additional group for the group to be deleted. I can say 'every' user in the group instead of 'all'

Copy link
Member

Choose a reason for hiding this comment

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

My bad, thanks @lgalis! I misread it. 👍

@jrafanie jrafanie merged commit 828b50b into ManageIQ:master May 24, 2017
@jrafanie jrafanie added this to the Sprint 62 Ending Jun 5, 2017 milestone May 24, 2017
simaishi pushed a commit that referenced this pull request May 24, 2017
Allow deletion of groups with users belonging to other groups
(cherry picked from commit 828b50b)

https://bugzilla.redhat.com/show_bug.cgi?id=1322396
@simaishi
Copy link
Contributor

Euwe backport details:

$ git log -1
commit 6dd942b66aa0f67a74acfc181ddd3c293bd8fdb7
Author: Joe Rafaniello <jrafanie@users.noreply.github.com>
Date:   Wed May 24 13:48:04 2017 -0400

    Merge pull request #15041 from lgalis/allow_not_empty_group_deletion
    
    Allow deletion of groups with users belonging to other groups
    (cherry picked from commit 828b50b82e5a7dedb2394e4db942bf1357360e6c)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1322396

simaishi pushed a commit that referenced this pull request Jun 9, 2017
Allow deletion of groups with users belonging to other groups
(cherry picked from commit 828b50b)

https://bugzilla.redhat.com/show_bug.cgi?id=1460307
@simaishi
Copy link
Contributor

simaishi commented Jun 9, 2017

Fine backport details:

$ git log -1
commit caa1b85a0d0ff8f73790a565843fc9866ec06aec
Author: Joe Rafaniello <jrafanie@users.noreply.github.com>
Date:   Wed May 24 13:48:04 2017 -0400

    Merge pull request #15041 from lgalis/allow_not_empty_group_deletion
    
    Allow deletion of groups with users belonging to other groups
    (cherry picked from commit 828b50b82e5a7dedb2394e4db942bf1357360e6c)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1460307

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