Skip to content

Commit 20d631f

Browse files
committed
[#71059] Limit sprint goal text length
Keep sprint goals short enough for dialog entry and header display while leaving the column type unchanged. https://community.openproject.org/wp/71059
1 parent 7884c30 commit 20d631f

6 files changed

Lines changed: 26 additions & 3 deletions

File tree

modules/backlogs/app/forms/backlogs/sprints/owned_goal_form.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ class OwnedGoalForm < ApplicationForm
3939
f.text_field(
4040
name: :text,
4141
label: Sprint.human_attribute_name(:goal),
42-
disabled:
42+
disabled:,
43+
maxlength: SprintGoal::TEXT_MAX_LENGTH
4344
)
4445
end
4546
end

modules/backlogs/app/forms/backlogs/sprints/shared_goal_form.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class SharedGoalForm < ApplicationForm
4040
name: :text,
4141
label: goal_label,
4242
caption: I18n.t("backlogs.sprint_form.goal_caption"),
43-
disabled:
43+
disabled:,
44+
maxlength: SprintGoal::TEXT_MAX_LENGTH
4445
)
4546
end
4647

modules/backlogs/app/models/sprint_goal.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@
2929
#++
3030

3131
class SprintGoal < ApplicationRecord
32+
TEXT_MAX_LENGTH = 500
33+
3234
belongs_to :sprint, inverse_of: :goals
3335
belongs_to :project
3436

3537
normalizes :text, with: ->(text) { text.strip.presence }
3638

37-
validates :text, presence: true
39+
validates :text, presence: true, length: { maximum: TEXT_MAX_LENGTH }
3840

3941
validates :project_id,
4042
uniqueness: { scope: :sprint_id, message: :project_already_has_goal }

modules/backlogs/spec/forms/backlogs/sprints/owned_goal_form_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ def render_form
6767
expect(rendered_form).to have_field("sprint[goal][text]")
6868
end
6969

70+
it "limits the goal text field length" do
71+
expect(rendered_form).to have_css(
72+
"input[name='sprint[goal][text]'][maxlength='#{SprintGoal::TEXT_MAX_LENGTH}']"
73+
)
74+
end
75+
7076
it "does not render the shared sprint caption" do
7177
expect(rendered_form).to have_no_text(I18n.t("backlogs.sprint_form.goal_caption"))
7278
end

modules/backlogs/spec/forms/backlogs/sprints/shared_goal_form_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ def render_form
7070
expect(rendered_form).to have_field("sprint[goal][text]")
7171
end
7272

73+
it "limits the goal text field length" do
74+
expect(rendered_form).to have_css(
75+
"input[name='sprint[goal][text]'][maxlength='#{SprintGoal::TEXT_MAX_LENGTH}']"
76+
)
77+
end
78+
7379
it "renders the shared sprint caption" do
7480
expect(rendered_form).to have_text(I18n.t("backlogs.sprint_form.goal_caption"))
7581
end

modules/backlogs/spec/models/sprint_goal_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@
5959
expect(sprint_goal).not_to be_valid
6060
end
6161

62+
it "limits text to 500 characters" do
63+
sprint_goal.text = "a" * 501
64+
65+
expect(sprint_goal).not_to be_valid
66+
expect(sprint_goal.errors).to be_added(:text, :too_long, count: 500)
67+
end
68+
6269
it "validates uniqueness of project_id scoped to sprint_id" do
6370
sprint_goal.save!
6471
expect(sprint_goal).to validate_uniqueness_of(:project_id)

0 commit comments

Comments
 (0)