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
9410f215
Unverified
Commit
9410f215
authored
Dec 26, 2016
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add nested groups support to the Groups::CreateService
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
7b4b3d5f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
4 deletions
+40
-4
create_service.rb
app/services/groups/create_service.rb
+13
-0
create_service_spec.rb
spec/services/groups/create_service_spec.rb
+27
-4
No files found.
app/services/groups/create_service.rb
View file @
9410f215
...
...
@@ -12,6 +12,19 @@ module Groups
return
@group
end
parent_id
=
params
[
:parent_id
]
if
parent_id
parent
=
Group
.
find
(
parent_id
)
unless
can?
(
current_user
,
:admin_group
,
parent
)
@group
.
parent_id
=
nil
@group
.
errors
.
add
(
:parent_id
,
'manage access required to create subgroup'
)
return
@group
end
end
@group
.
name
||=
@group
.
path
.
dup
@group
.
save
@group
.
add_owner
(
current_user
)
...
...
spec/services/groups/create_service_spec.rb
View file @
9410f215
require
'spec_helper'
describe
Groups
::
CreateService
,
services:
true
do
let!
(
:user
)
{
create
(
:user
)
}
describe
Groups
::
CreateService
,
'#execute'
,
services:
true
do
let!
(
:user
)
{
create
(
:user
)
}
let!
(
:group_params
)
{
{
path:
"group_path"
,
visibility_level:
Gitlab
::
VisibilityLevel
::
PUBLIC
}
}
describe
"execute"
do
let!
(
:service
)
{
described_class
.
new
(
user
,
group_params
)
}
describe
'visibility level restrictions'
do
let!
(
:service
)
{
described_class
.
new
(
user
,
group_params
)
}
subject
{
service
.
execute
}
context
"create groups without restricted visibility level"
do
...
...
@@ -14,7 +15,29 @@ describe Groups::CreateService, services: true do
context
"cannot create group with restricted visibility level"
do
before
{
allow_any_instance_of
(
ApplicationSetting
).
to
receive
(
:restricted_visibility_levels
).
and_return
([
Gitlab
::
VisibilityLevel
::
PUBLIC
])
}
it
{
is_expected
.
not_to
be_persisted
}
end
end
describe
'creating subgroup'
do
let!
(
:group
)
{
create
(
:group
)
}
let!
(
:service
)
{
described_class
.
new
(
user
,
group_params
.
merge
(
parent_id:
group
.
id
))
}
subject
{
service
.
execute
}
context
'as group owner'
do
before
{
group
.
add_owner
(
user
)
}
it
{
is_expected
.
to
be_persisted
}
end
context
'as guest'
do
it
'does not save group and returns an error'
do
is_expected
.
not_to
be_persisted
expect
(
subject
.
errors
[
:parent_id
].
first
).
to
eq
(
'manage access required to create subgroup'
)
expect
(
subject
.
parent_id
).
to
be_nil
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