Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kazuhiko Shiozaki
gitlab-ce
Commits
ad6a771d
Commit
ad6a771d
authored
Dec 01, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add custom LineCodeValidator
parent
96e51a03
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
2 deletions
+14
-2
app/models/note.rb
app/models/note.rb
+1
-1
app/models/sent_notification.rb
app/models/sent_notification.rb
+1
-1
app/validators/line_code_validator.rb
app/validators/line_code_validator.rb
+12
-0
No files found.
app/models/note.rb
View file @
ad6a771d
...
...
@@ -44,7 +44,7 @@ class Note < ActiveRecord::Base
validates
:note
,
:project
,
presence:
true
validates
:note
,
uniqueness:
{
scope:
[
:author
,
:noteable_type
,
:noteable_id
]
},
if:
->
(
n
)
{
n
.
is_award
}
validates
:note
,
inclusion:
{
in:
Emoji
.
emojis_names
},
if:
->
(
n
)
{
n
.
is_award
}
validates
:line_code
,
format:
{
with:
/\A[a-z0-9]+_\d+_\d+\Z/
}
,
allow_blank:
true
validates
:line_code
,
line_code:
true
,
allow_blank:
true
# Attachments are deprecated and are handled by Markdown uploader
validates
:attachment
,
file_size:
{
maximum: :max_attachment_size
}
...
...
app/models/sent_notification.rb
View file @
ad6a771d
...
...
@@ -21,7 +21,7 @@ class SentNotification < ActiveRecord::Base
validates
:reply_key
,
uniqueness:
true
validates
:noteable_id
,
presence:
true
,
unless: :for_commit?
validates
:commit_id
,
presence:
true
,
if: :for_commit?
validates
:line_code
,
format:
{
with:
/\A[a-z0-9]+_\d+_\d+\Z/
}
,
allow_blank:
true
validates
:line_code
,
line_code:
true
,
allow_blank:
true
class
<<
self
def
reply_key
...
...
app/validators/line_code_validator.rb
0 → 100644
View file @
ad6a771d
# LineCodeValidator
#
# Custom validator for GitLab line codes.
class
LineCodeValidator
<
ActiveModel
::
EachValidator
PATTERN
=
/\A[a-z0-9]+_\d+_\d+\z/
.
freeze
def
validate_each
(
record
,
attribute
,
value
)
unless
value
=~
PATTERN
record
.
errors
.
add
(
attribute
,
"must be a valid line code"
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment