Warn users when their keys are invalid

This commit is contained in:
Nick Thomas 2017-08-21 15:01:05 +01:00
parent b0f982fbdf
commit b49b7bc147
3 changed files with 11 additions and 3 deletions

View file

@ -1,9 +1,10 @@
module FormHelper
def form_errors(model)
def form_errors(model, headline = 'The form contains the following')
return unless model.errors.any?
pluralized = 'error'.pluralize(model.errors.count)
headline = "The form contains the following #{pluralized}:"
headline = headline + ' ' + pluralized + ':'
content_tag(:div, class: 'alert alert-danger', id: 'error_explanation') do
content_tag(:h4, headline) <<

View file

@ -1,6 +1,12 @@
%li.key-list-item
.pull-left.append-right-10
= icon 'key', class: "settings-list-icon hidden-xs"
- if key.valid?
= icon 'key', class: 'settings-list-icon hidden-xs'
- else
= icon 'exclamation-triangle', class: 'settings-list-icon hidden-xs',
title: 'The key is disabled because it is invalid'
.key-list-item-info
= link_to path_to_key(key, is_admin), class: "title" do
= key.title

View file

@ -16,6 +16,7 @@
%strong= @key.last_used_at.try(:to_s, :medium) || 'N/A'
.col-md-8
= form_errors(@key, 'The key has the following') unless @key.valid?
%p
%span.light Fingerprint:
%code.key-fingerprint= @key.fingerprint