Skip to content

Commit

Permalink
fix: 创建网络钩子异常
Browse files Browse the repository at this point in the history
relates #1381
  • Loading branch information
icyleaf committed Jan 5, 2024
1 parent 02dedbf commit 1db5d6e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/models/web_hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ class WebHook < ApplicationRecord
delegate :count, to: :channels, prefix: true

validates :channel_id, :url, presence: true
validates :body, json: { allow_blank: true }
validates :body, json: { format: :hash, value_allow_empty: true }
end
8 changes: 4 additions & 4 deletions app/validators/json_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ def initialize(options)
end

def validate_each(record, attribute, value)
return true if value.blank? && @allow_value_empty

parsed_value = _json(record, attribute, value)
validate_format(record, attribute, parsed_value)
validate_value(record, attribute, parsed_value)
validate_format(record, attribute, parsed_value)

true
end

private

def validate_value(record, attribute, value)
return if @allow_value_empty

record.errors.add(attribute, :empty_json_value) if value.empty?
record.errors.add(attribute, :empty_json_value) if value.blank?
end

def validate_format(record, attribute, value)
Expand Down

0 comments on commit 1db5d6e

Please sign in to comment.