30 行
900 B
Ruby
30 行
900 B
Ruby
class MaterialImportBlock < ApplicationRecord
|
|
MATCH_KINDS = ['sha256', 'exact_path', 'path_prefix', 'manual'].freeze
|
|
REASONS = [
|
|
'copyright_high_risk',
|
|
'copyright_takedown',
|
|
'adult_or_sensitive',
|
|
'personal_information',
|
|
'malware_or_dangerous_file',
|
|
'duplicate_or_low_quality',
|
|
'source_owner_request',
|
|
'other'
|
|
].freeze
|
|
|
|
belongs_to :created_by_user, class_name: 'User', optional: true
|
|
|
|
validates :match_kind, presence: true, inclusion: { in: MATCH_KINDS }
|
|
validates :reason, presence: true, inclusion: { in: REASONS }
|
|
validates :sha256, length: { is: 64 }, allow_blank: true
|
|
validate :match_value_must_be_present
|
|
|
|
private
|
|
|
|
def match_value_must_be_present
|
|
return if match_kind == 'manual'
|
|
return if sha256.present? || external_path_pattern.present?
|
|
|
|
errors.add(:base, 'sha256 または external_path_pattern は必須です.')
|
|
end
|
|
end
|