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 #32415 - access only through SettingRegistry #8465

Merged
merged 1 commit into from Jul 23, 2021

Conversation

ezr-ondrej
Copy link
Member

@ezr-ondrej ezr-ondrej commented Apr 24, 2021

Update and read the settings through SettingRegistry.
Adds a layer between controller and Model.
SettingRegistry is proxying the value parsing method to the model.

This lifts blocker for settings without DB record.

Blocked by #8438

@theforeman-bot
Copy link
Member

Issues: #32415

@ezr-ondrej ezr-ondrej changed the title Fixes #32415 - update only through SettingRegistry Fixes #32415 - access only through SettingRegistry Apr 24, 2021
@ezr-ondrej ezr-ondrej force-pushed the setting_registry_update branch 2 times, most recently from bc37989 to fe17545 Compare April 25, 2021 17:49
@lzap
Copy link
Member

lzap commented May 11, 2021

Merged the blocking PR, please rebase.

@theforeman-bot
Copy link
Member

@ezr-ondrej, this pull request is currently not mergeable. Please rebase against the develop branch and push again.

If you have a remote called 'upstream' that points to this repository, you can do this by running:

    $ git pull --rebase upstream develop

This message was auto-generated by Foreman's prprocessor

@ezr-ondrej
Copy link
Member Author

[test katello]

@ezr-ondrej
Copy link
Member Author

We are green here for some time, do I need to do anything to get this one merged? :)

Comment on lines 76 to 78
# rubocop:disable Style/DoubleNegation
case (!!value == value ? 'boolean' : value.class.to_s.downcase)
# rubocop:enable Style/DoubleNegation
Copy link
Member

Choose a reason for hiding this comment

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

It still surprises me that Ruby doesn't have a Boolean.new(value) method (or similar) to force it as a boolean.

That said: why isn't checking for trueclass / falseclass no longer the right thing?

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 was looking for something shorter, this works the best from what I found and is much easier to read IMHO.
But both are fine, this is shorter. If you think checking for two classes was better, I'm ok with that as well :)

Copy link
Member

Choose a reason for hiding this comment

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

To me that was easier to understand as a reader. I'm not used to reading !! and the fact Rubocop disables it by default probably also means something.

Copy link
Member Author

Choose a reason for hiding this comment

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

Back to using the trueclass and falseclass now :)

@ezr-ondrej ezr-ondrej force-pushed the setting_registry_update branch 4 times, most recently from 495e7b8 to 676ed86 Compare July 1, 2021 23:42
lzap
lzap previously approved these changes Jul 22, 2021
Copy link
Member

@lzap lzap left a comment

Choose a reason for hiding this comment

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

I tested editing of core and discovery settings. I have no comments on the code, perhaps someone with more RoR experience could waive the changes.

@ezr-ondrej
Copy link
Member Author

@tbrisker could you give it a look pls? :)

Copy link
Member

@ares ares left a comment

Choose a reason for hiding this comment

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

One tiny change and we're good to go


def set_user_value(name, value)
definition = find(name)
raise ActiveRecord::RecordNotFound.new(_("Setting definition for '%s' not found, can not set") % name, Setting, name) unless definition
Copy link
Member

Choose a reason for hiding this comment

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

N_() instead of _()

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not foreman exception, but ActiveRecord, so we need to translate here.

when db_record.settings_type
db_record.value = value
else
raise ::Foreman::Exception.new(N_('expected a value of type %s'), @setting.settings_type)
Copy link
Member

@ekohl ekohl Jul 23, 2021

Choose a reason for hiding this comment

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

You don't need to perform the interpolation of %s here?

Edit: never mind, looks from other code that this is correct.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, this is correct, the interpolation is for recordnotfound execption, that doesn't do any translation for message.
So the Marek's change request was also wrong, getting it back.

Update and read the settings through SettingRegistry.
Adds a layer between controller and Model.
SettingRegistry is proxying the value parsing method to the model.

This lifts blocker for settings without DB record.
@ares
Copy link
Member

ares commented Jul 23, 2021

All green, thanks @ezr-ondrej and sorry for turning you wrong direction. Merging!

@ares ares merged commit 3ff1fd2 into theforeman:develop Jul 23, 2021
@ezr-ondrej ezr-ondrej deleted the setting_registry_update branch July 25, 2021 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants