18F/identity-dashboard

View on GitHub
app/views/service_providers/_form.html.erb

Summary

Maintainability
Test Coverage
<%= form.error_notification %>
<fieldset class='usa-fieldset'>

  <legend class='usa-sr-only'>Dashboard Configuration</legend>
  <%= form.label :prod_config,
                 label: 'Dashboard Configuration',
                 class: 'usa-label' %>
  <%= form.collection_radio_buttons(:prod_config,
                                    { "Ready for Production" => true, "Sandbox" => false },
                                    :last, :first,
                                    item_wrapper_tag: :ul,
                                    item_wrapper_class: "usa-input-list") do |b| %>
    <li>
      <%=  b.radio_button(class: "usa-radio__input usa-radio__input--tile") %>
      <%=  b.label(class: "usa-radio__label")%>
    </li>
  <% end %>

  <%= form.input :app_name,
                 input_html: { class: 'usa-input' },
                 label_html: { class: 'usa-input-required'},
                 label: 'App name',
                 hint: t('service_provider_form.app_name_html') %>

  <%= form.input :friendly_name,
                 input_html: { class: 'usa-input', aria: { invalid: false } },
                 label_html: { class: 'usa-input-required'},
                 label: 'Friendly name',
                 hint: t('service_provider_form.friendly_name_html') %>


  <%= form.input :description,
                 as: :usa_textarea,
                 label_html: { class: 'usa-input-optional' },
                 label: 'Description',
                 hint: I18n.t('service_provider_form.description') %>

  <%= form.association :team,
                       as: :usa_collection_select,
                       value_method: :id,
                       collection: current_user.scoped_teams,
                       label: 'Team',
                       disabled: !can_edit_teams?(current_user),
                       hint: I18n.t('service_provider_form.team') %>


  <%# label the grouping of items using a fieldset and legend for screen readers,
      and use UL for radio buttons %>
  <fieldset class='usa-fieldset'>
    <legend class='usa-sr-only'>Authentication protocol</legend>
    <%= form.label :identity_protocol,
                   label: 'Authentication protocol',
                   class: 'usa-label' %>
      <% ServiceProvider.identity_protocols.each_key do |protocol| %>
        <div class="usa-radio">
          <%= form.radio_button :identity_protocol,
                                protocol,
                                class: 'usa-radio__input' %>
          <%= form.label ('identity_protocol_' + protocol).to_sym,
                         titleize(protocol),
                         class: 'usa-radio__label' %>
        </div>
     <% end %>
    <%= form.hint I18n.t('service_provider_form.protocol') %>
  </fieldset>

  <%= form.input :ial,
                 as: :select,
                 collection: [[I18n.t('service_provider_form.ial_option_1'), 1],
                              [I18n.t('service_provider_form.ial_option_2'), 2]],
                 selected: form.object.ial,
                 input_html: { class: 'usa-input usa-select'},
                 label: 'Level of Service',
                 hint: t('service_provider_form.identity_assurance_level_html') %>

  <%= form.input :default_aal,
                 as: :select,
                 collection: [
                   [I18n.t('service_provider_form.aal_option_default'), nil],
                   [I18n.t('service_provider_form.aal_option_2'), 2],
                   [I18n.t('service_provider_form.aal_option_3'), 3]],
                 selected: form.object.default_aal,
                 input_html: { class: 'usa-input usa-select'},
                 label: 'Default Authentication Assurance Level (AAL)' %>

  <%# label the grouping of items using a fieldset and legend for screen readers,
      and use UL for checkboxes%>
  <fieldset class='usa-fieldset-inputs usa-fieldset'>
    <legend class='usa-sr-only'>Attribute bundle</legend>
    <%= form.label :attribute_bundle,
                   label: 'Attribute bundle',
                   class: 'usa-label' %>
    <%= form.hint t('service_provider_form.attribute_bundle') %>

    <span class="usa-error-message js-bundle-input-error-message">
      <%= service_provider.errors[:attribute_bundle].to_sentence.presence %>
    </span>

    <%= form.collection_check_boxes(:attribute_bundle,
                                    ServiceProvider.possible_attributes,
                                    :first, :last,
                                    item_wrapper_tag: :div,
                                    item_wrapper_class: 'usa-checkbox ial-attr-wrapper') do |b| %>
      <%= b.check_box class: "usa-checkbox__input" %>
      <%= b.label class: "usa-checkbox__label" %>
    <% end %>
  </fieldset>

  <%= form.input :issuer,
                 disabled: form.object.persisted?,
                 label: 'Issuer',
                 label_html: { class: 'usa-input-required' },
                 input_html: { class: 'usa-input', aria: { invalid: false } },
                 hint: if form.object.persisted?
                     I18n.t('service_provider_form.change_issuer')
                   else
                     t('service_provider_form.issuer_html')
                   end %>

  <% if current_user.admin? %>
    <%# allow_prompt_login checkbox %>
    <fieldset class="usa-fieldset">
      <legend class="usa-sr-only">Enable prompt=login</legend>
      <%= form.label :allow_prompt_login,
                      label: 'Enable <prompt=login>',
                      class: 'usa-label' %>
      <div class="usa-checkbox">
        <%= form.check_box :allow_prompt_login, class: 'usa-checkbox__input' %>
        <%= form.label :allow_prompt_login, 'Enabled', class: 'usa-checkbox__label' %>
      </div>
    </fieldset>

    <%# email_nameid_format_allowed checkbox %>
    <fieldset class="usa-fieldset">
      <legend class="usa-sr-only">Allow email NameID Format</legend>
      <%= form.label :email_nameid_format_allowed,
                      label: 'Allow Email NameID Format',
                      class: 'usa-label' %>
      <div class="usa-checkbox">
        <%= form.check_box :email_nameid_format_allowed, class: 'usa-checkbox__input' %>
        <%= form.label :email_nameid_format_allowed, 'Enabled', class: 'usa-checkbox__label' %>
      </div>
    </fieldset>
  <% end %>

  <%= render 'logo_upload', form: form, service_provider: service_provider %>

  <fieldset class="usa-fieldset" id="certificate-container">
    <div class="usa-label">Certificates</div>

    <p>
      <% I18n.t('service_provider_form.certificate') =%>
    </p>


    <% service_provider.certificates.each do |certificate| %>
      <%= render 'certificate', certificate: certificate do %>
        <div class="usa-alert usa-alert--warning usa-alert--no-icon" >
          <div class="usa-alert__text">
            <%= check_box_tag "service_provider[remove_certificates][#{certificate.serial}]",
                              certificate.serial,
                              false,
                              name: "service_provider[remove_certificates][]",
                              class: 'usa-checkbox__input' %>
            <%= content_tag :label,
                            for: "service_provider_remove_certificates_#{certificate.serial}",
                            class: 'usa-checkbox__label' do %>
              Remove this certificate
            <% end %>
          </div>
        </div>
      <% end %>
    <% end %>

    <div class="lg-card margin-top-2">
      <label class="usa-label margin-top-0" for="service_provider_cert">
        Upload a new public cert
      </label>

      <div class="clearfix">
        <span class="usa-error-message js-pem-input-error-message">
          <%= service_provider.errors[:certs].to_sentence.presence %>
        </span>
        <%= form.file_field :cert, class: 'input-file js-pem-input' %>
        <label class="usa-button file-input-button" for="service_provider_cert">
          Choose a cert file
        </label>
        <div class="margin-top-4 js-pem-file-name"></div>
      </div>

      <div class="margin-top-2">
        <p>
          Take a look at our developer documentation for
          <a href="https://developers.login.gov/testing/#creating-a-public-certificate">
          how to generate a public-private key pair</a>.
        </p>
        <p>
          Certificate must be
          <a href="https://en.wikipedia.org/wiki/Privacy-enhanced_Electronic_Mail" target="_blank">PEM encoded</a>,
          like this example:
        </p>
        <pre><code>-----BEGIN CERTIFICATE-----
MIIDXTCCAkWgAwIBAgIJAJC1HiIAZAiIMA0GCSqGSIb3Df
BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVx
B7xxt8BVc69rHV15A0qyx77CLSj3tCx2IUXVqRs5mlvA==
-----END CERTIFICATE-----</code></pre>
      </div>
    </div>
  </fieldset>

  <div class='saml-fields'>
    <%= form.input :acs_url,
                   input_html: { class: 'usa-input', aria: { invalid: false } },
                   label_html: { class: 'usa-input-required'},
                   label: 'Assertion Consumer Service URL',
                   required: true,
                   hint: t('service_provider_form.assertion_consumer_service_url_html') %>

    <%= form.input :assertion_consumer_logout_service_url,
                   input_html: { class: 'usa-input' },
                   label: 'Assertion Consumer Logout Service URL',
                   hint: t('service_provider_form.assertion_consumer_logout_service_url_html') %>

    <%= form.input :sp_initiated_login_url,
                   input_html: { class: 'usa-input' },
                   label: 'SP Initiated Login URL',
                   hint: t('service_provider_form.sp_initiated_login_url_html') %>

    <%= form.input :block_encryption,
                   input_html: { class: 'usa-select' },
                   label: 'SAML Assertion Encryption',
                   include_blank: false,
                   hint: I18n.t('service_provider_form.saml_assertion_encryption') %>

    <legend class='usa-sr-only'>Signed Response Message Requested</legend>
    <%= form.label :signed_response_message_requested,
                  label: 'Signed Response Message Requested',
                  class: 'usa-label' %>
    <%= form.collection_radio_buttons(:signed_response_message_requested,
                                      { "Yes" => true, "No" => false },
                                      :last, :first,
                                      item_wrapper_tag: :div,
                                      item_wrapper_class: 'usa-radio') do |b| %>
      <%=  b.radio_button(class: "usa-radio__input") %>
      <%=  b.label(class: "usa-radio__label")%>
    <% end %>
  </div>

  <div class='saml-fields'>
    <%= form.input :return_to_sp_url,
                  input_html: { class: 'usa-input', aria: { invalid: false } },
                  label_html: { class: 'usa-input-required'},
                  label: 'Return to App URL',
                  required: true,
                  hint: t('service_provider_form.return_to_app_url_html') %>
  </div>
  <%= form.input :failure_to_proof_url,
                 input_html: { class: 'usa-input', aria: { invalid: false } },
                 label_html: { class: 'usa-input-required'},
                 label: 'Failure to Proof URL',
                 hint: I18n.t('service_provider_form.failure_to_proof_url'),
                 required: true %>

  <%= form.input :push_notification_url,
                 input_html: { class: 'usa-input' },
                 label: 'Push notification URL',
                 hint: I18n.t('service_provider_form.push_notification_url') %>

  <%# BEGIN redirect_uris %>
    <div class='usa-hint oidc-fields'>
      <%= form.label :redirect_uris,
                     label: 'Redirect URIs',
                     class: 'usa-label' %>
      <% service_provider.errors[:redirect_uris].each do |error| %>
        <span class="usa-error-message js-bundle-input-error-message">
          <%= error %>
        </span>
      <% end %>
    </div>

    <div class='usa-hint saml-fields'>
      <%= form.label :redirect_uris,
                     label: 'Additional Redirect URIs',
                     class: 'usa-label' %>
      <% service_provider.errors[:redirect_uris].each do |error| %>
        <span class="usa-error-message js-bundle-input-error-message">
          <%= error %>
        </span>
      <% end %>
    </div>

    <%= content_tag :div, class: 'json optional service_provider_redirect_uris' do -%>
      <% redirect_uri_list.each do |value| %>
        <%= text_field_tag 'service_provider[redirect_uris][]',
                           value,
                           id: 'service_provider_redirect_uris',
                           class: 'block col-12 json optional usa-input',
                           multiple: 'multiple' %>
      <% end %>
    <% end %>

    <div class='oidc-fields'>
      <%= t('service_provider_form.oidc_redirects_html') %>
    </div>

    <div class='saml-fields margin-0'>
      <%= form.hint t('service_provider_form.saml_redirects_html') %>
    </div>

    <%= form.button :button,
                    'Add another URI',
                    type: 'button',
                    id: 'add-redirect-uri-field',
                    class: 'usa-button margin-bottom-4' %>
  <%# END redirect_uris %>

  <div class='active margin-bottom-4'>
    <legend class='usa-sr-only'>Accessible</legend>
    <%= form.label :admin,
                   label: 'Accessible',
                   class: 'usa-label' %>
    <%= form.collection_radio_buttons(:active,
                                      { "Yes" => true, "No" => false },
                                      :last, :first,
                                      item_wrapper_tag: :ul,
                                      item_wrapper_class: 'usa-input-list') do |b| %>
      <li>
        <%=  b.radio_button(class: "usa-radio__input usa-radio__input--tile") %>
        <%=  b.label(class: "usa-radio__label")%>
      </li>
    <% end %>
    <%= form.hint I18n.t('service_provider_form.active') %>
  </div>

  <% if show_minimal_help_text_element?(service_provider) %>
    <p class="usa-label">Help text</p>
    <% if help_text_options_enabled? %>
     <p class="text-base">You can choose from the default help text options to alert users of important information at the sign-in, sign-up, and forgot password stages of logging into your app.</p>
     <p class="text-base">If your app requires custom help text, reach out to the <a href="https://logingov.zendesk.com">Partner Support Help Desk</a>. Help text guidance is outlined in the User experience section 
      of the developer documentation. You should understand the guidance when you request support.</p>                                 
      <%= render 'form_default_help_text', form: form, service_provider: @service_provider %>
    <% else %>
      <p>You have no existing help text.</p>
      <p>Do you need to add help text for your application? <a href="https://logingov.zendesk.com">Contact us</a>.</p>
    <% end %>
  <% else%>
    <fieldset class="usa-fieldset-inputs custom-help-text">
      <legend>Custom help text</legend>
      <% if policy(service_provider).edit_custom_help_text? %>
        <p>You can specify help text in these different areas to alert users of important information for logging into your app. Permitted HTML elements include the following:
        <%= safe_join(ServiceProvider::ALLOWED_HELP_TEXT_HTML_TAGS.map { |t| tag.code(t) }, ", ") %>.
        </p>
      <% else %>
        <p>You can view your existing help text here.</p>
        <p>Do you need to edit the custom help text for your application? <a href="https://logingov.zendesk.com">Contact us</a>.</p>
      <% end %>
      <%= render 'form_custom_help_text', form: form, service_provider: @service_provider %>
    </fieldset>
  <% end %>
</fieldset>

<%= javascript_include_tag 'service_provider_form' %>