From 78395ce4fd852e54b985964b0311b26e88e8154b Mon Sep 17 00:00:00 2001 From: icyleaf Date: Tue, 14 Jan 2025 15:06:16 +0000 Subject: [PATCH] fix(web): show errors message on create apple developer page --- app/models/apple_key.rb | 14 +++++++++----- app/views/admin/apple_keys/_form.html.slim | 1 - 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/models/apple_key.rb b/app/models/apple_key.rb index f7ffe6db4..e3aba547b 100644 --- a/app/models/apple_key.rb +++ b/app/models/apple_key.rb @@ -6,10 +6,10 @@ class AppleKey < ApplicationRecord has_many :devices, through: :apple_keys_devices validates :issuer_id, :key_id, :private_key, :filename, :checksum, presence: true - validates :checksum, uniqueness: true, on: :create - validate :private_key_format, on: :create - validate :appstoreconnect_api_role_permissions, on: :create - validate :distribution_certificate, on: :create + validates :checksum, uniqueness: true, on: :create, if: :requires_fields? + validate :private_key_format, on: :create, if: :requires_fields? + validate :appstoreconnect_api_role_permissions, on: :create, if: :requires_fields? + validate :distribution_certificate_exists, on: :create, if: :requires_fields? before_create :generate_checksum @@ -126,7 +126,7 @@ def appstoreconnect_api_role_permissions errors.add(:key_id, :unknown, message: "[#{e.class}]: #{e.message}") end - def distribution_certificate + def distribution_certificate_exists if apple_distribtion_certiticate.blank? errors.add(:issuer_id, :missing_distribution_certificate) end @@ -136,6 +136,10 @@ def apple_distribtion_certiticate @apple_distribtion_certiticate ||= client.distribution_certificates.to_model end + def requires_fields? + issuer_id.present? && key_id.present? || private_key.present? + end + def client @client ||= TinyAppstoreConnect::Client.new( issuer_id: issuer_id, diff --git a/app/views/admin/apple_keys/_form.html.slim b/app/views/admin/apple_keys/_form.html.slim index f5cbe2a40..e9b22c0b2 100644 --- a/app/views/admin/apple_keys/_form.html.slim +++ b/app/views/admin/apple_keys/_form.html.slim @@ -7,7 +7,6 @@ - if @apple_key.new_record? = f.input :private_key, as: :file - if @apple_key.errors.size > 0 - = f.input :filename, disabled: true = f.input :checksum, disabled: true - else = f.input :filename, disabled: true