Frontend doesn't send auth_method when password auth is used with pull mirrors

As discussed in https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/9134#note_131453554, we see that if a pull mirrors is added with password auth, the frontend doesn't submit the auth_method with password because the selection box is disabled:

image

It looks like we can fix this in one of two ways:

  1. Add a hidden field
  2. Enable the selection box before the form is submitted

@lbennett I think this patch does the job with a hidden field, but would you prefer option 2 or another way?

diff --git a/app/assets/javascripts/mirrors/ssh_mirror.js b/app/assets/javascripts/mirrors/ssh_mirror.js
index 5bdf5d6277a..ca77d35bd9e 100644
--- a/app/assets/javascripts/mirrors/ssh_mirror.js
+++ b/app/assets/javascripts/mirrors/ssh_mirror.js
@@ -20,6 +20,7 @@ export default class SSHMirror {
     this.$btnDetectHostKeys = this.$form.find('.js-detect-host-keys');
     this.$btnSSHHostsShowAdvanced = this.$form.find('.btn-show-advanced');
     this.$dropdownAuthType = this.$form.find('.js-mirror-auth-type');
+    this.$hiddenAuthType = this.$form.find('.js-hidden-mirror-auth-type');

     this.$wellAuthTypeChanging = this.$form.find('.js-well-changing-auth');
     this.$wellPasswordAuth = this.$form.find('.js-well-password-auth');
@@ -72,9 +73,13 @@ export default class SSHMirror {
       if (forceMatch && isSsh) {
         this.$dropdownAuthType.val(AUTH_METHOD.SSH);
         this.toggleAuthWell(AUTH_METHOD.SSH);
+        this.$hiddenAuthType.val(AUTH_METHOD.SSH);
+        this.$hiddenAuthType.prop('disabled', true);
       } else {
         this.$dropdownAuthType.val(AUTH_METHOD.PASSWORD);
         this.toggleAuthWell(AUTH_METHOD.PASSWORD);
+        this.$hiddenAuthType.val(AUTH_METHOD.PASSWORD);
+        this.$hiddenAuthType.prop('disabled', false);
       }
     }
   }
@@ -234,6 +239,8 @@ export default class SSHMirror {
   toggleAuthWell(authType) {
     this.$wellPasswordAuth.collapse(authType === AUTH_METHOD.PASSWORD ? 'show' : 'hide');
     this.$wellSSHAuth.collapse(authType === AUTH_METHOD.SSH ? 'show' : 'hide');
+    this.$hiddenAuthType.val(authType);
+    this.$hiddenAuthType.prop('disabled', authType === AUTH_METHOD.SSH);
   }

   /**
diff --git a/app/views/projects/mirrors/_authentication_method.html.haml b/app/views/projects/mirrors/_authentication_method.html.haml
index 293a2e3ebfe..ef6db07a1bb 100644
--- a/app/views/projects/mirrors/_authentication_method.html.haml
+++ b/app/views/projects/mirrors/_authentication_method.html.haml
@@ -9,6 +9,7 @@
   = f.select :auth_method,
       options_for_select(auth_options, mirror.auth_method),
       {}, { class: "form-control js-mirror-auth-type qa-authentication-method" }
+  = f.hidden_field :auth_method, value: "password", class: "js-hidden-mirror-auth-type"

 .form-group
   .collapse.js-well-changing-auth