Skip to content

Commit 1bc80b9

Browse files
[OP-19964] Fix 500 when creating a meeting outcome with an invalid kind (#24771)
* Fix 500 when creating a meeting outcome with an invalid kind MeetingOutcome's kind enum was declared without validate: true, so assigning an unrecognized value raised a raw Rails ArgumentError instead of a normal ActiveModel validation error, propagating uncaught through the API endpoint as a 500. Add validate: true to the enum declaration -- Rails then rejects an out-of-enum value through the usual validation path, returning a clean 422. * Add missing MeetingOutcome#kind locale entry CI's Units + Features job caught this live: the earlier fix in this PR (validate: true on the kind enum) means Rails now builds a real ActiveModel error message on an invalid kind, which needs human_attribute_name for the attribute -- a key that never existed for MeetingOutcome. Without it, the 422 path itself crashed with I18n::MissingTranslationData instead of returning the intended validation error. Verified live: before this entry, requesting 'activerecord.attributes.meeting_outcome.kind' raised; after, it resolves to "Kind" and the full validation message reads "Kind is not set to one of the allowed values." * Refactor meeting_section localization entries Removed duplicate meeting_section entries and adjusted presenter position. * Fix missing keys * Drop regression-test comment restating the PR description; fix stray trailing whitespace The trailing whitespace after "Title" was an unrelated artifact of the original diff's line touch. --------- Co-authored-by: Oliver Günther <o.guenther@openproject.com> Co-authored-by: Oliver Günther <mail@oliverguenther.de>
1 parent 929e697 commit 1bc80b9

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

modules/meeting/app/models/meeting_outcome.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class MeetingOutcome < ApplicationRecord
3636
information: 0,
3737
decision: 1,
3838
work_package: 2
39-
}.freeze, suffix: true, default: "information"
39+
}.freeze, suffix: true, default: "information", validate: true
4040

4141
validates :meeting_agenda_item, presence: true
4242
validates :notes, presence: { if: -> { information_kind? } }

modules/meeting/config/locales/en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ en:
6262
position: "Position"
6363
presenter: "Presenter"
6464
title: "Title"
65+
meeting_outcome:
66+
kind: "Kind"
6567
meeting_participant:
6668
attended: "Attended"
6769
invited: "Invited"

modules/meeting/spec/requests/api/v3/meeting_outcomes/outcomes_by_agenda_item_resource_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,29 @@
159159
end
160160
end
161161

162+
context "with an invalid kind value" do
163+
let(:body) do
164+
{
165+
kind: "not_a_real_kind",
166+
notes: { raw: "Outcome with invalid kind" },
167+
_links: {
168+
agendaItem: {
169+
href: api_v3_paths.meeting_agenda_item(agenda_item.id)
170+
}
171+
}
172+
}.to_json
173+
end
174+
175+
it "returns 422 rather than raising" do
176+
expect { response }.not_to raise_error
177+
expect(response).to have_http_status(:unprocessable_entity)
178+
end
179+
180+
it "does not create the outcome" do
181+
expect { response }.not_to change(MeetingOutcome, :count)
182+
end
183+
end
184+
162185
context "when creating a work package outcome" do
163186
let(:permissions) { %i[view_meetings manage_outcomes view_work_packages] }
164187
let(:work_package) { create(:work_package, project:) }

0 commit comments

Comments
 (0)