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
e3027502
Commit
e3027502
authored
May 18, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update snippet file count depending on ff
parent
079c18c1
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
36 additions
and
5 deletions
+36
-5
app/models/snippet.rb
app/models/snippet.rb
+6
-1
lib/gitlab/git_access_snippet.rb
lib/gitlab/git_access_snippet.rb
+1
-1
spec/lib/gitlab/checks/push_file_count_check_spec.rb
spec/lib/gitlab/checks/push_file_count_check_spec.rb
+2
-2
spec/lib/gitlab/git_access_snippet_spec.rb
spec/lib/gitlab/git_access_snippet_spec.rb
+10
-0
spec/models/snippet_spec.rb
spec/models/snippet_spec.rb
+16
-0
spec/support/helpers/test_env.rb
spec/support/helpers/test_env.rb
+1
-1
No files found.
app/models/snippet.rb
View file @
e3027502
...
...
@@ -18,7 +18,8 @@ class Snippet < ApplicationRecord
include
AfterCommitQueue
extend
::
Gitlab
::
Utils
::
Override
MAX_FILE_COUNT
=
1
MAX_FILE_COUNT
=
10
MAX_SINGLE_FILE_COUNT
=
1
cache_markdown_field
:title
,
pipeline: :single_line
cache_markdown_field
:description
...
...
@@ -169,6 +170,10 @@ class Snippet < ApplicationRecord
Snippet
.
find_by
(
id:
id
,
project:
project
)
end
def
self
.
max_file_limit
(
user
)
Feature
.
enabled?
(
:snippet_multiple_files
,
user
)
?
MAX_FILE_COUNT
:
MAX_SINGLE_FILE_COUNT
end
def
initialize
(
attributes
=
{})
# We can't use default_value_for because the database has a default
# value of 0 for visibility_level. If someone attempts to create a
...
...
lib/gitlab/git_access_snippet.rb
View file @
e3027502
...
...
@@ -106,7 +106,7 @@ module Gitlab
def
check_single_change_access
(
change
)
Checks
::
SnippetCheck
.
new
(
change
,
logger:
logger
).
validate!
Checks
::
PushFileCountCheck
.
new
(
change
,
repository:
repository
,
limit:
Snippet
::
MAX_FILE_COUNT
,
logger:
logger
).
validate!
Checks
::
PushFileCountCheck
.
new
(
change
,
repository:
repository
,
limit:
Snippet
.
max_file_limit
(
user
)
,
logger:
logger
).
validate!
rescue
Checks
::
TimedLogger
::
TimeoutError
raise
TimeoutError
,
logger
.
full_message
end
...
...
spec/lib/gitlab/checks/push_file_count_check_spec.rb
View file @
e3027502
...
...
@@ -8,7 +8,7 @@ describe Gitlab::Checks::PushFileCountCheck do
let
(
:timeout
)
{
Gitlab
::
GitAccess
::
INTERNAL_TIMEOUT
}
let
(
:logger
)
{
Gitlab
::
Checks
::
TimedLogger
.
new
(
timeout:
timeout
)
}
subject
{
described_class
.
new
(
changes
,
repository:
snippet
.
repository
,
limit:
1
,
logger:
logger
)
}
subject
{
described_class
.
new
(
changes
,
repository:
snippet
.
repository
,
limit:
2
,
logger:
logger
)
}
describe
'#validate!'
do
using
RSpec
::
Parameterized
::
TableSyntax
...
...
@@ -31,7 +31,7 @@ describe Gitlab::Checks::PushFileCountCheck do
where
(
:old
,
:new
,
:valid
,
:message
)
do
'single-file'
|
'edit-file'
|
true
|
nil
'single-file'
|
'multiple-files'
|
false
|
'The repository can contain at most
1
file(s).'
'single-file'
|
'multiple-files'
|
false
|
'The repository can contain at most
2
file(s).'
'single-file'
|
'no-files'
|
false
|
'The repository must contain at least 1 file.'
'edit-file'
|
'rename-and-edit-file'
|
true
|
nil
end
...
...
spec/lib/gitlab/git_access_snippet_spec.rb
View file @
e3027502
...
...
@@ -278,6 +278,16 @@ describe Gitlab::GitAccessSnippet do
expect
{
push_access_check
}.
to
raise_forbidden
(
'foo'
)
end
it
'sets the file count limit from Snippet class'
do
service
=
double
expect
(
service
).
to
receive
(
:validate!
).
and_return
(
nil
)
expect
(
Snippet
).
to
receive
(
:max_file_limit
).
with
(
user
).
and_return
(
5
)
expect
(
Gitlab
::
Checks
::
PushFileCountCheck
).
to
receive
(
:new
).
with
(
anything
,
hash_including
(
limit:
5
)).
and_return
(
service
)
push_access_check
end
end
it_behaves_like
'snippet checks'
...
...
spec/models/snippet_spec.rb
View file @
e3027502
...
...
@@ -734,4 +734,20 @@ describe Snippet do
it
{
is_expected
.
to
eq
(
Gitlab
.
config
.
gitlab_shell
.
ssh_path_prefix
+
"
#{
snippet
.
project
.
full_path
}
/snippets/
#{
snippet
.
id
}
.git"
)
}
end
end
describe
'.max_file_limit'
do
subject
{
described_class
.
max_file_limit
(
nil
)
}
it
"returns
#{
Snippet
::
MAX_FILE_COUNT
}
"
do
expect
(
subject
).
to
eq
Snippet
::
MAX_FILE_COUNT
end
context
'when feature flag :snippet_multiple_files is disabled'
do
it
"returns
#{
described_class
::
MAX_SINGLE_FILE_COUNT
}
"
do
stub_feature_flags
(
snippet_multiple_files:
false
)
expect
(
subject
).
to
eq
described_class
::
MAX_SINGLE_FILE_COUNT
end
end
end
end
spec/support/helpers/test_env.rb
View file @
e3027502
...
...
@@ -59,7 +59,7 @@ module TestEnv
'merge-commit-analyze-side-branch'
=>
'8a99451'
,
'merge-commit-analyze-after'
=>
'646ece5'
,
'snippet/single-file'
=>
'43e4080aaa14fc7d4b77ee1f5c9d067d5a7df10e'
,
'snippet/multiple-files'
=>
'
b80faa8c5b2b62f6489a0d84755580e927e1189b
'
,
'snippet/multiple-files'
=>
'
40232f7eb98b3f221886432def6e8bab2432add9
'
,
'snippet/rename-and-edit-file'
=>
'220a1e4b4dff37feea0625a7947a4c60fbe78365'
,
'snippet/edit-file'
=>
'c2f074f4f26929c92795a75775af79a6ed6d8430'
,
'snippet/no-files'
=>
'671aaa842a4875e5f30082d1ab6feda345fdb94d'
,
...
...
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