-
Notifications
You must be signed in to change notification settings - Fork 988
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 #15621 - WebUI: Cloned roles saved with nil builtin #3630
Fixes #15621 - WebUI: Cloned roles saved with nil builtin #3630
Conversation
7cec956
to
6c74f37
Compare
There were the following issues with the commit message:
If you don't have a ticket number, please create an issue in Redmine, selecting the appropriate project. More guidelines are available in Coding Standards or on the Foreman wiki. This message was auto-generated by Foreman's prprocessor |
@vision2910 Sorry but I can't reproduce this one. Check out this gif trying to reproduce it: I clone a builtin role, and it's properly displayed as not builtin. In the API (sorry I cropped the picture too much) it returns a 0! Is that what you're seeing? If not, check out the latest branch (develop) of this repo and try to reproduce it there. Thank you! |
@dLobatog thanks for reviewing the changes. I am also not able to reproduce it in the latest branch code(develop). But in the file /app/controllers/roles_controller.rb#L84, we are assigning 'false' to the 'builtin' attribute while it is an integer attribute. Down the line it may cause some issue. Suggest if we can set it to integer zero instead of false value? |
@vision2910 From what I can tell, that's not really a problem as it's saved as 0 with false. I agree it's not ideal, and it all stems from the fact the If you can write a db migration to change the field to be boolean in the db, I think that'd be ideal and we could merge that. Thank you! |
@dLobatog point noted, will do the db changes. |
@dLobatog missed to mention that 'builtin' can have value |
@vision2910 Good point, thanks. Let's trigger tests with [test] & I'll merge if green. |
The value of |
@dLobatog @domcleal To avoid this confusion here are the below actions we can take- Let me know your comments in this regard... |
Well, I don't think moving the specific numbers around is necessary if the field is simply changed to a boolean. Writing a DB migration that migrates the ints safely to a boolean field is probably all that is required. This may require some additional steps (such as creating, then renaming a temporary boolean column) if conversion isn't possible on all DBs in a single statement. |
6c74f37
to
495556d
Compare
There were the following issues with the commit message:
If you don't have a ticket number, please create an issue in Redmine, selecting the appropriate project. More guidelines are available in Coding Standards or on the Foreman wiki. This message was auto-generated by Foreman's prprocessor |
@domcleal I have verified that storing anything other than 0,1 or true, false in a boolean attribute would cause the problem. We have to avoid using 2 as a role.builtin's value. |
[test] |
roles = Role.where(:builtin => 2) | ||
roles.each do |role| | ||
role.builtin = 1 | ||
role.save! |
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.
this should either use fake model or some AR method to skip validations to avoid problems in future, please see example in some older migration
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.
SQL would be better here.
ActiveRecord::Base.connection.execute("UPDATE roles SET builtin = 1 WHERE builtin = 2")
@@ -63,6 +63,16 @@ class RoleTest < ActiveSupport::TestCase | |||
assert_equal Role::BUILTIN_DEFAULT_ROLE, role.builtin | |||
end | |||
end | |||
|
|||
should "have zero or one builtin" do | |||
role = Role.new(:name => 'role name') |
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.
this should be defined above the should block as
let(:role) { FactoryGirl.build(:role) }
I think a lot of tests fail because factory for role should be updated too |
Btw the reason it works in develop branch is that recently merged PR fixed default value of builtin attribute https://github.com/theforeman/foreman/pull/3659/files#diff-dbdb4ceb4a2d790f9001a3bc2be67da1R3 |
There were the following issues with the commit message:
If you don't have a ticket number, please create an issue in Redmine, selecting the appropriate project. More guidelines are available in Coding Standards or on the Foreman wiki. This message was auto-generated by Foreman's prprocessor |
Can an existing organization member please verify this patch? |
2 similar comments
Can an existing organization member please verify this patch? |
Can an existing organization member please verify this patch? |
Thank you for your contribution, @vision2910! This PR has been inactive for 6 months, closing for now. |
The above fix will prevent nil value for 'builtin' attribute for Role while cloning it. The changed files are-
/app/controllers/roles_controller.rb#L84
/test/functional/roles_controller_test.rb#L83