summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Zagorodny <vzagorodny@gitlab.com>2019-09-17 00:00:00 +0300
committerVictor Zagorodny <vzagorodny@gitlab.com>2019-09-18 13:30:19 +0300
commitb5a25fa0a4f89caf389adfa92365cbb7d2ddec5c (patch)
treea6586e5422f13549328c1e0dd56886df069aa5a7
parent5c578a9ca237617214451af559d80cf52bce8675 (diff)
downloadgitlab-ce-10242-create-vulnerability-model-ce.tar.gz
Add validations for Issuable-related fields10242-create-vulnerability-model-ce
-rw-r--r--app/models/concerns/issuable.rb11
-rw-r--r--doc/development/README.md1
-rw-r--r--doc/development/issuable-like-models.md19
3 files changed, 28 insertions, 3 deletions
diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb
index d02f3731cc2..38852f8ce44 100644
--- a/app/models/concerns/issuable.rb
+++ b/app/models/concerns/issuable.rb
@@ -4,7 +4,7 @@
#
# Contains common functionality shared between Issues and MergeRequests
#
-# Used by Issue, MergeRequest
+# Used by Issue, MergeRequest, Epic
#
module Issuable
extend ActiveSupport::Concern
@@ -26,6 +26,11 @@ module Issuable
include IssuableStates
include ClosedAtFilterable
+ TITLE_LENGTH_MAX = 255
+ TITLE_HTML_LENGTH_MAX = 800
+ DESCRIPTION_LENGTH_MAX = 16000
+ DESCRIPTION_HTML_LENGTH_MAX = 48000
+
# This object is used to gather issuable meta data for displaying
# upvotes, downvotes, notes and closing merge requests count for issues and merge requests
# lists avoiding n+1 queries and improving performance.
@@ -72,8 +77,8 @@ module Issuable
prefix: true
validates :author, presence: true
- validates :title, presence: true, length: { maximum: 255 }
- validates :description, length: { maximum: Gitlab::Database::MAX_TEXT_SIZE_LIMIT }, allow_blank: true
+ validates :title, presence: true, length: { maximum: TITLE_LENGTH_MAX }
+ validates :description, length: { maximum: DESCRIPTION_LENGTH_MAX }, allow_blank: true
validate :milestone_is_valid
scope :authored, ->(user) { where(author_id: user) }
diff --git a/doc/development/README.md b/doc/development/README.md
index e8bebc79124..9d6f1b1b73d 100644
--- a/doc/development/README.md
+++ b/doc/development/README.md
@@ -34,6 +34,7 @@ description: 'Learn how to contribute to GitLab.'
## Backend guides
- [GitLab utilities](utilities.md)
+- [Issuable-like Rails models](issuable-like-models.md)
- [Logging](logging.md)
- [API styleguide](api_styleguide.md) Use this styleguide if you are
contributing to the API
diff --git a/doc/development/issuable-like-models.md b/doc/development/issuable-like-models.md
new file mode 100644
index 00000000000..99432ef3bc0
--- /dev/null
+++ b/doc/development/issuable-like-models.md
@@ -0,0 +1,19 @@
+# Issuable-like Rails models utilities
+
+GitLab Rails codebase contains several models that hold common functionality and behave similarly to an [Issue]. Other
+examples of `Issuable`s are [Merge Requests] and [Epics].
+
+This guide accumulates guidelines on working with such Rails models.
+
+## Important text fields
+
+There are max length constraints for the most important text fields for `Issuable`s:
+
+- `title`: 255 chars
+- `title_html`: 800 chars
+- `description`: 16000 chars
+- `description_html`: 48000 chars
+
+[Issue]: https://docs.gitlab.com/ee/user/project/issues
+[Merge Requests]: https://docs.gitlab.com/ee/user/project/merge_requests
+[Epics]: https://docs.gitlab.com/ee/user/group/epics