BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
728b0a5f
Commit
728b0a5f
authored
Feb 24, 2017
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce DurationValidator, feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/9219#note_24032923
parent
ac531c0e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
8 deletions
+18
-8
application_setting.rb
app/models/application_setting.rb
+1
-8
duration_validator.rb
app/validators/duration_validator.rb
+17
-0
No files found.
app/models/application_setting.rb
View file @
728b0a5f
...
...
@@ -80,8 +80,7 @@ class ApplicationSetting < ActiveRecord::Base
presence:
true
,
numericality:
{
only_integer:
true
,
greater_than:
0
}
validates
:default_artifacts_expire_in
,
presence:
true
validate
:check_default_artifacts_expire_in
validates
:default_artifacts_expire_in
,
presence:
true
,
duration:
true
validates
:container_registry_token_expire_delay
,
presence:
true
,
...
...
@@ -305,10 +304,4 @@ class ApplicationSetting < ActiveRecord::Base
errors
.
add
(
:repository_storages
,
"can't include:
#{
invalid
.
join
(
", "
)
}
"
)
unless
invalid
.
empty?
end
def
check_default_artifacts_expire_in
ChronicDuration
.
parse
(
default_artifacts_expire_in
)
rescue
ChronicDuration
::
DurationParseError
errors
.
add
(
:default_artifacts_expire_in
,
"is not a correct duration"
)
end
end
app/validators/duration_validator.rb
0 → 100644
View file @
728b0a5f
# DurationValidator
#
# Validate the format conforms with ChronicDuration
#
# Example:
#
# class ApplicationSetting < ActiveRecord::Base
# validates :default_artifacts_expire_in, presence: true, duration: true
# end
#
class
DurationValidator
<
ActiveModel
::
EachValidator
def
validate_each
(
record
,
attribute
,
value
)
ChronicDuration
.
parse
(
value
)
rescue
ChronicDuration
::
DurationParseError
record
.
errors
.
add
(
attribute
,
"is not a correct duration"
)
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