-
Notifications
You must be signed in to change notification settings - Fork 897
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
Allow deletion of groups with users belonging to other groups #15041
Conversation
5595336
to
9b3fa7b
Compare
@miq-bot add_label enhancement |
@lpichler, @gtanzillo - please review |
app/models/miq_group.rb
Outdated
own_users = [] | ||
users.each { |user| own_users << user if user.miq_groups.count == 1 } | ||
own_users | ||
end |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this 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:
- We can just refuse to delete of such group.
- We can reassign the other group to logged user.
- Logout.
thanks
@miq-bot add_label fine/yes |
17cc7f7
to
7eff596
Compare
app/models/miq_group.rb
Outdated
@@ -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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
6c88998
to
bc7b891
Compare
…p also belong to other groups
…the current login group
bc7b891
to
18e29cc
Compare
Checked commits lgalis/manageiq@7558f9f~...18e29cc with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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'
There was a problem hiding this comment.
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. 👍
Allow deletion of groups with users belonging to other groups (cherry picked from commit 828b50b) https://bugzilla.redhat.com/show_bug.cgi?id=1322396
Euwe backport details:
|
Allow deletion of groups with users belonging to other groups (cherry picked from commit 828b50b) https://bugzilla.redhat.com/show_bug.cgi?id=1460307
Fine backport details:
|
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