DEV: Update plugin to match latest guidelines (#390)
- Define extension modules - Use different files instead of plugin.rb - Make sure plugin is disabled according to the setting
This commit is contained in:
parent
c25461d0d2
commit
8f69c1165b
|
@ -1,11 +0,0 @@
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
module Admin::DiscourseCalendar
|
|
||||||
class AdminDiscourseCalendarController < Admin::AdminController
|
|
||||||
before_action :ensure_calendar_enabled
|
|
||||||
|
|
||||||
def ensure_calendar_enabled
|
|
||||||
raise Discourse::NotFound if !SiteSetting.calendar_enabled
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,7 +1,9 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Admin::DiscourseCalendar
|
module Admin::DiscourseCalendar
|
||||||
class AdminHolidaysController < AdminDiscourseCalendarController
|
class AdminHolidaysController < Admin::AdminController
|
||||||
|
requires_plugin DiscourseCalendar::PLUGIN_NAME
|
||||||
|
|
||||||
def index
|
def index
|
||||||
region_code = params[:region_code]
|
region_code = params[:region_code]
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,11 @@
|
||||||
|
|
||||||
module DiscoursePostEvent
|
module DiscoursePostEvent
|
||||||
class DiscoursePostEventController < ::ApplicationController
|
class DiscoursePostEventController < ::ApplicationController
|
||||||
|
requires_plugin DiscourseCalendar::PLUGIN_NAME
|
||||||
before_action :ensure_discourse_post_event_enabled
|
before_action :ensure_discourse_post_event_enabled
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
def ensure_discourse_post_event_enabled
|
def ensure_discourse_post_event_enabled
|
||||||
raise Discourse::NotFound if !SiteSetting.discourse_post_event_enabled
|
raise Discourse::NotFound if !SiteSetting.discourse_post_event_enabled
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module DiscoursePostEvent
|
||||||
|
module ExportCsvControllerExtension
|
||||||
|
def export_entity
|
||||||
|
if post_event_export? && ensure_can_export_post_event
|
||||||
|
Jobs.enqueue(
|
||||||
|
:export_csv_file,
|
||||||
|
entity: export_params[:entity],
|
||||||
|
user_id: current_user.id,
|
||||||
|
args: export_params[:args],
|
||||||
|
)
|
||||||
|
StaffActionLogger.new(current_user).log_entity_export(export_params[:entity])
|
||||||
|
render json: success_json
|
||||||
|
else
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def export_params
|
||||||
|
if post_event_export?
|
||||||
|
@_export_params ||=
|
||||||
|
begin
|
||||||
|
params.require(:entity)
|
||||||
|
params.permit(:entity, args: %i[id]).to_h
|
||||||
|
end
|
||||||
|
else
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def post_event_export?
|
||||||
|
params[:entity] === "post_event"
|
||||||
|
end
|
||||||
|
|
||||||
|
def ensure_can_export_post_event
|
||||||
|
return if !SiteSetting.discourse_post_event_enabled
|
||||||
|
|
||||||
|
post_event = DiscoursePostEvent::Event.find(export_params[:args][:id])
|
||||||
|
post_event && guardian.can_act_on_discourse_post_event?(post_event)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,37 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module DiscoursePostEvent
|
||||||
|
module ExportPostEventCsvReportExtension
|
||||||
|
def post_event_export(&block)
|
||||||
|
return enum_for(:post_event_export) unless block_given?
|
||||||
|
|
||||||
|
guardian = Guardian.new(current_user)
|
||||||
|
|
||||||
|
event = DiscoursePostEvent::Event.includes(invitees: :user).find(@extra[:id])
|
||||||
|
|
||||||
|
guardian.ensure_can_act_on_discourse_post_event!(event)
|
||||||
|
|
||||||
|
event
|
||||||
|
.invitees
|
||||||
|
.order(:id)
|
||||||
|
.each do |invitee|
|
||||||
|
yield(
|
||||||
|
[
|
||||||
|
invitee.user.username,
|
||||||
|
DiscoursePostEvent::Invitee.statuses[invitee.status],
|
||||||
|
invitee.created_at,
|
||||||
|
invitee.updated_at,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_header(entity)
|
||||||
|
if SiteSetting.discourse_post_event_enabled && entity === "post_event"
|
||||||
|
%w[username status first_answered_at last_updated_at]
|
||||||
|
else
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,23 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module DiscoursePostEvent
|
||||||
|
module PostExtension
|
||||||
|
def self.prepended(base)
|
||||||
|
base.class_eval do
|
||||||
|
has_one :event,
|
||||||
|
dependent: :destroy,
|
||||||
|
class_name: "DiscoursePostEvent::Event",
|
||||||
|
foreign_key: :id
|
||||||
|
|
||||||
|
validate :valid_event
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def valid_event
|
||||||
|
return unless self.raw_changed?
|
||||||
|
|
||||||
|
validator = DiscoursePostEvent::EventValidator.new(self)
|
||||||
|
validator.validate_event
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
349
plugin.rb
349
plugin.rb
|
@ -12,7 +12,7 @@ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
||||||
|
|
||||||
gem "rrule", "0.4.4", require: false
|
gem "rrule", "0.4.4", require: false
|
||||||
|
|
||||||
load File.expand_path("../lib/calendar_settings_validator.rb", __FILE__)
|
require_relative "lib/calendar_settings_validator.rb"
|
||||||
|
|
||||||
enabled_site_setting :calendar_enabled
|
enabled_site_setting :calendar_enabled
|
||||||
|
|
||||||
|
@ -50,6 +50,7 @@ after_initialize do
|
||||||
add_to_serializer :basic_category, :sort_topics_by_event_start_date do
|
add_to_serializer :basic_category, :sort_topics_by_event_start_date do
|
||||||
object.custom_fields["sort_topics_by_event_start_date"]
|
object.custom_fields["sort_topics_by_event_start_date"]
|
||||||
end
|
end
|
||||||
|
|
||||||
add_to_serializer :basic_category, :disable_topic_resorting do
|
add_to_serializer :basic_category, :disable_topic_resorting do
|
||||||
object.custom_fields["disable_topic_resorting"]
|
object.custom_fields["disable_topic_resorting"]
|
||||||
end
|
end
|
||||||
|
@ -74,22 +75,22 @@ after_initialize do
|
||||||
end
|
end
|
||||||
|
|
||||||
module ::DiscourseCalendar
|
module ::DiscourseCalendar
|
||||||
PLUGIN_NAME ||= "discourse-calendar"
|
PLUGIN_NAME = "discourse-calendar"
|
||||||
|
|
||||||
# Type of calendar ('static' or 'dynamic')
|
# Type of calendar ('static' or 'dynamic')
|
||||||
CALENDAR_CUSTOM_FIELD ||= "calendar"
|
CALENDAR_CUSTOM_FIELD = "calendar"
|
||||||
|
|
||||||
# User custom field set when user is on holiday
|
# User custom field set when user is on holiday
|
||||||
HOLIDAY_CUSTOM_FIELD ||= "on_holiday"
|
HOLIDAY_CUSTOM_FIELD = "on_holiday"
|
||||||
|
|
||||||
# List of all users on holiday
|
# List of all users on holiday
|
||||||
USERS_ON_HOLIDAY_KEY ||= "users_on_holiday"
|
USERS_ON_HOLIDAY_KEY = "users_on_holiday"
|
||||||
|
|
||||||
# User region used in finding holidays
|
# User region used in finding holidays
|
||||||
REGION_CUSTOM_FIELD ||= "holidays-region"
|
REGION_CUSTOM_FIELD = "holidays-region"
|
||||||
|
|
||||||
# List of groups
|
# List of groups
|
||||||
GROUP_TIMEZONES_CUSTOM_FIELD ||= "group-timezones"
|
GROUP_TIMEZONES_CUSTOM_FIELD = "group-timezones"
|
||||||
|
|
||||||
def self.users_on_holiday
|
def self.users_on_holiday
|
||||||
PluginStore.get(PLUGIN_NAME, USERS_ON_HOLIDAY_KEY) || []
|
PluginStore.get(PLUGIN_NAME, USERS_ON_HOLIDAY_KEY) || []
|
||||||
|
@ -106,11 +107,11 @@ after_initialize do
|
||||||
end
|
end
|
||||||
|
|
||||||
module ::DiscoursePostEvent
|
module ::DiscoursePostEvent
|
||||||
PLUGIN_NAME ||= "discourse-post-event"
|
PLUGIN_NAME = "discourse-post-event"
|
||||||
|
|
||||||
# Topic where op has a post event custom field
|
# Topic where op has a post event custom field
|
||||||
TOPIC_POST_EVENT_STARTS_AT ||= "TopicEventStartsAt"
|
TOPIC_POST_EVENT_STARTS_AT = "TopicEventStartsAt"
|
||||||
TOPIC_POST_EVENT_ENDS_AT ||= "TopicEventEndsAt"
|
TOPIC_POST_EVENT_ENDS_AT = "TopicEventEndsAt"
|
||||||
|
|
||||||
class Engine < ::Rails::Engine
|
class Engine < ::Rails::Engine
|
||||||
engine_name PLUGIN_NAME
|
engine_name PLUGIN_NAME
|
||||||
|
@ -123,11 +124,10 @@ after_initialize do
|
||||||
add_admin_route "admin.calendar", "calendar"
|
add_admin_route "admin.calendar", "calendar"
|
||||||
|
|
||||||
%w[
|
%w[
|
||||||
../app/controllers/admin/admin_discourse_calendar_controller.rb
|
app/controllers/admin/discourse_calendar/admin_holidays_controller.rb
|
||||||
../app/controllers/admin/discourse_calendar/admin_holidays_controller.rb
|
app/models/discourse_calendar/disabled_holiday.rb
|
||||||
../app/models/discourse_calendar/disabled_holiday.rb
|
app/services/discourse_calendar/holiday.rb
|
||||||
../app/services/discourse_calendar/holiday.rb
|
].each { |path| require_relative path }
|
||||||
].each { |path| load File.expand_path(path, __FILE__) }
|
|
||||||
|
|
||||||
Discourse::Application.routes.append do
|
Discourse::Application.routes.append do
|
||||||
mount ::DiscourseCalendar::Engine, at: "/"
|
mount ::DiscourseCalendar::Engine, at: "/"
|
||||||
|
@ -147,23 +147,26 @@ after_initialize do
|
||||||
# DISCOURSE POST EVENT
|
# DISCOURSE POST EVENT
|
||||||
|
|
||||||
%w[
|
%w[
|
||||||
../app/controllers/discourse_post_event_controller.rb
|
app/controllers/discourse_post_event_controller.rb
|
||||||
../app/controllers/discourse_post_event/invitees_controller.rb
|
app/controllers/discourse_post_event/events_controller.rb
|
||||||
../app/controllers/discourse_post_event/events_controller.rb
|
app/controllers/discourse_post_event/invitees_controller.rb
|
||||||
../app/controllers/discourse_post_event/upcoming_events_controller.rb
|
app/controllers/discourse_post_event/upcoming_events_controller.rb
|
||||||
../app/models/discourse_post_event/event.rb
|
app/models/discourse_post_event/event_date.rb
|
||||||
../app/models/discourse_post_event/event_date.rb
|
app/models/discourse_post_event/event.rb
|
||||||
../app/models/discourse_post_event/invitee.rb
|
app/models/discourse_post_event/invitee.rb
|
||||||
../lib/discourse_post_event/event_parser.rb
|
app/serializers/discourse_post_event/event_serializer.rb
|
||||||
../lib/discourse_post_event/event_validator.rb
|
app/serializers/discourse_post_event/invitee_serializer.rb
|
||||||
../lib/discourse_post_event/rrule_generator.rb
|
jobs/regular/discourse_post_event/bulk_invite.rb
|
||||||
../jobs/regular/discourse_post_event/bulk_invite.rb
|
jobs/regular/discourse_post_event/bump_topic.rb
|
||||||
../jobs/regular/discourse_post_event/send_reminder.rb
|
jobs/regular/discourse_post_event/send_reminder.rb
|
||||||
../jobs/regular/discourse_post_event/bump_topic.rb
|
lib/discourse_post_event/event_finder.rb
|
||||||
../lib/discourse_post_event/event_finder.rb
|
lib/discourse_post_event/event_parser.rb
|
||||||
../app/serializers/discourse_post_event/invitee_serializer.rb
|
lib/discourse_post_event/event_validator.rb
|
||||||
../app/serializers/discourse_post_event/event_serializer.rb
|
lib/discourse_post_event/export_csv_controller_extension.rb
|
||||||
].each { |path| load File.expand_path(path, __FILE__) }
|
lib/discourse_post_event/export_csv_file_extension.rb
|
||||||
|
lib/discourse_post_event/post_extension.rb
|
||||||
|
lib/discourse_post_event/rrule_generator.rb
|
||||||
|
].each { |path| require_relative path }
|
||||||
|
|
||||||
::ActionController::Base.prepend_view_path File.expand_path("../app/views", __FILE__)
|
::ActionController::Base.prepend_view_path File.expand_path("../app/views", __FILE__)
|
||||||
|
|
||||||
|
@ -185,16 +188,9 @@ after_initialize do
|
||||||
end
|
end
|
||||||
|
|
||||||
reloadable_patch do
|
reloadable_patch do
|
||||||
Post.class_eval do
|
ExportCsvController.class_eval { prepend DiscoursePostEvent::ExportCsvControllerExtension }
|
||||||
has_one :event, dependent: :destroy, class_name: "DiscoursePostEvent::Event", foreign_key: :id
|
Jobs::ExportCsvFile.class_eval { prepend DiscoursePostEvent::ExportPostEventCsvReportExtension }
|
||||||
|
Post.class_eval { prepend DiscoursePostEvent::PostExtension }
|
||||||
validate :valid_event
|
|
||||||
def valid_event
|
|
||||||
return unless self.raw_changed?
|
|
||||||
validator = DiscoursePostEvent::EventValidator.new(self)
|
|
||||||
validator.validate_event
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
add_to_class(:user, :can_create_discourse_post_event?) do
|
add_to_class(:user, :can_create_discourse_post_event?) do
|
||||||
|
@ -317,20 +313,20 @@ after_initialize do
|
||||||
# DISCOURSE CALENDAR
|
# DISCOURSE CALENDAR
|
||||||
|
|
||||||
%w[
|
%w[
|
||||||
../app/models/calendar_event.rb
|
app/models/calendar_event.rb
|
||||||
../app/serializers/user_timezone_serializer.rb
|
app/serializers/user_timezone_serializer.rb
|
||||||
../jobs/scheduled/create_holiday_events.rb
|
jobs/scheduled/create_holiday_events.rb
|
||||||
../jobs/scheduled/delete_expired_event_posts.rb
|
jobs/scheduled/delete_expired_event_posts.rb
|
||||||
../jobs/scheduled/update_holiday_usernames.rb
|
jobs/scheduled/monitor_event_dates.rb
|
||||||
../jobs/scheduled/monitor_event_dates.rb
|
jobs/scheduled/update_holiday_usernames.rb
|
||||||
../lib/calendar_validator.rb
|
lib/calendar_validator.rb
|
||||||
../lib/calendar.rb
|
lib/calendar.rb
|
||||||
../lib/event_validator.rb
|
lib/event_validator.rb
|
||||||
../lib/group_timezones.rb
|
lib/group_timezones.rb
|
||||||
../lib/time_sniffer.rb
|
lib/holiday_status.rb
|
||||||
../lib/users_on_holiday.rb
|
lib/time_sniffer.rb
|
||||||
../lib/holiday_status.rb
|
lib/users_on_holiday.rb
|
||||||
].each { |path| load File.expand_path(path, __FILE__) }
|
].each { |path| require_relative path }
|
||||||
|
|
||||||
register_post_custom_field_type(DiscourseCalendar::CALENDAR_CUSTOM_FIELD, :string)
|
register_post_custom_field_type(DiscourseCalendar::CALENDAR_CUSTOM_FIELD, :string)
|
||||||
register_post_custom_field_type(DiscourseCalendar::GROUP_TIMEZONES_CUSTOM_FIELD, :json)
|
register_post_custom_field_type(DiscourseCalendar::GROUP_TIMEZONES_CUSTOM_FIELD, :json)
|
||||||
|
@ -476,176 +472,89 @@ after_initialize do
|
||||||
|
|
||||||
add_to_serializer(:site, :include_users_on_holiday?) { scope.is_staff? }
|
add_to_serializer(:site, :include_users_on_holiday?) { scope.is_staff? }
|
||||||
|
|
||||||
reloadable_patch do
|
on(:reduce_cooked) do |fragment, post|
|
||||||
module DiscoursePostEvent::ExportCsvControllerExtension
|
if SiteSetting.discourse_post_event_enabled
|
||||||
def export_entity
|
fragment
|
||||||
if post_event_export? && ensure_can_export_post_event
|
.css(".discourse-post-event")
|
||||||
Jobs.enqueue(
|
.each do |event_node|
|
||||||
:export_csv_file,
|
starts_at = event_node["data-start"]
|
||||||
entity: export_params[:entity],
|
ends_at = event_node["data-end"]
|
||||||
user_id: current_user.id,
|
dates = "#{starts_at} (#{event_node["data-timezone"] || "UTC"})"
|
||||||
args: export_params[:args],
|
dates = "#{dates} → #{ends_at} (#{event_node["data-timezone"] || "UTC"})" if ends_at
|
||||||
|
|
||||||
|
event_name = event_node["data-name"] || post.topic.title
|
||||||
|
event_node.replace <<~TXT
|
||||||
|
<div style='border:1px solid #dedede'>
|
||||||
|
<p><a href="#{Discourse.base_url}#{post.url}">#{event_name}</a></p>
|
||||||
|
<p>#{dates}</p>
|
||||||
|
</div>
|
||||||
|
TXT
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
on(:user_destroyed) { |user| DiscoursePostEvent::Invitee.where(user_id: user.id).destroy_all }
|
||||||
|
|
||||||
|
if respond_to?(:add_post_revision_notifier_recipients)
|
||||||
|
add_post_revision_notifier_recipients do |post_revision|
|
||||||
|
# next if no modifications
|
||||||
|
next if !post_revision.modifications.present?
|
||||||
|
|
||||||
|
# do no notify recipients when only updating tags
|
||||||
|
next if post_revision.modifications.keys == ["tags"]
|
||||||
|
|
||||||
|
ids = []
|
||||||
|
post = post_revision.post
|
||||||
|
|
||||||
|
if post && post.is_first_post? && post.event
|
||||||
|
ids.concat(post.event.on_going_event_invitees.pluck(:user_id))
|
||||||
|
end
|
||||||
|
|
||||||
|
ids
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
on(:site_setting_changed) do |name, old_val, new_val|
|
||||||
|
next if name != :discourse_post_event_allowed_custom_fields
|
||||||
|
|
||||||
|
previous_fields = old_val.split("|")
|
||||||
|
new_fields = new_val.split("|")
|
||||||
|
removed_fields = previous_fields - new_fields
|
||||||
|
|
||||||
|
next if removed_fields.empty?
|
||||||
|
|
||||||
|
DiscoursePostEvent::Event.all.find_each do |event|
|
||||||
|
removed_fields.each { |field| event.custom_fields.delete(field) }
|
||||||
|
event.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if defined?(DiscourseAutomation)
|
||||||
|
on(:discourse_post_event_event_started) do |event|
|
||||||
|
DiscourseAutomation::Automation
|
||||||
|
.where(enabled: true, trigger: "event_started")
|
||||||
|
.each do |automation|
|
||||||
|
fields = automation.serialized_fields
|
||||||
|
topic_id = fields.dig("topic_id", "value")
|
||||||
|
|
||||||
|
next unless event.post.topic.id.to_s == topic_id
|
||||||
|
|
||||||
|
automation.trigger!(
|
||||||
|
"kind" => "event_started",
|
||||||
|
"event" => event,
|
||||||
|
"placeholders" => {
|
||||||
|
"event_url" => event.url,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
StaffActionLogger.new(current_user).log_entity_export(export_params[:entity])
|
|
||||||
render json: success_json
|
|
||||||
else
|
|
||||||
super
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def export_params
|
|
||||||
if post_event_export?
|
|
||||||
@_export_params ||=
|
|
||||||
begin
|
|
||||||
params.require(:entity)
|
|
||||||
params.permit(:entity, args: %i[id]).to_h
|
|
||||||
end
|
|
||||||
else
|
|
||||||
super
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def post_event_export?
|
|
||||||
params[:entity] === "post_event"
|
|
||||||
end
|
|
||||||
|
|
||||||
def ensure_can_export_post_event
|
|
||||||
return if !SiteSetting.discourse_post_event_enabled
|
|
||||||
|
|
||||||
post_event = DiscoursePostEvent::Event.find(export_params[:args][:id])
|
|
||||||
post_event && guardian.can_act_on_discourse_post_event?(post_event)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
require_dependency "export_csv_controller"
|
add_triggerable_to_scriptable("event_started", "send_chat_message")
|
||||||
class ::ExportCsvController
|
|
||||||
prepend DiscoursePostEvent::ExportCsvControllerExtension
|
|
||||||
end
|
|
||||||
|
|
||||||
module ExportPostEventCsvReportExtension
|
add_automation_triggerable("event_started") do
|
||||||
def post_event_export(&block)
|
placeholder :event_url
|
||||||
return enum_for(:post_event_export) unless block_given?
|
|
||||||
|
|
||||||
guardian = Guardian.new(current_user)
|
field :topic_id, component: :text
|
||||||
|
|
||||||
event = DiscoursePostEvent::Event.includes(invitees: :user).find(@extra[:id])
|
|
||||||
|
|
||||||
guardian.ensure_can_act_on_discourse_post_event!(event)
|
|
||||||
|
|
||||||
event
|
|
||||||
.invitees
|
|
||||||
.order(:id)
|
|
||||||
.each do |invitee|
|
|
||||||
yield(
|
|
||||||
[
|
|
||||||
invitee.user.username,
|
|
||||||
DiscoursePostEvent::Invitee.statuses[invitee.status],
|
|
||||||
invitee.created_at,
|
|
||||||
invitee.updated_at,
|
|
||||||
]
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_header(entity)
|
|
||||||
if SiteSetting.discourse_post_event_enabled && entity === "post_event"
|
|
||||||
%w[username status first_answered_at last_updated_at]
|
|
||||||
else
|
|
||||||
super
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class Jobs::ExportCsvFile
|
|
||||||
prepend ExportPostEventCsvReportExtension
|
|
||||||
end
|
|
||||||
|
|
||||||
on(:reduce_cooked) do |fragment, post|
|
|
||||||
if SiteSetting.discourse_post_event_enabled
|
|
||||||
fragment
|
|
||||||
.css(".discourse-post-event")
|
|
||||||
.each do |event_node|
|
|
||||||
starts_at = event_node["data-start"]
|
|
||||||
ends_at = event_node["data-end"]
|
|
||||||
dates = "#{starts_at} (#{event_node["data-timezone"] || "UTC"})"
|
|
||||||
dates = "#{dates} → #{ends_at} (#{event_node["data-timezone"] || "UTC"})" if ends_at
|
|
||||||
|
|
||||||
event_name = event_node["data-name"] || post.topic.title
|
|
||||||
event_node.replace <<~TXT
|
|
||||||
<div style='border:1px solid #dedede'>
|
|
||||||
<p><a href="#{Discourse.base_url}#{post.url}">#{event_name}</a></p>
|
|
||||||
<p>#{dates}</p>
|
|
||||||
</div>
|
|
||||||
TXT
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
on(:user_destroyed) { |user| DiscoursePostEvent::Invitee.where(user_id: user.id).destroy_all }
|
|
||||||
|
|
||||||
if respond_to?(:add_post_revision_notifier_recipients)
|
|
||||||
add_post_revision_notifier_recipients do |post_revision|
|
|
||||||
# next if no modifications
|
|
||||||
next if !post_revision.modifications.present?
|
|
||||||
|
|
||||||
# do no notify recipients when only updating tags
|
|
||||||
next if post_revision.modifications.keys == ["tags"]
|
|
||||||
|
|
||||||
ids = []
|
|
||||||
post = post_revision.post
|
|
||||||
|
|
||||||
if post && post.is_first_post? && post.event
|
|
||||||
ids.concat(post.event.on_going_event_invitees.pluck(:user_id))
|
|
||||||
end
|
|
||||||
|
|
||||||
ids
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
on(:site_setting_changed) do |name, old_val, new_val|
|
|
||||||
next if name != :discourse_post_event_allowed_custom_fields
|
|
||||||
|
|
||||||
previous_fields = old_val.split("|")
|
|
||||||
new_fields = new_val.split("|")
|
|
||||||
removed_fields = previous_fields - new_fields
|
|
||||||
|
|
||||||
next if removed_fields.empty?
|
|
||||||
|
|
||||||
DiscoursePostEvent::Event.all.find_each do |event|
|
|
||||||
removed_fields.each { |field| event.custom_fields.delete(field) }
|
|
||||||
event.save
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if defined?(DiscourseAutomation)
|
|
||||||
on(:discourse_post_event_event_started) do |event|
|
|
||||||
DiscourseAutomation::Automation
|
|
||||||
.where(enabled: true, trigger: "event_started")
|
|
||||||
.each do |automation|
|
|
||||||
fields = automation.serialized_fields
|
|
||||||
topic_id = fields.dig("topic_id", "value")
|
|
||||||
|
|
||||||
next unless event.post.topic.id.to_s == topic_id
|
|
||||||
|
|
||||||
automation.trigger!(
|
|
||||||
"kind" => "event_started",
|
|
||||||
"event" => event,
|
|
||||||
"placeholders" => {
|
|
||||||
"event_url" => event.url,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
add_triggerable_to_scriptable("event_started", "send_chat_message")
|
|
||||||
|
|
||||||
add_automation_triggerable("event_started") do
|
|
||||||
placeholder :event_url
|
|
||||||
|
|
||||||
field :topic_id, component: :text
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue