Files
discourse/plugins/discourse-events/app/services/discourse_post_event/destroy_event.rb
T
David Battersby 629c919eb2 DEV: rename Discourse Calendar to Discourse Events (#42021)
Moves the plugin directory and associated files, along with updating
various import references.
2026-08-12 11:34:15 +04:00

48 lines
1.0 KiB
Ruby

# frozen_string_literal: true
module DiscoursePostEvent
class DestroyEvent
include Service::Base
params do
attribute :event_id, :integer
validates :event_id, presence: true
end
model :event
policy :can_act_on_event
step :publish_event_update
model :webhook_payload, :build_webhook_payload
transaction { step :destroy_event }
step :enqueue_destroyed_webhooks
private
def fetch_event(params:)
Event.includes(:image_upload).find_by(id: params.event_id)
end
def can_act_on_event(guardian:, event:)
guardian.can_act_on_discourse_post_event?(event)
end
def publish_event_update(event:)
event.publish_update!
end
def build_webhook_payload(event:)
WebHook.build_calendar_event_payload(event)
end
def destroy_event(event:)
event.destroy!
end
def enqueue_destroyed_webhooks(event:, webhook_payload:)
WebHook.enqueue_calendar_event_hooks(:calendar_event_destroyed, event, webhook_payload)
end
end
end