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
e490f69b
Commit
e490f69b
authored
Oct 01, 2020
by
Kerri Miller
Committed by
Gabriel Mazetto
Oct 01, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create basic non-EE NamespaceSettings::UpdateService
parent
27278244
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
80 additions
and
27 deletions
+80
-27
app/services/namespace_settings/update_service.rb
app/services/namespace_settings/update_service.rb
+25
-0
ee/app/services/ee/groups/update_service.rb
ee/app/services/ee/groups/update_service.rb
+1
-1
ee/app/services/ee/namespace_settings/update_service.rb
ee/app/services/ee/namespace_settings/update_service.rb
+18
-25
ee/spec/services/ee/namespace_settings/update_service_spec.rb
...pec/services/ee/namespace_settings/update_service_spec.rb
+1
-1
spec/services/namespace_settings/update_service_spec.rb
spec/services/namespace_settings/update_service_spec.rb
+35
-0
No files found.
app/services/namespace_settings/update_service.rb
0 → 100644
View file @
e490f69b
# frozen_string_literal: true
module
NamespaceSettings
class
UpdateService
include
::
Gitlab
::
Allowable
attr_reader
:current_user
,
:group
,
:settings_params
def
initialize
(
current_user
,
group
,
settings
)
@current_user
=
current_user
@group
=
group
@settings_params
=
settings
end
def
execute
if
group
.
namespace_settings
group
.
namespace_settings
.
attributes
=
settings_params
else
group
.
build_namespace_settings
(
settings_params
)
end
end
end
end
NamespaceSettings
::
UpdateService
.
prepend_if_ee
(
'EE::NamespaceSettings::UpdateService'
)
ee/app/services/ee/groups/update_service.rb
View file @
e490f69b
...
...
@@ -116,7 +116,7 @@ module EE
settings_params
=
params
.
slice
(
:prevent_forking_outside_group
)
params
.
delete
(
:prevent_forking_outside_group
)
NamespaceSettings
::
UpdateService
.
new
(
current_user
,
group
,
settings_params
).
execute
::
NamespaceSettings
::
UpdateService
.
new
(
current_user
,
group
,
settings_params
).
execute
end
def
log_audit_event
...
...
ee/app/services/ee/namespace_settings/update_service.rb
View file @
e490f69b
...
...
@@ -2,44 +2,37 @@
module
EE
# This class is responsible for updating the namespace settings of a specific group.
#
module
NamespaceSettings
class
UpdateService
include
::
Gitlab
::
Allowable
def
initialize
(
current_user
,
group
,
settings
)
@current_user
=
current_user
@group
=
group
@settings_params
=
settings
end
module
UpdateService
extend
::
Gitlab
::
Utils
::
Override
override
:execute
def
execute
unless
valid?
group
.
errors
.
add
(
:prevent_forking_outside_group
,
s_
(
'GroupSettings|Prevent forking setting was not saved'
))
unless
can_update_prevent_forking?
group
.
errors
.
add
(
:prevent_forking_outside_group
,
s_
(
'GroupSettings|Prevent forking setting was not saved'
)
)
return
end
if
group
.
namespace_settings
group
.
namespace_settings
.
attributes
=
settings_params
else
group
.
build_namespace_settings
(
settings_params
)
end
super
end
private
attr_reader
:current_user
,
:group
,
:settings_params
def
can_update_prevent_forking?
return
true
unless
settings_params
.
key?
(
:prevent_forking_outside_group
)
def
valid?
if
settings_params
.
key?
(
:prevent_forking_outside_group
)
can_update_prevent_forking?
else
if
can?
(
current_user
,
:change_prevent_group_forking
,
group
)
true
e
nd
end
e
lse
settings_params
.
delete
(
:prevent_forking_outside_group
)
def
can_update_prevent_forking?
can?
(
current_user
,
:change_prevent_group_forking
,
group
)
false
end
end
end
end
...
...
ee/spec/services/ee/namespace_settings/update_service_spec.rb
View file @
e490f69b
...
...
@@ -6,7 +6,7 @@ RSpec.describe EE::NamespaceSettings::UpdateService do
let
(
:group
)
{
create
(
:group
)
}
let
(
:user
)
{
create
(
:user
)
}
subject
{
described_class
.
new
(
user
,
group
,
params
).
execute
}
subject
{
NamespaceSettings
::
UpdateService
.
new
(
user
,
group
,
params
).
execute
}
describe
'#execute'
do
before
do
...
...
spec/services/namespace_settings/update_service_spec.rb
0 → 100644
View file @
e490f69b
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
NamespaceSettings
::
UpdateService
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:group
)
{
create
(
:group
)
}
let
(
:settings
)
{
{}
}
subject
(
:service
)
{
described_class
.
new
(
user
,
group
,
settings
)
}
describe
"#execute"
do
context
"group has no namespace_settings"
do
it
"builds out a new namespace_settings record"
do
expect
do
service
.
execute
end
.
to
change
{
NamespaceSetting
.
count
}.
by
(
1
)
end
end
context
"group has a namespace_settings"
do
before
do
create
(
:namespace_settings
,
namespace:
group
)
service
.
execute
end
it
"doesn't create a new namespace_setting record"
do
expect
do
service
.
execute
end
.
not_to
change
{
NamespaceSetting
.
count
}
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