-
Notifications
You must be signed in to change notification settings - Fork 902
[WIP] Fix widget sets with orphaned group #23404
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
base: master
Are you sure you want to change the base?
[WIP] Fix widget sets with orphaned group #23404
Conversation
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.
Good stuff
@@ -342,6 +342,10 @@ def current_user_group? | |||
id == current_user_group.try(:id) | |||
end | |||
|
|||
def destroy_subscribed_widget_sets | |||
MiqWidgetSet.where(:group_id => id).destroy_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.
So if we delete this group, a user widget set will probably want to stick around.
So if user_id
is around, want to figure out the user's new group and set the widget set's group to the user's new set?
--
I do want a test around user_id and group_id set
next unless groups_by_id.key?(k) # Make sure the group associated with a widget set / dashboard hasn't been removed | ||
|
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.
Won't the next line (blank) take care of some of this.
psudo code - have not tested yet (will revsit when we ask questions) Widget Setcurrent table
--- users that have dashboard (that is not in the list of the user's groups)
SELECT miq_sets.id, miq_sets.name, miq_sets.read_only,
miq_sets.owner_type, miq_sets.owner_id, miq_sets.userid, miq_sets.group_id
FROM miq_sets
WHERE
miq_sets.set_type = 'MiqWidgetSet'
AND miq_sets.userid IS NOT NULL
AND (
-- invalid user
(
NOT EXISTS (SELECT 1 FROM users WHERE users.userid = userid)
-- invalid group
) OR (
NOT EXISTS (
SELECT 1 FROM users
join miq_groups_users on users.id = miq_groups_users.user_id
WHERE users.userid = miq_sets.userid and miq_groups_users.miq_group_id = miq_sets.group_id
)
)
)
ORDER BY userid, group_id;
--- sanity check: groups the users are in
SELECT users.id, users.userid, miq_groups_users.miq_group_id, miq_groups.description
FROM users
JOIN miq_groups_users on users.id = miq_groups_users.user_id
JOIN miq_groups ON miq_groups.id = miq_groups_users.miq_group_id
WHERE users.userid in (select userid from miq_sets where set_type = 'MiqWidgetSet')
ORDER by users.userid; Actionsremove group from a user
delete user
delete group
|
ok, updated queries to point to |
A revised version the above pseudo code was tested to verify the dashboards for invalid users, users no longer in the group (group exists but user isn't in it anymore or group does NOT exist). DELETE FROM miq_sets
WHERE
miq_sets.set_type = 'MiqWidgetSet'
AND miq_sets.userid IS NOT NULL
AND (
-- invalid user
(
NOT EXISTS (SELECT 1 FROM users WHERE users.userid = userid)
-- invalid group
) OR (
NOT EXISTS (
SELECT 1 FROM users
join miq_groups_users on users.id = miq_groups_users.user_id
WHERE users.userid = miq_sets.userid and miq_groups_users.miq_group_id = miq_sets.group_id
)
)
); For followup, here and elsewhere, we'll need to:
|
These probably will need to be done async to deleting the user/group, maybe as a callback it's put on the queue or maybe we create a purger.
Probably for any existing ones, but maybe a purger is more appropriate to keep it clean in an ongoing manner? I think there needs to be a 3.5 for dealing with deleting groups. |
Good point. That's the original code for this PR so I neglected to put it. EDIT: Edited the comment above to remember it when I return. |
TODO: I have no idea why we have ownership AND group association for a widget set and why the owner can be nil and the group pointing to an orphaned group id. This is fixing the symptoms but not really solving the problem yet. We need to understand why these things were happening and how to properly fix it going forward.