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

Prevent rendering User to Look Up form field twice and with same id #6565

Merged

Conversation

hstastna
Copy link
Contributor

@hstastna hstastna commented Dec 18, 2019

Issue: #2316

This PR solves the specific situation in LDAP user lookup form: DOM ID "user" was there twice. This was caused by ManageIQ/manageiq#4042. The exactly same field with the same id, that was already there, was added in the haml, together with the javascript for showing/hiding the divs with the appropriate fields. This (not the best) solution was implemented for displaying/hiding Retrieve button next to the field.

Later, thanks to some cleanup in that area, this issue became obvious: the same field was rendered twice in the screen, all the divs were shown because the javascript was not executed - and this because @edit was nil - this all thanks to this change.

This PR cares about:

  • removing unnecessary extra field from the appropriate haml
  • adding a simple condition for displaying Retrieve button if mode == "httpd"
    Note that mode is already set here, no need to use the whole condition as here.
  • adding another similar condition for displaying Username and Password fields: unless mode == "httpd" because of this
  • removing the unnecessary javascript from the haml
  • removing extra Retrieve button as, according to the existing logic in the haml, Retrieve button will always be there

Note:
Adding - if @edit to the haml (added in the haml during the later cleanup) is not necessary because it's already there in the right place.

@hstastna
Copy link
Contributor Author

@miq-bot add_label bug

@miq-bot miq-bot added the bug label Dec 18, 2019
@hstastna
Copy link
Contributor Author

@martinpovolny @himdel Could you, please, review this? Thanks :)

@himdel
Copy link
Contributor

himdel commented Dec 18, 2019

Before:

user_id_ext_auth_form_group - show when httpd
user_id_form_group - hide when httpd
user_name_form_group - hide when httpd
user_password_form_group - hide when httpd

Now:

user_id_ext_auth_form_group & user_id_form_group - merged, show the ext_auth variant when httpd
user_name_form_group, user_password_form_group - hide when httpd

We're losing the actual id (because the same form group can't have 2), but it's not used elsewhere 👍

(not tested yet)

@hstastna
Copy link
Contributor Author

hstastna commented Dec 18, 2019

@himdel I am not sure if I should use #user_name_form_group or #user_id_ext_auth_form_group for the field (with or without Retrieve button) which remains in the haml. It looks like it does not matter (it was there only for showing/hiding the exact div). But maybe #user_name_form_group is more universal. And yes, better to test it.

Just to be clear, the div - 'the ext_auth variant' - as you've written, is now displayed no matter the authentication mode. The Retrieve button next to the field - this is what we really want to display if httpd (or not to display if no httpd). The field by itself should be there no matter the mode - I think this is the original logic and I tried to keep it, just to prevent the issues.

@himdel
Copy link
Contributor

himdel commented Dec 18, 2019

So, LGTM, this works.

But you can go one step further ;)...

the Retrieve button is present and identical in both the - if mode == "httpd" branch and the -unless mode == "httpd" branch.

So, what about...

diff --git a/app/views/ops/_rbac_group_details.html.haml b/app/views/ops/_rbac_group_details.html.haml
index 51fd8d9d52..c50a872f17 100644
--- a/app/views/ops/_rbac_group_details.html.haml
+++ b/app/views/ops/_rbac_group_details.html.haml
@@ -124,7 +124,7 @@
         %h3
           = _("LDAP Group Look Up")
         .form-horizontal
-          .form-group#user_id_ext_auth_form_group
+          .form-group#user_id_form_group
             %label.col-md-2.control-label
               = _("User to Look Up")
             .col-md-8
@@ -134,19 +134,6 @@
                                :class             => "form-control",
                                "data-miq_observe" => {:interval => '.5',
                                                       :url      => url}.to_json)
-            - if mode == "httpd"
-              .col-md-12{:align => "right", :valign => "bottom"}
-                = link_to("Retrieve",
-                          {:action => "rbac_group_user_lookup",
-                           :button => "submit",
-                           :id     => @edit[:group_id] || "new"},
-                          :class                 => "btn btn-primary",
-                          :alt                   => t = _("LDAP Group Lookup"),
-                          "data-miq_sparkle_on"  => true,
-                          "data-miq_sparkle_off" => true,
-                          :remote                => true,
-                          "data-method"          => :post,
-                          :title                 => t)
 
           - unless mode == "httpd"
             .form-group#user_name_form_group
@@ -170,18 +157,19 @@
                                      :class => "form-control",
                                      "data-miq_observe" => {:interval => '.5',
                                                             :url      => url}.to_json)
-              .col-md-12{:align => "right", :valign => "bottom"}
-                = link_to("Retrieve",
-                          {:action => "rbac_group_user_lookup",
-                           :button => "submit",
-                           :id     => @edit[:group_id] || "new"},
-                          :class                 => "btn btn-primary",
-                          :alt                   => t = _("LDAP Group Lookup"),
-                          "data-miq_sparkle_on"  => true,
-                          "data-miq_sparkle_off" => true,
-                          :remote                => true,
-                          "data-method"          => :post,
-                          :title                 => t)
+
+          .col-md-12{:align => "right", :valign => "bottom"}
+            = link_to("Retrieve",
+                      {:action => "rbac_group_user_lookup",
+                       :button => "submit",
+                       :id     => @edit[:group_id] || "new"},
+                      :class                 => "btn btn-primary",
+                      :alt                   => t = _("LDAP Group Lookup"),
+                      "data-miq_sparkle_on"  => true,
+                      "data-miq_sparkle_off" => true,
+                      :remote                => true,
+                      "data-method"          => :post,
+                      :title                 => t)
 
   %hr
   %h3

(on top of the current changes)

@hstastna hstastna force-pushed the Broken_LDAP_user_lookup_form_ID_user_twice branch from d232c0b to 23a5a41 Compare December 19, 2019 10:33
@miq-bot
Copy link
Member

miq-bot commented Dec 19, 2019

Checked commit hstastna@23a5a41 with ruby 2.5.5, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0
1 file checked, 0 offenses detected
Everything looks fine. 🏆

@hstastna
Copy link
Contributor Author

@himdel I've made suggested changes regarding the Retrieve button :)

@himdel himdel merged commit e6420e5 into ManageIQ:master Dec 19, 2019
@himdel
Copy link
Contributor

himdel commented Dec 19, 2019

LGTM, merging :)

with mode database - no lookup:

mode-db

with mode ldap or ldaps - 3 fields:

mode-ldap

with mode httpd (and no saml or oidc):

mode-httpd

@himdel himdel added this to the Sprint 127 Ending Jan 6, 2020 milestone Dec 19, 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.

None yet

3 participants