Some checks failed
Lock Threads / action (push) Has been cancelled
Mark stale issues and pull requests / stale (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot EE docker images / merge (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot CE docker images / merge (push) Has been cancelled
Run Chatwoot CE spec / lint-backend (push) Has been cancelled
Run Chatwoot CE spec / lint-frontend (push) Has been cancelled
Run Chatwoot CE spec / frontend-tests (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (0, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (1, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (10, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (11, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (12, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (13, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (14, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (15, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (2, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (3, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (4, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (5, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (6, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (7, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (8, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (9, 16) (push) Has been cancelled
Run Linux nightly installer / nightly (push) Has been cancelled
- Add Logistics component with progress tracking - Add OrderDetail component for order information - Support data-driven steps and actions - Add blue color scale to widget SCSS - Fix node overflow and progress bar rendering issues - Add English translations for dashboard components Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
53 lines
2.2 KiB
Ruby
53 lines
2.2 KiB
Ruby
class ContentAttributeValidator < ActiveModel::Validator
|
|
ALLOWED_SELECT_ITEM_KEYS = [:title, :value].freeze
|
|
ALLOWED_CARD_ITEM_KEYS = [:title, :description, :media_url, :actions].freeze
|
|
ALLOWED_CARD_ITEM_ACTION_KEYS = [:text, :type, :payload, :uri].freeze
|
|
ALLOWED_FORM_ITEM_KEYS = [:type, :placeholder, :label, :name, :options, :default, :required, :pattern, :title, :pattern_error].freeze
|
|
ALLOWED_ARTICLE_KEYS = [:title, :description, :link].freeze
|
|
|
|
def validate(record)
|
|
case record.content_type
|
|
when 'input_select'
|
|
validate_items!(record)
|
|
validate_item_attributes!(record, ALLOWED_SELECT_ITEM_KEYS)
|
|
when 'cards'
|
|
validate_items!(record)
|
|
validate_item_attributes!(record, ALLOWED_CARD_ITEM_KEYS)
|
|
validate_item_actions!(record)
|
|
when 'form'
|
|
validate_items!(record)
|
|
validate_item_attributes!(record, ALLOWED_FORM_ITEM_KEYS)
|
|
when 'article'
|
|
validate_items!(record)
|
|
validate_item_attributes!(record, ALLOWED_ARTICLE_KEYS)
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def validate_items!(record)
|
|
record.errors.add(:content_attributes, 'At least one item is required.') if record.items.blank?
|
|
record.errors.add(:content_attributes, 'Items should be a hash.') if record.items.reject { |item| item.is_a?(Hash) }.present?
|
|
end
|
|
|
|
def validate_item_attributes!(record, valid_keys)
|
|
item_keys = record.items.collect(&:keys).flatten.filter_map(&:to_sym)
|
|
invalid_keys = item_keys - valid_keys
|
|
record.errors.add(:content_attributes, "contains invalid keys for items : #{invalid_keys}") if invalid_keys.present?
|
|
end
|
|
|
|
def validate_item_actions!(record)
|
|
if record.items.select { |item| item[:actions].blank? }.present?
|
|
record.errors.add(:content_attributes, 'contains items missing actions') && return
|
|
end
|
|
|
|
validate_item_action_attributes!(record)
|
|
end
|
|
|
|
def validate_item_action_attributes!(record)
|
|
item_action_keys = record.items.collect { |item| item[:actions].collect(&:keys) }
|
|
invalid_keys = item_action_keys.flatten.compact.map(&:to_sym) - ALLOWED_CARD_ITEM_ACTION_KEYS
|
|
record.errors.add(:content_attributes, "contains invalid keys for actions: #{invalid_keys}") if invalid_keys.present?
|
|
end
|
|
end
|