-
Notifications
You must be signed in to change notification settings - Fork 356
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
Remove unnecessary validation before clicking on Add/Save while adding/editing a Group or Role #6169
Conversation
f74e5d1
to
98ad6ab
Compare
@@ -1411,7 +1404,7 @@ def rbac_group_validate? | |||
@assigned_filters = [] if @edit[:new][:filters].empty? || @edit[:new][:use_filter_expression] | |||
@filter_expression = [] if @edit[:new][:filter_expression].empty? || @edit[:new][:use_filter_expression] == false | |||
if @edit[:new][:role].nil? || @edit[:new][:role] == "" | |||
add_flash(_("A User Group must be assigned a Role"), :error) | |||
add_flash(_("A Role must be assigned to a Group"), :error) |
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.
I think this should be "A Group must be assigned a Role".
But if you want to switch it around, "A Role must be assigned to this Group", otherwise, it sounds like "fix the role", not "fix the group".
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.
For me "A Group must be assigned a Role" does not make sense. I think there's still missing something. So I am better with "A Role must be assigned to this Group". Or "A Group must HAVE assigned a Role".
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.
I'm fine with both of those :) Thanks :)
@@ -670,6 +670,7 @@ def rbac_edit_save_or_add(what, rbac_suffix = what) | |||
when :group then | |||
record = @edit[:group_id] ? MiqGroup.find_by(:id => @edit[:group_id]) : MiqGroup.new | |||
validated = rbac_group_validate? | |||
rbac_group_set_record_description_role(record) # Set new Description, Role and Tenant for a new Group |
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.
first validate, then set extra fields?
Shouldn't this be the other way around?
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 was like that, originally. And yes, it looks weird but the logic behind this is that in rbac_group_validate?
, it is just checked that user filled in required fields like Description and Role. @edit[:new]
is checked there, not record
. And if everything is ok, then record
is set according to what user filled in and then saved.
My change here is that I am putting the new info which is required (Description, Role, Tenant) to record
even if rbac_group_validate?
fails. It fails if any of required fields is missing, not if all of them. And if it fails, rbac_group_set_record_vars
wouldn't be called so record
would miss ALL the info user filled in properly. So then later here, record.description
would be nil
, instead of the name user filled in. This leads to displaying error message about missing Description which does not make sense because user filled in Description (and forgot to choose a role, for example).
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.
Aah, perfect, thanks! :)
LGTM I think 👍 , (Not tested yet) |
98ad6ab
to
65e24ce
Compare
Test failure looks unrelated, maybe a rebase? :) |
65e24ce
to
4813cff
Compare
@h-kataria Good point! I like it. Let's be more consistent. Where else can I check what's happening if I forget to add any Role? Thank you. ❇️ |
Remove unneccessary code related to adding/editing a Group
Remove the flash message which did not make sense to be displayed if user filled in a description and pressed Add button while adding new Group.
4813cff
to
db57f6e
Compare
Checked commits hstastna/manageiq-ui-classic@f93d713~...db57f6e with ruby 2.4.6, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0 |
Sorry for the delay, merging :) |
This PR removes unnecessary code related to adding/editing a Group or Role because in older fields like in our cases and validation is usually provided AFTER clicking on Add/Save button - the same as in other screens => more consistency. Add/Save button respond now on any changes, and not also on the information if all the required fields are set.
This PR also fixes displaying extra flash message (Description can't be blank) which accidentally appears if we fill in only Description and click on Add button, while adding new Group. Caused by: #3164 The solution is setting Description, Role and/or Tenant (if it was chosen) even if
rbac_group_validate?
was nottrue
. This issue is reproducible after applying the first commit of this PR (removing 'bad' variable).More:
Related PR where we were dealing with the same issue: #5972 (comment)
Older PR which was adding
bad
variable: ManageIQ/manageiq#4566After:
Note:
Choosing Project/Tenant is not required. If user is signed it, its Tenant is chosen by default. See:
https://github.com/ManageIQ/manageiq/blob/33a3327b395700ce245f9f770b4277e0ce08d2c2/app/models/mixins/tenancy_mixin.rb#L16