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

Fixes #16363 - fix taxable user deletion #4879

Merged
merged 1 commit into from
Oct 31, 2017

Conversation

ares
Copy link
Member

@ares ares commented Sep 27, 2017

Reproducing steps:

as admin:

  1. create a user and assign him some organization
  2. create user group and assign this new user to this user group
  3. switch context to this org, do not remain in Any Context where all works
  4. try deleting the user
  5. see the error

with this fix, the user gets deleted

technical details:
belongs_to respects the default scope which unfortunately is used by taxonomies, therefore when member is being loaded, it fails resulting in member being nil. When it's later passed to find_all_affected_users_for, it fails since nil is unknown member type. In this case we need to skip taxonomies verification. Sadly we can't use any of common tricks since this is a polymorphic associations.

belongs_to :member, -> { unscope(:where) }, :polymorphic => true does not work since it also reset the where defined by polymorphic part, taxonomix does not define any named scope, just where("id IN ...")

@theforeman-bot
Copy link
Member

Issues: #16363

raise "Unknown member type #{member_type}"
end
end
alias_method_chain :member, :unscoped
Copy link
Contributor

Choose a reason for hiding this comment

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

alias_method_chain will be gone in Rails 5.1, see 3896497

@ares ares force-pushed the fix/16363 branch 2 times, most recently from ef9f33c to e22b5ae Compare October 10, 2017 13:14
@tstrachota
Copy link
Member

👍 for both the code and functionality. I tested the patch today and it works nicely.

Copy link
Member

@timogoebel timogoebel left a comment

Choose a reason for hiding this comment

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

@ares: Looks good, just one small comment.

when 'Usergroup'
Usergroup.unscoped { super }
else
raise "Unknown member type #{member_type}"
Copy link
Member

Choose a reason for hiding this comment

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

... Foreman::Exception.new() ?

Copy link
Member

Choose a reason for hiding this comment

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

Good catch. We raise it as ArgumentError on two other locations in this file. Whatever exception type we use, we should be consistent.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, I changed the exception to ArgumentError since this is an internal exception for devs, not really for users.

Copy link

@houndci-bot houndci-bot left a comment

Choose a reason for hiding this comment

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

Some files could not be reviewed due to errors:

.rubocop.yml: Style/FileName has the wrong namespace - should be Naming
.rubocop.yml: Style/FileName has the wrong namespace - should be Naming
.rubocop.yml: Style/PredicateName has the wrong namespace - should be Naming
.rubocop.yml: Style/AccessorMethodName has the wrong namespace - should be Naming
.rubocop.yml: Style/MethodName has the wrong namespace - should be Naming
.rubocop.yml: Style/VariableNumber has the wrong namespace - should be Naming
Error: The `Style/OpMethod` cop has been renamed and moved to `Naming/BinaryOperatorParameterName`.
(obsolete configuration found in .rubocop.yml, please update it)

@timogoebel
Copy link
Member

@ares: Can you rebase please to fix the test failures? Thanks.

@ares
Copy link
Member Author

ares commented Oct 27, 2017

rebased

@mmoll
Copy link
Contributor

mmoll commented Oct 27, 2017

test failures related ;)

@ares
Copy link
Member Author

ares commented Oct 27, 2017

ah I accidentally pushed older version from a different computer, should be good now

@timogoebel
Copy link
Member

@ares: Before I merge this, one final question, just to make sure: Is there a case when member_type might be nil?

@ares
Copy link
Member Author

ares commented Oct 31, 2017

no, I'm not aware such case, it's always user or user group

@timogoebel timogoebel merged commit 0ddaffe into theforeman:develop Oct 31, 2017
@timogoebel
Copy link
Member

Merged, thanks @ares and @tstrachota.

I'll put this on 1.17, but feel free to put it in 1.16 at your own discretion.

@ares
Copy link
Member Author

ares commented Oct 31, 2017

Thanks, I think it's fine to keep for 1.17, it's not 1.16 regression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants