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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
d1a6d7e8
Commit
d1a6d7e8
authored
Aug 04, 2020
by
Uday Aggarwal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added minimum limit to wiki page
parent
877c9eaf
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
8 deletions
+46
-8
app/helpers/application_settings_helper.rb
app/helpers/application_settings_helper.rb
+2
-1
app/models/application_setting.rb
app/models/application_setting.rb
+1
-0
app/models/application_setting_implementation.rb
app/models/application_setting_implementation.rb
+2
-1
app/models/wiki_page.rb
app/models/wiki_page.rb
+13
-5
spec/models/application_setting_spec.rb
spec/models/application_setting_spec.rb
+1
-0
spec/models/wiki_page_spec.rb
spec/models/wiki_page_spec.rb
+27
-1
No files found.
app/helpers/application_settings_helper.rb
View file @
d1a6d7e8
...
...
@@ -328,7 +328,8 @@ module ApplicationSettingsHelper
:group_import_limit
,
:group_export_limit
,
:group_download_export_limit
,
:wiki_page_max_content_bytes
:wiki_page_max_content_bytes
,
:wiki_page_min_content_bytes
]
end
...
...
app/models/application_setting.rb
View file @
d1a6d7e8
...
...
@@ -273,6 +273,7 @@ class ApplicationSetting < ApplicationRecord
validates
:snippet_size_limit
,
numericality:
{
only_integer:
true
,
greater_than:
0
}
validates
:wiki_page_max_content_bytes
,
numericality:
{
only_integer:
true
,
greater_than:
0
}
validates
:wiki_page_min_content_bytes
,
numericality:
{
only_integer:
true
,
greater_than:
0
}
validates
:email_restrictions
,
untrusted_regexp:
true
...
...
app/models/application_setting_implementation.rb
View file @
d1a6d7e8
...
...
@@ -165,7 +165,8 @@ module ApplicationSettingImplementation
user_default_external:
false
,
user_default_internal_regex:
nil
,
user_show_add_ssh_key_message:
true
,
wiki_page_max_content_bytes:
50
.
megabytes
wiki_page_max_content_bytes:
50
.
megabytes
,
wiki_page_min_content_bytes:
1
.
kilobytes
}
end
...
...
app/models/wiki_page.rb
View file @
d1a6d7e8
...
...
@@ -408,11 +408,19 @@ class WikiPage
def
validate_content_size_limit
current_value
=
raw_content
.
to_s
.
bytesize
max_size
=
Gitlab
::
CurrentSettings
.
wiki_page_max_content_bytes
return
if
current_value
<=
max_size
min_size
=
Gitlab
::
CurrentSettings
.
wiki_page_min_content_bytes
return
if
current_value
<=
max_size
&&
current_value
>=
min_size
errors
.
add
(
:content
,
_
(
'is too long (%{current_value}). The maximum size is %{max_size}.'
)
%
{
current_value:
ActiveSupport
::
NumberHelper
.
number_to_human_size
(
current_value
),
max_size:
ActiveSupport
::
NumberHelper
.
number_to_human_size
(
max_size
)
})
if
current_value
>
max_size
errors
.
add
(
:content
,
_
(
'is too long (%{current_value}). The maximum size is %{max_size}.'
)
%
{
current_value:
ActiveSupport
::
NumberHelper
.
number_to_human_size
(
current_value
),
max_size:
ActiveSupport
::
NumberHelper
.
number_to_human_size
(
max_size
)
})
else
errors
.
add
(
:content
,
_
(
'is too short (%{current_value}). The minimum size is %{min_size}.'
)
%
{
current_value:
ActiveSupport
::
NumberHelper
.
number_to_human_size
(
current_value
),
min_size:
ActiveSupport
::
NumberHelper
.
number_to_human_size
(
min_size
)
})
end
end
end
spec/models/application_setting_spec.rb
View file @
d1a6d7e8
...
...
@@ -73,6 +73,7 @@ RSpec.describe ApplicationSetting do
it
{
is_expected
.
to
validate_numericality_of
(
:snippet_size_limit
).
only_integer
.
is_greater_than
(
0
)
}
it
{
is_expected
.
to
validate_numericality_of
(
:wiki_page_max_content_bytes
).
only_integer
.
is_greater_than
(
0
)
}
it
{
is_expected
.
to
validate_numericality_of
(
:wiki_page_min_content_bytes
).
only_integer
.
is_greater_than
(
0
)
}
it
{
is_expected
.
to
validate_presence_of
(
:max_artifacts_size
)
}
it
{
is_expected
.
to
validate_numericality_of
(
:max_artifacts_size
).
only_integer
.
is_greater_than
(
0
)
}
it
{
is_expected
.
to
validate_presence_of
(
:max_pages_size
)
}
...
...
spec/models/wiki_page_spec.rb
View file @
d1a6d7e8
...
...
@@ -275,6 +275,7 @@ RSpec.describe WikiPage do
context
'with a new page'
do
before
do
stub_application_setting
(
wiki_page_max_content_bytes:
10
)
stub_application_setting
(
wiki_page_min_content_bytes:
2
)
end
it
'accepts content below the limit'
do
...
...
@@ -283,6 +284,12 @@ RSpec.describe WikiPage do
expect
(
subject
).
to
be_valid
end
it
'accepts content above the limit'
do
subject
.
attributes
[
:content
]
=
'a'
*
2
expect
(
subject
).
to
be_valid
end
it
'rejects content exceeding the limit'
do
subject
.
attributes
[
:content
]
=
'a'
*
11
...
...
@@ -292,6 +299,15 @@ RSpec.describe WikiPage do
)
end
it
'rejects content below the limit'
do
subject
.
attributes
[
:content
]
=
'a'
expect
(
subject
).
not_to
be_valid
expect
(
subject
.
errors
.
messages
).
to
eq
(
content:
[
'is too short (1 Bytes). The minimum size is 2 Bytes.'
]
)
end
it
'counts content size in bytes rather than characters'
do
subject
.
attributes
[
:content
]
=
'💩💩💩'
...
...
@@ -308,13 +324,14 @@ RSpec.describe WikiPage do
before
do
subject
stub_application_setting
(
wiki_page_max_content_bytes:
11
)
stub_application_setting
(
wiki_page_min_content_bytes:
2
)
end
it
'accepts content when it has not changed'
do
expect
(
subject
).
to
be_valid
end
it
'rejects content when it has changed'
do
it
'rejects content when it has changed
and exceeds the limit
'
do
subject
.
attributes
[
:content
]
=
'a'
*
12
expect
(
subject
).
not_to
be_valid
...
...
@@ -322,6 +339,15 @@ RSpec.describe WikiPage do
content:
[
'is too long (12 Bytes). The maximum size is 11 Bytes.'
]
)
end
it
'rejects content when it has changed and is below the limit'
do
subject
.
attributes
[
:content
]
=
'a'
*
1
expect
(
subject
).
not_to
be_valid
expect
(
subject
.
errors
.
messages
).
to
eq
(
content:
[
'is too short (1 Bytes). The minimum size is 2 Bytes.'
]
)
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