Skip to content

Commit 48aeb70

Browse files
1 parent 8eca192 commit 48aeb70

3 files changed

Lines changed: 47 additions & 0 deletions

File tree

modules/meeting/app/contracts/meetings/update_contract.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class UpdateContract < BaseContract
3535

3636
validate :user_allowed_to_edit_in_source_project
3737
validate :user_allowed_to_edit_in_destination_project
38+
validate :meeting_is_editable
3839
validate :valid_rescheduling_date, if: -> { check_reschedule? }
3940

4041
attribute :lock_version do
@@ -57,6 +58,12 @@ def user_allowed_to_edit_in_destination_project
5758
end
5859
end
5960

61+
def meeting_is_editable
62+
return unless user.allowed_in_project?(:edit_meetings, model.project)
63+
64+
errors.add :base, I18n.t(:text_meeting_not_editable_anymore) unless model.editable?(user)
65+
end
66+
6067
def valid_rescheduling_date # rubocop:disable Metrics/AbcSize
6168
if model.start_time < Time.zone.now
6269
errors.add :start_date, :after_today

modules/meeting/spec/contracts/meetings/update_contract_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@
6666

6767
it_behaves_like "contract is invalid", base: :error_conflict
6868
end
69+
70+
context "when meeting is closed" do
71+
before do
72+
meeting.update_column(:state, :closed)
73+
end
74+
75+
it_behaves_like "contract is invalid", base: I18n.t(:text_meeting_not_editable_anymore)
76+
end
6977
end
7078

7179
context "without permission" do

modules/meeting/spec/requests/meetings_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,38 @@
6565
end
6666
end
6767

68+
describe "update_details" do
69+
let(:details_params) do
70+
{
71+
project_id: project.id,
72+
id: meeting.id,
73+
meeting: {
74+
title: "Modified title",
75+
start_date: Date.current.to_s,
76+
duration: "1h",
77+
location: "Modified location",
78+
lock_version: meeting.lock_version
79+
}
80+
}
81+
end
82+
83+
context "when meeting is closed" do
84+
before do
85+
meeting.update_column(:state, :closed)
86+
end
87+
88+
it "rejects the update" do
89+
expect do
90+
put update_details_project_meeting_path(project, meeting),
91+
params: details_params,
92+
as: :turbo_stream
93+
end.not_to change { meeting.reload.attributes.slice("title", "start_time", "duration", "location") }
94+
95+
expect(response).to have_http_status(:bad_request)
96+
end
97+
end
98+
end
99+
68100
describe "copy" do
69101
let(:base_params) do
70102
{

0 commit comments

Comments
 (0)