Skip to content

Commit

Permalink
Fix cancellation of scheduled meetings
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmir committed Dec 4, 2024
1 parent 9140018 commit d739bca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
26 changes: 12 additions & 14 deletions modules/meeting/app/controllers/recurring_meetings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class RecurringMeetingsController < ApplicationController
before_action :find_optional_project, only: %i[index show new create update details_dialog destroy edit delete_scheduled]
before_action :authorize_global, only: %i[index new create]
before_action :authorize, except: %i[index new create]
before_action :get_scheduled_meeting, only: %i[delete_scheduled]

before_action :convert_params, only: %i[create update]

Expand Down Expand Up @@ -142,22 +143,13 @@ def destroy
end

def delete_scheduled # rubocop:disable Metrics/AbcSize

Check warning on line 145 in modules/meeting/app/controllers/recurring_meetings_controller.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] modules/meeting/app/controllers/recurring_meetings_controller.rb#L145 <Lint/RedundantCopDisableDirective>

Unnecessary disabling of `Metrics/AbcSize`.
Raw output
modules/meeting/app/controllers/recurring_meetings_controller.rb:145:24: W: Lint/RedundantCopDisableDirective: Unnecessary disabling of `Metrics/AbcSize`.
call = ::RecurringMeetings::InitOccurrenceService
.new(user: current_user, recurring_meeting: @recurring_meeting)
.call(start_time: DateTime.iso8601(params[:start_time]))

if call.success?
::Meetings::DeleteService
.new(model: call.result, user: current_user)
.call
.on_success { flash[:notice] = I18n.t(:notice_successful_cancel) }
.on_failure { |delete_call| flash[:error] = delete_call.message }

redirect_to polymorphic_path([@project, @recurring_meeting]), status: :see_other
if @scheduled.update(cancelled: true)
flash[:notice] = I18n.t(:notice_successful_cancel)
else
flash[:error] = call.message
redirect_to action: :show, id: @recurring_meeting
flash[:error] = I18n.t(:error_failed_to_delete_entry)
end

redirect_to polymorphic_path([@project, @recurring_meeting]), status: :see_other
end

private
Expand All @@ -181,6 +173,12 @@ def scheduled_meeting(start_time)
ScheduledMeeting.new(start_time:, recurring_meeting: @recurring_meeting)
end

def get_scheduled_meeting
@scheduled = @recurring_meeting.scheduled_meetings.find_or_initialize_by(start_time: params[:start_time])

render_400 unless @scheduled.meeting_id.nil?
end

def find_optional_project
@project = Project.find(params[:project_id]) if params[:project_id].present?
rescue ActiveRecord::RecordNotFound
Expand Down
2 changes: 1 addition & 1 deletion modules/meeting/app/models/scheduled_meeting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ class ScheduledMeeting < ApplicationRecord

scope :cancelled, -> { where(cancelled: true) }

validates_uniqueness_of :meeting
validates_uniqueness_of :meeting, allow_nil: true
validates_presence_of :start_time
end

0 comments on commit d739bca

Please sign in to comment.