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

Adding data integrity constrains for some associations to User model #18472

Merged

Conversation

yrudman
Copy link
Contributor

@yrudman yrudman commented Feb 20, 2019

Issue: It is currently possible to destroy user which still referred to from other models

Fix: before_destroy callback canceling destroy if user refer to in other models

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

@miq-bot add-label bug, core

@yrudman yrudman force-pushed the prevent-user-deleting-if-user-present-somewere branch 2 times, most recently from c91e2e4 to ecb1e9f Compare February 20, 2019 22:15
@yrudman yrudman changed the title [WIP] Adding data integrity constrains for some associations to User model Adding data integrity constrains for some associations to User model Feb 21, 2019
@yrudman
Copy link
Contributor Author

yrudman commented Feb 21, 2019

@gtanzillo @jrafanie could you review

I am not sure which models should have this constrain

@miq-bot miq-bot removed the wip label Feb 21, 2019
Copy link
Member

@jrafanie jrafanie left a comment

Choose a reason for hiding this comment

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

I have some comments on the existing code but a general question... does this mean you can't delete a user with existing requests or vms? Will that cause other problems if we allowed that in the past?

app/models/user.rb Outdated Show resolved Hide resolved
app/models/user.rb Outdated Show resolved Hide resolved
app/models/user.rb Outdated Show resolved Hide resolved
app/models/user.rb Outdated Show resolved Hide resolved
@yrudman yrudman force-pushed the prevent-user-deleting-if-user-present-somewere branch from 1e1aa44 to 6540d00 Compare February 21, 2019 20:36
@gtanzillo
Copy link
Member

@yrudman @jrafanie I think we need some further discussion on this one. It feels like this change is definitely necessary to safeguard against deleting a user and breaking references leading to the originally reported bug.

But i see you point that this could prevent a user from ever getting deleted. I'm not sure if that's such a bad thing , though.

If we add the ability to reassign the referenced objects to another user, it may open another can of worms with groups, roles and RBAC. Not sure.

end

unless present_ref.empty?
errors.add(:base, "user with id [#{id}] has references to other models: #{present_ref.join(" ")}")
Copy link
Member

Choose a reason for hiding this comment

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

We should probably also mention the userid or name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@@ -110,6 +112,18 @@ def validate
before_validation :dummy_password_for_external_auth
before_destroy :destroy_subscribed_widget_sets

def check_reference
present_ref = []
%w(miq_requests vms miq_widgets miq_templates).each do |association|
Copy link
Member

Choose a reason for hiding this comment

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

I assume that the user will still have miq_widgets since this callback is being prepended and will run before :destroy_subscribed_widget_sets, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, this check will be executed first

@yrudman yrudman force-pushed the prevent-user-deleting-if-user-present-somewere branch from 6540d00 to 76614c7 Compare June 21, 2019 15:09
@yrudman yrudman force-pushed the prevent-user-deleting-if-user-present-somewere branch from 76614c7 to 3f04d3c Compare June 21, 2019 15:21
@miq-bot
Copy link
Member

miq-bot commented Jun 21, 2019

Checked commits yrudman/manageiq@2d63bc6~...0006000 with ruby 2.3.3, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0
3 files checked, 0 offenses detected
Everything looks fine. 👍

@bdunne
Copy link
Member

bdunne commented Jun 24, 2019

I have some comments on the existing code but a general question... does this mean you can't delete a user with existing requests or vms? Will that cause other problems if we allowed that in the past?

@jrafanie Any other thoughts here? I'm leaning toward merging this.

@bdunne bdunne merged commit e844881 into ManageIQ:master Jun 26, 2019
@bdunne bdunne self-assigned this Jun 26, 2019
@bdunne bdunne added this to the Sprint 115 Ending Jul 8, 2019 milestone Jun 26, 2019
@yrudman
Copy link
Contributor Author

yrudman commented Jun 26, 2019

@miq-bot add-label changelog/yes

@jrafanie
Copy link
Member

Yeah, I'm fine with this. We'll see what it breaks and change it if needed.

@yrudman yrudman deleted the prevent-user-deleting-if-user-present-somewere branch June 27, 2019 15:24
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.

5 participants