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

Remove unnecessary validation before clicking on Add/Save while adding/editing a Group or Role #6169

Merged
merged 2 commits into from
Sep 23, 2019

Conversation

hstastna
Copy link

@hstastna hstastna commented Sep 9, 2019

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 not true. 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#4566

After:
group_add-after

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

@miq-bot miq-bot added the wip label Sep 9, 2019
@hstastna hstastna changed the title [WIP] Remove unnecessary bad variable and validation before clicking on Add/Save while adding/editing a Group or Role [WIP] Remove unnecessary validation before clicking on Add/Save while adding/editing a Group or Role Sep 9, 2019
@hstastna hstastna force-pushed the Remove_bad_ops_rbac branch 7 times, most recently from f74e5d1 to 98ad6ab Compare September 10, 2019 11:46
@hstastna hstastna changed the title [WIP] Remove unnecessary validation before clicking on Add/Save while adding/editing a Group or Role Remove unnecessary validation before clicking on Add/Save while adding/editing a Group or Role Sep 10, 2019
@miq-bot miq-bot removed the wip label Sep 10, 2019
@@ -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)
Copy link
Contributor

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".

Copy link
Author

@hstastna hstastna Sep 10, 2019

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".

Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Author

@hstastna hstastna Sep 10, 2019

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).

Copy link
Contributor

Choose a reason for hiding this comment

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

Aah, perfect, thanks! :)

@himdel
Copy link
Contributor

himdel commented Sep 10, 2019

LGTM I think 👍 ,
except the new message is a bit confusing.

(Not tested yet)

@himdel
Copy link
Contributor

himdel commented Sep 10, 2019

Test failure looks unrelated, maybe a rebase? :)

@h-kataria
Copy link
Contributor

LGTM I think ,
except the new message is a bit confusing.

(Not tested yet)

@hstastna @himdel How about just to be consistent with other screens "Role is required"

@hstastna
Copy link
Author

hstastna commented Sep 11, 2019

@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. ❇️

Hilda Stastna added 2 commits September 18, 2019 16:42
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.
@miq-bot
Copy link
Member

miq-bot commented Sep 18, 2019

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
2 files checked, 0 offenses detected
Everything looks fine. 👍

@himdel himdel self-assigned this Sep 23, 2019
@himdel himdel added the bug label Sep 23, 2019
@himdel himdel added this to the Sprint 121 Ending Sep 30, 2019 milestone Sep 23, 2019
@himdel
Copy link
Contributor

himdel commented Sep 23, 2019

Sorry for the delay, merging :)

@himdel himdel merged commit b183ad3 into ManageIQ:master Sep 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants