Files
discourse/plugins/discourse-events/app/services/discourse_post_event/invite.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

41 lines
851 B
Ruby

# frozen_string_literal: true
module DiscoursePostEvent
class Invite
include Service::Base
params do
attribute :event_id, :integer
attribute :invites
before_validation { self.invites = Array(invites) }
validates :event_id, presence: true
end
model :event
policy :can_act_on_event
model :invited_users, optional: true
step :notify_invited_users
private
def fetch_event(params:)
Event.find_by(id: params.event_id)
end
def can_act_on_event(guardian:, event:)
guardian.can_act_on_discourse_post_event?(event)
end
def fetch_invited_users(params:)
User.real.where(username: params.invites)
end
def notify_invited_users(event:, invited_users:)
invited_users.each { |user| event.create_notification!(user, event.post) }
end
end
end