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
1fa095f9
Commit
1fa095f9
authored
Oct 08, 2020
by
Kerri Miller
Committed by
Igor Drozdov
Oct 08, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add :default_branch_name as permitted attribute
parent
c9a519bb
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
112 additions
and
5 deletions
+112
-5
app/controllers/groups_controller.rb
app/controllers/groups_controller.rb
+2
-1
app/models/namespace_setting.rb
app/models/namespace_setting.rb
+12
-0
app/services/groups/update_service.rb
app/services/groups/update_service.rb
+14
-0
ee/app/services/ee/namespace_settings/update_service.rb
ee/app/services/ee/namespace_settings/update_service.rb
+2
-4
spec/controllers/groups_controller_spec.rb
spec/controllers/groups_controller_spec.rb
+31
-0
spec/models/namespace_setting_spec.rb
spec/models/namespace_setting_spec.rb
+40
-0
spec/services/namespace_settings/update_service_spec.rb
spec/services/namespace_settings/update_service_spec.rb
+11
-0
No files found.
app/controllers/groups_controller.rb
View file @
1fa095f9
...
@@ -241,7 +241,8 @@ class GroupsController < Groups::ApplicationController
...
@@ -241,7 +241,8 @@ class GroupsController < Groups::ApplicationController
:two_factor_grace_period
,
:two_factor_grace_period
,
:project_creation_level
,
:project_creation_level
,
:subgroup_creation_level
,
:subgroup_creation_level
,
:default_branch_protection
:default_branch_protection
,
:default_branch_name
]
]
end
end
...
...
app/models/namespace_setting.rb
View file @
1fa095f9
...
@@ -3,7 +3,19 @@
...
@@ -3,7 +3,19 @@
class
NamespaceSetting
<
ApplicationRecord
class
NamespaceSetting
<
ApplicationRecord
belongs_to
:namespace
,
inverse_of: :namespace_settings
belongs_to
:namespace
,
inverse_of: :namespace_settings
validate
:default_branch_name_content
NAMESPACE_SETTINGS_PARAMS
=
[
:default_branch_name
].
freeze
self
.
primary_key
=
:namespace_id
self
.
primary_key
=
:namespace_id
def
default_branch_name_content
return
if
default_branch_name
.
nil?
if
default_branch_name
.
blank?
errors
.
add
(
:default_branch_name
,
"can not be an empty string"
)
end
end
end
end
NamespaceSetting
.
prepend_if_ee
(
'EE::NamespaceSetting'
)
NamespaceSetting
.
prepend_if_ee
(
'EE::NamespaceSetting'
)
app/services/groups/update_service.rb
View file @
1fa095f9
...
@@ -23,6 +23,8 @@ module Groups
...
@@ -23,6 +23,8 @@ module Groups
before_assignment_hook
(
group
,
params
)
before_assignment_hook
(
group
,
params
)
handle_namespace_settings
group
.
assign_attributes
(
params
)
group
.
assign_attributes
(
params
)
begin
begin
...
@@ -40,6 +42,18 @@ module Groups
...
@@ -40,6 +42,18 @@ module Groups
private
private
def
handle_namespace_settings
settings_params
=
params
.
slice
(
*::
NamespaceSetting
::
NAMESPACE_SETTINGS_PARAMS
)
return
if
settings_params
.
empty?
::
NamespaceSetting
::
NAMESPACE_SETTINGS_PARAMS
.
each
do
|
nsp
|
params
.
delete
(
nsp
)
end
::
NamespaceSettings
::
UpdateService
.
new
(
current_user
,
group
,
settings_params
).
execute
end
def
valid_path_change_with_npm_packages?
def
valid_path_change_with_npm_packages?
return
true
unless
group
.
packages_feature_enabled?
return
true
unless
group
.
packages_feature_enabled?
return
true
if
params
[
:path
].
blank?
return
true
if
params
[
:path
].
blank?
...
...
ee/app/services/ee/namespace_settings/update_service.rb
View file @
1fa095f9
...
@@ -9,16 +9,14 @@ module EE
...
@@ -9,16 +9,14 @@ module EE
override
:execute
override
:execute
def
execute
def
execute
super
unless
can_update_prevent_forking?
unless
can_update_prevent_forking?
group
.
errors
.
add
(
group
.
errors
.
add
(
:prevent_forking_outside_group
,
:prevent_forking_outside_group
,
s_
(
'GroupSettings|Prevent forking setting was not saved'
)
s_
(
'GroupSettings|Prevent forking setting was not saved'
)
)
)
return
end
end
super
end
end
private
private
...
...
spec/controllers/groups_controller_spec.rb
View file @
1fa095f9
...
@@ -551,6 +551,37 @@ RSpec.describe GroupsController, factory_default: :keep do
...
@@ -551,6 +551,37 @@ RSpec.describe GroupsController, factory_default: :keep do
end
end
end
end
context
"updating default_branch_name"
do
let
(
:example_branch_name
)
{
"example_branch_name"
}
subject
(
:update_action
)
do
put
:update
,
params:
{
id:
group
.
to_param
,
group:
{
default_branch_name:
example_branch_name
}
}
end
it
"updates the attribute"
do
expect
{
subject
}
.
to
change
{
group
.
namespace_settings
.
reload
.
default_branch_name
}
.
from
(
nil
)
.
to
(
example_branch_name
)
expect
(
response
).
to
have_gitlab_http_status
(
:found
)
end
context
"to empty string"
do
let
(
:example_branch_name
)
{
''
}
it
"does not update the attribute"
do
subject
expect
(
group
.
namespace_settings
.
reload
.
default_branch_name
).
not_to
eq
(
''
)
end
end
end
context
'when there is a conflicting group path'
do
context
'when there is a conflicting group path'
do
let!
(
:conflict_group
)
{
create
(
:group
,
path:
SecureRandom
.
hex
(
12
)
)
}
let!
(
:conflict_group
)
{
create
(
:group
,
path:
SecureRandom
.
hex
(
12
)
)
}
let!
(
:old_name
)
{
group
.
name
}
let!
(
:old_name
)
{
group
.
name
}
...
...
spec/models/namespace_setting_spec.rb
View file @
1fa095f9
...
@@ -3,5 +3,45 @@
...
@@ -3,5 +3,45 @@
require
'spec_helper'
require
'spec_helper'
RSpec
.
describe
NamespaceSetting
,
type: :model
do
RSpec
.
describe
NamespaceSetting
,
type: :model
do
# Relationships
#
it
{
is_expected
.
to
belong_to
(
:namespace
)
}
it
{
is_expected
.
to
belong_to
(
:namespace
)
}
describe
"validations"
do
describe
"#default_branch_name_content"
do
let_it_be
(
:group
)
{
create
(
:group
)
}
let
(
:namespace_settings
)
{
group
.
namespace_settings
}
shared_examples
"doesn't return an error"
do
it
"doesn't return an error"
do
expect
(
namespace_settings
.
valid?
).
to
be_truthy
expect
(
namespace_settings
.
errors
.
full_messages
).
to
be_empty
end
end
context
"when not set"
do
it_behaves_like
"doesn't return an error"
end
context
"when set"
do
before
do
namespace_settings
.
default_branch_name
=
"example_branch_name"
end
it_behaves_like
"doesn't return an error"
end
context
"when an empty string"
do
before
do
namespace_settings
.
default_branch_name
=
''
end
it
"returns an error"
do
expect
(
namespace_settings
.
valid?
).
to
be_falsey
expect
(
namespace_settings
.
errors
.
full_messages
).
not_to
be_empty
end
end
end
end
end
end
spec/services/namespace_settings/update_service_spec.rb
View file @
1fa095f9
...
@@ -33,5 +33,16 @@ RSpec.describe NamespaceSettings::UpdateService do
...
@@ -33,5 +33,16 @@ RSpec.describe NamespaceSettings::UpdateService do
end
.
not_to
change
{
NamespaceSetting
.
count
}
end
.
not_to
change
{
NamespaceSetting
.
count
}
end
end
end
end
context
"updating :default_branch_name"
do
let
(
:example_branch_name
)
{
"example_branch_name"
}
let
(
:settings
)
{
{
default_branch_name:
example_branch_name
}
}
it
"changes settings"
do
expect
{
service
.
execute
}
.
to
change
{
group
.
namespace_settings
.
default_branch_name
}
.
from
(
nil
).
to
(
example_branch_name
)
end
end
end
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