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

Disable <Choose a Role> option to prevent error while adding Group #5933

Merged

Conversation

hstastna
Copy link

@hstastna hstastna commented Aug 2, 2019

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1730402

Unexpected error occurs if we choose < Choose a Role > option in the drop down for specifying some Role while adding a new Group (after we had some Role already chosen). With disabling this option, we prevent occurring errors and we also bring more consistency because it is not possible to choose <Choose a Project/Tenant> option, too, for specifying a Project or Tenant.

With disabling option, we also prevent saving group with in the drop down.

Note:
Name, Role and Project or Tenant are required to specify for adding new Group.


Before:
role_before

After:
role_after

@hstastna
Copy link
Author

hstastna commented Aug 2, 2019

@miq-bot add_label bug, ivanchuk/yes, hammer/yes

@hstastna hstastna changed the title Disable <Choose a Role> option to prevent error while adding Group [WIP] Disable <Choose a Role> option to prevent error while adding Group Aug 2, 2019
@miq-bot miq-bot added the wip label Aug 2, 2019
@hstastna hstastna force-pushed the Error_changing_Role_adding_Group branch from a648843 to d6ae9a7 Compare August 2, 2019 15:13
@hstastna hstastna changed the title [WIP] Disable <Choose a Role> option to prevent error while adding Group Disable <Choose a Role> option to prevent error while adding Group Aug 2, 2019
@miq-bot miq-bot removed the wip label Aug 2, 2019
@@ -70,8 +70,8 @@
= link_to(@group.miq_user_role.name, "#", params)
- else
= select_tag('group_role',
options_for_select(@edit[:roles].sort, @edit[:new][:role]),
:class => "selectpicker")
options_for_select(@edit[:roles].sort, selected: @edit[:new][:role], disabled: ["<Choose a Role>", nil]),
Copy link
Member

Choose a reason for hiding this comment

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

@hstastna use arrows instead of the colon for selected and disabled parameters

Copy link
Author

Choose a reason for hiding this comment

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

@romanblanco Done ;)

@hstastna hstastna force-pushed the Error_changing_Role_adding_Group branch 2 times, most recently from 4c2426b to 6e6cf95 Compare August 5, 2019 10:46
Copy link
Member

@romanblanco romanblanco left a comment

Choose a reason for hiding this comment

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

Now, Add button get's enabled only after setting Project/Tenant field, but submitting the form without setting Role in the dropdown throws an error:

[----] F, [2019-08-05T12:04:41.126740 #27616:2b18c50e5070] FATAL -- : Error caught: [ActiveRecord::RecordNotFound] Couldn't find MiqUser
Role with 'id'=<Choose a Role>
/home/rblanco/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.1.7/lib/active_record/relation/finder_methods.rb:343:in `rai
se_record_not_found_exception!'
/home/rblanco/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.1.7/lib/active_record/relation/finder_methods.rb:460:in `fin
d_one'
/home/rblanco/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.1.7/lib/active_record/relation/finder_methods.rb:440:in `fin
d_with_ids'
/home/rblanco/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.1.7/lib/active_record/relation/finder_methods.rb:66:in `find
'
/home/rblanco/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.1.7/lib/active_record/querying.rb:3:in `find'
/home/rblanco/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.1.7/lib/active_record/core.rb:178:in `find'
/home/rblanco/devel/manageiq-ui-classic/app/controllers/ops_controller/ops_rbac.rb:1225:in `rbac_group_set_record_vars'
/home/rblanco/devel/manageiq-ui-classic/app/controllers/ops_controller/ops_rbac.rb:673:in `rbac_edit_save_or_add'
/home/rblanco/devel/manageiq-ui-classic/app/controllers/ops_controller/ops_rbac.rb:92:in `rbac_group_edit'

The Add button should be enabled after setting both Project/Tenant and Role fields.

Also "Description can't be blank" error message shows up if you skip the Description, so even this field should probably affect Add button, to prevent the error message.

@@ -1226,7 +1222,7 @@ module OpsController::OpsRbac

   # Set group record variables to new values
   def rbac_group_set_record_vars(group)
-    role = MiqUserRole.find(@edit[:new][:role])
+    role = MiqUserRole.find(@edit[:new][:role].second) if @edit[:new][:role].second.present?
     group.description = @edit[:new][:description]
     group.miq_user_role = role
     group.tenant = Tenant.find(@edit[:new][:group_tenant]) if @edit[:new][:group_tenant]

makes it available to submit the form without Role.

@hstastna hstastna force-pushed the Error_changing_Role_adding_Group branch from 6e6cf95 to 0efaef0 Compare August 5, 2019 12:43
@hstastna
Copy link
Author

hstastna commented Aug 5, 2019

@romanblanco So do you think that Add button should be enabled after setting Project/Tenant, Role AND Description (everything in Group Information section)? Thank you.

@hstastna hstastna force-pushed the Error_changing_Role_adding_Group branch 2 times, most recently from 47ee19c to 5025fcc Compare August 5, 2019 13:30
@hstastna
Copy link
Author

hstastna commented Aug 5, 2019

I think we don't want to submit the form without Role. I was told that Name, Role and Project or Tenant are required to specify for adding new Group.

@romanblanco
Copy link
Member

@romanblanco So do you think that Add button should be enabled after setting Project/Tenant, Role AND Description (everything in Group Information section)? Thank you.

it yells if Description is missing and fails if Role is missing, I think yes. ☺️

@hstastna
Copy link
Author

hstastna commented Aug 5, 2019

@romanblanco This is the logic which allows Add button to be enabled only if some Role and Tenant is set. I can add the logic also for the Name there. But I am not sure if we want this in this PR. What do you think about it? Because it's little bit different issue (Add/Save button also does not respond properly for editing a Group). And this PR should be mainly about fixing the BZ :)

Copy link
Member

@romanblanco romanblanco left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@@ -69,9 +69,11 @@
%i.ff.ff-user-role{params}
= link_to(@group.miq_user_role.name, "#", params)
- else
- disabled_item = ["<Choose a Role>", nil]
- selected_item = @edit[:new][:role] ? @edit[:new][:role] : disabled_item
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps shorter:

- selected_item = @edit[:new][:role] || disabled_item

@hstastna
Copy link
Author

hstastna commented Aug 5, 2019

I've created an issue regarding Add/Save button ;)

@hstastna hstastna force-pushed the Error_changing_Role_adding_Group branch from bd6a93c to 029a9a0 Compare August 7, 2019 09:16
@miq-bot
Copy link
Member

miq-bot commented Aug 7, 2019

Checked commits hstastna/manageiq-ui-classic@fc0c980~...029a9a0 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. 🍰

@h-kataria h-kataria self-assigned this Aug 7, 2019
@h-kataria h-kataria added this to the Sprint 118 Ending Aug 19, 2019 milestone Aug 7, 2019
@h-kataria h-kataria merged commit 8538572 into ManageIQ:master Aug 7, 2019
simaishi pushed a commit that referenced this pull request Aug 7, 2019
Disable <Choose a Role> option to prevent error while adding Group

(cherry picked from commit 8538572)

https://bugzilla.redhat.com/show_bug.cgi?id=1730402
@simaishi
Copy link
Contributor

simaishi commented Aug 7, 2019

Ivanchuk backport details:

$ git log -1
commit 03edbba27814be6cb25f7d2e7aa2640c12d2b35a
Author: Harpreet Kataria <[email protected]>
Date:   Wed Aug 7 12:04:19 2019 -0400

    Merge pull request #5933 from hstastna/Error_changing_Role_adding_Group
    
    Disable <Choose a Role> option to prevent error while adding Group
    
    (cherry picked from commit 85385728dc262b35e33cd46d048aceac7756c017)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1730402

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

Successfully merging this pull request may close these issues.

7 participants