mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-04 00:20:20 +08:00
27 lines
628 B
Ruby
27 lines
628 B
Ruby
# frozen_string_literal: true
|
|
|
|
module DiscourseCalendar
|
|
class CalendarValidator
|
|
def initialize(post)
|
|
@post = post
|
|
end
|
|
|
|
def validate_calendar
|
|
extracted_calendars = DiscourseCalendar::Calendar.extract(@post)
|
|
|
|
return false if extracted_calendars.count == 0
|
|
|
|
if extracted_calendars.count > 1
|
|
@post.errors.add(:base, I18n.t("discourse_calendar.more_than_one_calendar"))
|
|
return false
|
|
end
|
|
|
|
if !@post.is_first_post?
|
|
@post.errors.add(:base, I18n.t("discourse_calendar.calendar_must_be_in_first_post"))
|
|
return false
|
|
end
|
|
|
|
true
|
|
end
|
|
end
|
|
end
|