Merge branch 'general-cleanup'

This commit is contained in:
Vinoth Kannan 2018-09-06 23:57:59 +05:30
commit 0df19fbc5a
4 changed files with 15 additions and 34 deletions

View File

@ -15,6 +15,8 @@ export default {
withPluginApi('0.1', api => {
const usersOnHoliday = Discourse.Site.current().users_on_holiday;
if (!usersOnHoliday) { return; }
api.addPosterIcon(cfs => {
const onHoliday = customBool(cfs.on_holiday);
if (!onHoliday) { return; }

View File

@ -2,8 +2,7 @@ module DiscourseSimpleCalendar
class EventUpdater
def self.update(post)
op = post.topic.first_post
dates = DiscourseSimpleCalendar::Dates.extract(post.raw, post.topic_id, post.user.id)
dates = post.local_dates
# if we dont have any date it's not an event anymore
if dates.empty?

View File

@ -25,20 +25,21 @@ after_initialize do
TO_INDEX = 2
USERNAME_INDEX = 3
autoload :CalendarValidator, "#{Rails.root}/plugins/discourse-simple-calendar/lib/calendar_validator"
autoload :CalendarUpdater, "#{Rails.root}/plugins/discourse-simple-calendar/lib/calendar_updater"
autoload :CalendarDestroyer, "#{Rails.root}/plugins/discourse-simple-calendar/lib/calendar_destroyer"
autoload :EventValidator, "#{Rails.root}/plugins/discourse-simple-calendar/lib/event_validator"
autoload :EventUpdater, "#{Rails.root}/plugins/discourse-simple-calendar/lib/event_updater"
autoload :EventDestroyer, "#{Rails.root}/plugins/discourse-simple-calendar/lib/event_destroyer"
def self.users_on_holiday
PluginStore.get(PLUGIN_NAME, USERS_ON_HOLIDAY_KEY)
end
end
require File.expand_path("../jobs/scheduled/ensure_expired_event_destruction", __FILE__)
require File.expand_path("../jobs/scheduled/update_holiday_usernames", __FILE__)
[
"../lib/calendar_validator.rb",
"../lib/calendar_updater.rb",
"../lib/calendar_destroyer.rb",
"../lib/event_validator.rb",
"../lib/event_updater.rb",
"../lib/event_destroyer.rb",
"../jobs/scheduled/ensure_expired_event_destruction.rb",
"../jobs/scheduled/update_holiday_usernames.rb",
].each { |path| load File.expand_path(path, __FILE__) }
register_post_custom_field_type(DiscourseSimpleCalendar::CALENDAR_DETAILS_CUSTOM_FIELD, :json)
register_post_custom_field_type(DiscourseSimpleCalendar::CALENDAR_CUSTOM_FIELD, :string)
@ -65,27 +66,6 @@ after_initialize do
end
end
# should be moved into discourse-local-dates plugin code
class DiscourseSimpleCalendar::Dates
class << self
def extract(raw, topic_id, user_id = nil)
cooked = PrettyText.cook(raw, topic_id: topic_id, user_id: user_id)
Nokogiri::HTML(cooked).css('span.discourse-local-date').map do |cooked_date|
date = {}
cooked_date.attributes.values.each do |attribute|
if attribute.name && ['data-date', 'data-time'].include?(attribute.name)
unless attribute.value == 'undefined'
date[attribute.name.gsub('data-', '')] = CGI.escapeHTML(attribute.value || "")
end
end
end
date
end
end
end
end
on(:post_process_cooked) do |doc, post|
validator = DiscourseSimpleCalendar::EventValidator.new(post)
@ -161,6 +141,6 @@ after_initialize do
end
add_to_serializer(:site, :users_on_holiday) do
PluginStore.get(PLUGIN_NAME, DiscourseSimpleCalendar::USERS_ON_HOLIDAY_KEY)
DiscourseSimpleCalendar.users_on_holiday
end
end

View File

@ -27,7 +27,7 @@ describe DiscourseSimpleCalendar::EventUpdater do
expect(post.deleted_at).to be_nil
expect(op.custom_fields[DiscourseSimpleCalendar::CALENDAR_DETAILS_CUSTOM_FIELD][post_number]).to be_present
DiscourseSimpleCalendar::EnsuredExpiredEventDestruction.new.execute
DiscourseSimpleCalendar::EnsuredExpiredEventDestruction.new.execute(nil)
post.reload
op.reload