mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-23 02:18:23 +08:00
29 lines
572 B
Ruby
Vendored
29 lines
572 B
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
class AssignStatusesValidator
|
|
def initialize(opts = {})
|
|
@opts = opts
|
|
end
|
|
|
|
def valid_value?(value)
|
|
statuses = value.split("|")
|
|
|
|
case
|
|
when statuses.size < 2
|
|
@reason = "too_few"
|
|
return false
|
|
when statuses.size != statuses.uniq.size
|
|
@reason = "duplicate"
|
|
return false
|
|
when Assignment.where.not(status: statuses).count > 0
|
|
@reason = "removed_in_use"
|
|
return false
|
|
end
|
|
|
|
true
|
|
end
|
|
|
|
def error_message
|
|
I18n.t("site_settings.errors.assign_statuses.#{@reason}")
|
|
end
|
|
end
|