Skip to content

Commit

Permalink
fix(web): show errors message on create apple developer page
Browse files Browse the repository at this point in the history
  • Loading branch information
icyleaf committed Jan 14, 2025
1 parent 02ce98e commit 78395ce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
14 changes: 9 additions & 5 deletions app/models/apple_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion app/views/admin/apple_keys/_form.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 78395ce

Please sign in to comment.