Skip to content

Commit 6766b2d

Browse files
committed
Add MeetingParticipants::DeleteService
1 parent c2f04e6 commit 6766b2d

File tree

3 files changed

+101
-3
lines changed

3 files changed

+101
-3
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# frozen_string_literal: true
2+
3+
#-- copyright
4+
# OpenProject is an open source project management software.
5+
# Copyright (C) the OpenProject GmbH
6+
#
7+
# This program is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU General Public License version 3.
9+
#
10+
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
11+
# Copyright (C) 2006-2013 Jean-Philippe Lang
12+
# Copyright (C) 2010-2013 the ChiliProject Team
13+
#
14+
# This program is free software; you can redistribute it and/or
15+
# modify it under the terms of the GNU General Public License
16+
# as published by the Free Software Foundation; either version 2
17+
# of the License, or (at your option) any later version.
18+
#
19+
# This program is distributed in the hope that it will be useful,
20+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
# GNU General Public License for more details.
23+
#
24+
# You should have received a copy of the GNU General Public License
25+
# along with this program; if not, write to the Free Software
26+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27+
#
28+
# See COPYRIGHT and LICENSE files for more details.
29+
#++
30+
31+
module MeetingParticipants
32+
class DeleteContract < ::DeleteContract
33+
delete_permission -> {
34+
model.meeting.project && user.allowed_in_project?(:edit_meetings, model.meeting.project)
35+
}
36+
end
37+
end

modules/meeting/app/controllers/meeting_participants_controller.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,19 @@ def toggle_attendance
7373
end
7474

7575
def destroy
76-
if @participant.destroy!
76+
call = MeetingParticipants::DeleteService
77+
.new(user: User.current, model: @participant)
78+
.call
79+
80+
if call.success?
7781
update_add_user_form_component_via_turbo_stream
7882
update_list_component_via_turbo_stream
7983
update_sidebar_participants_component_via_turbo_stream(meeting: @meeting)
80-
81-
respond_with_turbo_streams
84+
else
85+
render_error_flash_message_via_turbo_stream(message: join_flash_messages(call.errors))
8286
end
87+
88+
respond_with_turbo_streams
8389
end
8490

8591
def manage_participants_dialog
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# frozen_string_literal: true
2+
3+
#-- copyright
4+
# OpenProject is an open source project management software.
5+
# Copyright (C) the OpenProject GmbH
6+
#
7+
# This program is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU General Public License version 3.
9+
#
10+
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
11+
# Copyright (C) 2006-2013 Jean-Philippe Lang
12+
# Copyright (C) 2010-2013 the ChiliProject Team
13+
#
14+
# This program is free software; you can redistribute it and/or
15+
# modify it under the terms of the GNU General Public License
16+
# as published by the Free Software Foundation; either version 2
17+
# of the License, or (at your option) any later version.
18+
#
19+
# This program is distributed in the hope that it will be useful,
20+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
# GNU General Public License for more details.
23+
#
24+
# You should have received a copy of the GNU General Public License
25+
# along with this program; if not, write to the Free Software
26+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27+
#
28+
# See COPYRIGHT and LICENSE files for more details.
29+
#++
30+
31+
module MeetingParticipants
32+
class DeleteService < BaseServices::Delete
33+
protected
34+
35+
def after_validate(call)
36+
send_cancellation_notification(model) if should_send_notification?
37+
38+
call
39+
end
40+
41+
def send_cancellation_notification(participant)
42+
meeting = participant.meeting
43+
44+
if meeting.template?
45+
MeetingMailer.cancelled_series(meeting.recurring_meeting, participant.user, user).deliver_later
46+
else
47+
MeetingMailer.cancelled(meeting, participant.user, user).deliver_later
48+
end
49+
end
50+
51+
def should_send_notification?
52+
Journal::NotificationConfiguration.active? && model.meeting.send_emails?
53+
end
54+
end
55+
end

0 commit comments

Comments
 (0)