mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-28 05:06:08 +08:00
This commit removes the `include_expired` param and its associated site setting `include_expired_events_on_calendar`. Since recent changes this performance optimisation doesn’t make sense anymore as we only load the events needed for a specific before/after range. The rules are the following: Non recurring events: - They have to have a start date between before/after range Recurring events: - they don't have event_dates, so we don't rely on it for them - what's important for recurring_event, is the recurring_until property and the original starts at - we want to return recurring events when their start date is is after the after param and the before param is before the recurring_until - if recurring_until is NULL we just look at the start date It's done this way as the serializer only sends the rrule to the front, and this is the frontend which will compute the recurring events, but if you want to have all the events of august, and your recurring event is starting in june, you need to also fetch this june event. This commit ensures we can now deal properly with nil dates as it makes no sense to have dates for an expired recurring event.
131 lines
3.7 KiB
Ruby
Vendored
131 lines
3.7 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
module DiscoursePostEvent
|
|
class EventsController < DiscoursePostEventController
|
|
def index
|
|
@events =
|
|
DiscoursePostEvent::EventFinder.search(current_user, filtered_events_params).includes(
|
|
post: :topic,
|
|
)
|
|
|
|
# The detailed serializer is currently not used anywhere in the frontend, but available via API
|
|
serializer = params[:include_details] == "true" ? EventSerializer : BasicEventSerializer
|
|
|
|
render json:
|
|
ActiveModel::ArraySerializer.new(
|
|
@events,
|
|
each_serializer: serializer,
|
|
scope: guardian,
|
|
).as_json
|
|
end
|
|
|
|
def invite
|
|
event = Event.find(params[:id])
|
|
guardian.ensure_can_act_on_discourse_post_event!(event)
|
|
invites = Array(params.permit(invites: [])[:invites])
|
|
users = User.real.where(username: invites)
|
|
|
|
users.each { |user| event.create_notification!(user, event.post) }
|
|
|
|
render json: success_json
|
|
end
|
|
|
|
def show
|
|
event = Event.find(params[:id])
|
|
guardian.ensure_can_see!(event.post)
|
|
serializer = EventSerializer.new(event, scope: guardian)
|
|
render_json_dump(serializer)
|
|
end
|
|
|
|
def destroy
|
|
event = Event.find(params[:id])
|
|
guardian.ensure_can_act_on_discourse_post_event!(event)
|
|
event.publish_update!
|
|
event.destroy
|
|
render json: success_json
|
|
end
|
|
|
|
def csv_bulk_invite
|
|
require "csv"
|
|
|
|
event = Event.find(params[:id])
|
|
guardian.ensure_can_edit!(event.post)
|
|
guardian.ensure_can_create_discourse_post_event!
|
|
|
|
file = params[:file] || (params[:files] || []).first
|
|
raise Discourse::InvalidParameters.new(:file) if file.blank?
|
|
|
|
hijack do
|
|
begin
|
|
invitees = []
|
|
|
|
CSV.foreach(file.tempfile) do |row|
|
|
invitees << { identifier: row[0], attendance: row[1] || "going" } if row[0].present?
|
|
end
|
|
|
|
if invitees.present?
|
|
Jobs.enqueue(
|
|
:discourse_post_event_bulk_invite,
|
|
event_id: event.id,
|
|
invitees: invitees,
|
|
current_user_id: current_user.id,
|
|
)
|
|
render json: success_json
|
|
else
|
|
render json:
|
|
failed_json.merge(
|
|
errors: [I18n.t("discourse_post_event.errors.bulk_invite.error")],
|
|
),
|
|
status: 422
|
|
end
|
|
rescue StandardError
|
|
render json:
|
|
failed_json.merge(
|
|
errors: [I18n.t("discourse_post_event.errors.bulk_invite.error")],
|
|
),
|
|
status: 422
|
|
end
|
|
end
|
|
end
|
|
|
|
def bulk_invite
|
|
event = Event.find(params[:id])
|
|
guardian.ensure_can_edit!(event.post)
|
|
guardian.ensure_can_create_discourse_post_event!
|
|
|
|
invitees = Array(params[:invitees]).reject { |x| x.empty? }
|
|
raise Discourse::InvalidParameters.new(:invitees) if invitees.blank?
|
|
|
|
begin
|
|
Jobs.enqueue(
|
|
:discourse_post_event_bulk_invite,
|
|
event_id: event.id,
|
|
invitees: invitees.as_json,
|
|
current_user_id: current_user.id,
|
|
)
|
|
render json: success_json
|
|
rescue StandardError
|
|
render json:
|
|
failed_json.merge(
|
|
errors: [I18n.t("discourse_post_event.errors.bulk_invite.error")],
|
|
),
|
|
status: 422
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def filtered_events_params
|
|
params.permit(
|
|
:post_id,
|
|
:category_id,
|
|
:include_subcategories,
|
|
:limit,
|
|
:before,
|
|
:attending_user,
|
|
:before,
|
|
:after,
|
|
)
|
|
end
|
|
end
|
|
end
|