Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexis Reigel <mail@koffeinfrei.org>2017-02-22 18:22:39 +0300
committerAlexis Reigel <mail@koffeinfrei.org>2017-07-27 16:40:40 +0300
commitab4120de3165ea262de726aa3e102b74951d2bca (patch)
tree96c42755e279a415bf1dd1375dd389370f030651 /app/models/gpg_key.rb
parent7b7cd6f69d59092a55fc8b293edf09638fba20d9 (diff)
only validate gpg_key#fingerprint "internally"
Diffstat (limited to 'app/models/gpg_key.rb')
-rw-r--r--app/models/gpg_key.rb14
1 files changed, 9 insertions, 5 deletions
diff --git a/app/models/gpg_key.rb b/app/models/gpg_key.rb
index d77051850f3..b012db1428f 100644
--- a/app/models/gpg_key.rb
+++ b/app/models/gpg_key.rb
@@ -3,17 +3,21 @@ class GpgKey < ActiveRecord::Base
belongs_to :user
- validates :fingerprint,
- presence: true,
- uniqueness: true
-
validates :key,
presence: true,
uniqueness: true,
format: {
- with: /\A#{KEY_PREFIX}((?!#{KEY_PREFIX}).)+\Z/m
+ with: /\A#{KEY_PREFIX}((?!#{KEY_PREFIX}).)+\Z/m,
+ message: "is invalid. A valid public GPG key begins with '#{KEY_PREFIX}'"
}
+ validates :fingerprint,
+ presence: true,
+ uniqueness: true,
+ # only validate when the `key` is valid, as we don't want the user to show
+ # the error about the fingerprint
+ unless: -> { errors.has_key?(:key) }
+
before_validation :extract_fingerprint
def key=(value)