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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
b82fdf62
Commit
b82fdf62
authored
Dec 20, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix error 500 renaming group. Also added specs and changelog.
parent
ad1a1d97
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
83 additions
and
11 deletions
+83
-11
app/controllers/groups_controller.rb
app/controllers/groups_controller.rb
+4
-1
app/models/namespace.rb
app/models/namespace.rb
+2
-2
app/services/groups/update_service.rb
app/services/groups/update_service.rb
+7
-1
changelogs/unreleased/fix-group-path-rename-error.yml
changelogs/unreleased/fix-group-path-rename-error.yml
+4
-0
lib/gitlab/update_path_error.rb
lib/gitlab/update_path_error.rb
+3
-0
spec/controllers/groups_controller_spec.rb
spec/controllers/groups_controller_spec.rb
+21
-0
spec/services/groups/update_service_spec.rb
spec/services/groups/update_service_spec.rb
+42
-7
No files found.
app/controllers/groups_controller.rb
View file @
b82fdf62
...
@@ -82,7 +82,10 @@ class GroupsController < Groups::ApplicationController
...
@@ -82,7 +82,10 @@ class GroupsController < Groups::ApplicationController
if
Groups
::
UpdateService
.
new
(
@group
,
current_user
,
group_params
).
execute
if
Groups
::
UpdateService
.
new
(
@group
,
current_user
,
group_params
).
execute
redirect_to
edit_group_path
(
@group
),
notice:
"Group '
#{
@group
.
name
}
' was successfully updated."
redirect_to
edit_group_path
(
@group
),
notice:
"Group '
#{
@group
.
name
}
' was successfully updated."
else
else
render
action:
"edit"
error
=
group
.
errors
.
full_messages
.
first
alert_message
=
"Group '
#{
@group
.
name
}
' cannot be updated: "
+
error
redirect_to
edit_group_path
(
@group
.
reload
),
alert:
alert_message
end
end
end
end
...
...
app/models/namespace.rb
View file @
b82fdf62
...
@@ -98,7 +98,7 @@ class Namespace < ActiveRecord::Base
...
@@ -98,7 +98,7 @@ class Namespace < ActiveRecord::Base
def
move_dir
def
move_dir
if
any_project_has_container_registry_tags?
if
any_project_has_container_registry_tags?
raise
Exception
.
new
(
'Namespace cannot be moved, because at least one project has tags in container registry'
)
raise
Gitlab
::
UpdatePathError
.
new
(
'Namespace cannot be moved, because at least one project has tags in container registry'
)
end
end
# Move the namespace directory in all storages paths used by member projects
# Move the namespace directory in all storages paths used by member projects
...
@@ -111,7 +111,7 @@ class Namespace < ActiveRecord::Base
...
@@ -111,7 +111,7 @@ class Namespace < ActiveRecord::Base
# if we cannot move namespace directory we should rollback
# if we cannot move namespace directory we should rollback
# db changes in order to prevent out of sync between db and fs
# db changes in order to prevent out of sync between db and fs
raise
Exception
.
new
(
'namespace directory cannot be moved'
)
raise
Gitlab
::
UpdatePathError
.
new
(
'namespace directory cannot be moved'
)
end
end
end
end
...
...
app/services/groups/update_service.rb
View file @
b82fdf62
...
@@ -14,7 +14,13 @@ module Groups
...
@@ -14,7 +14,13 @@ module Groups
group
.
assign_attributes
(
params
)
group
.
assign_attributes
(
params
)
group
.
save
begin
group
.
save
rescue
Gitlab
::
UpdatePathError
=>
e
group
.
errors
.
add
(
:base
,
e
.
message
)
false
end
end
end
end
end
end
end
changelogs/unreleased/fix-group-path-rename-error.yml
0 → 100644
View file @
b82fdf62
---
title
:
Fix 500 error renaming group
merge_request
:
author
:
lib/gitlab/update_path_error.rb
0 → 100644
View file @
b82fdf62
module
Gitlab
class
UpdatePathError
<
StandardError
;
end
end
spec/controllers/groups_controller_spec.rb
View file @
b82fdf62
...
@@ -105,4 +105,25 @@ describe GroupsController do
...
@@ -105,4 +105,25 @@ describe GroupsController do
end
end
end
end
end
end
describe
'PUT update'
do
before
do
sign_in
(
user
)
end
it
'updates the path succesfully'
do
post
:update
,
id:
group
.
to_param
,
group:
{
path:
'new_path'
}
expect
(
response
).
to
have_http_status
(
302
)
expect
(
controller
).
to
set_flash
[
:notice
]
end
it
'does not update the path on error'
do
allow_any_instance_of
(
Group
).
to
receive
(
:move_dir
).
and_raise
(
Gitlab
::
UpdatePathError
)
post
:update
,
id:
group
.
to_param
,
group:
{
path:
'new_path'
}
expect
(
response
).
to
have_http_status
(
302
)
expect
(
controller
).
to
set_flash
[
:alert
]
end
end
end
end
spec/services/groups/update_service_spec.rb
View file @
b82fdf62
require
'spec_helper'
require
'spec_helper'
describe
Groups
::
UpdateService
,
services:
true
do
describe
Groups
::
UpdateService
,
services:
true
do
let!
(
:user
)
{
create
(
:user
)
}
let!
(
:user
)
{
create
(
:user
)
}
let!
(
:private_group
)
{
create
(
:group
,
:private
)
}
let!
(
:private_group
)
{
create
(
:group
,
:private
)
}
let!
(
:internal_group
)
{
create
(
:group
,
:internal
)
}
let!
(
:internal_group
)
{
create
(
:group
,
:internal
)
}
let!
(
:public_group
)
{
create
(
:group
,
:public
)
}
let!
(
:public_group
)
{
create
(
:group
,
:public
)
}
describe
"#execute"
do
describe
"#execute"
do
context
"project visibility_level validation"
do
context
"project visibility_level validation"
do
context
"public group with public projects"
do
context
"public group with public projects"
do
let!
(
:service
)
{
described_class
.
new
(
public_group
,
user
,
visibility_level:
Gitlab
::
VisibilityLevel
::
INTERNAL
)
}
let!
(
:service
)
{
described_class
.
new
(
public_group
,
user
,
visibility_level:
Gitlab
::
VisibilityLevel
::
INTERNAL
)
}
before
do
before
do
public_group
.
add_user
(
user
,
Gitlab
::
Access
::
MASTER
)
public_group
.
add_user
(
user
,
Gitlab
::
Access
::
MASTER
)
...
@@ -23,7 +23,7 @@ describe Groups::UpdateService, services: true do
...
@@ -23,7 +23,7 @@ describe Groups::UpdateService, services: true do
end
end
context
"internal group with internal project"
do
context
"internal group with internal project"
do
let!
(
:service
)
{
described_class
.
new
(
internal_group
,
user
,
visibility_level:
Gitlab
::
VisibilityLevel
::
PRIVATE
)
}
let!
(
:service
)
{
described_class
.
new
(
internal_group
,
user
,
visibility_level:
Gitlab
::
VisibilityLevel
::
PRIVATE
)
}
before
do
before
do
internal_group
.
add_user
(
user
,
Gitlab
::
Access
::
MASTER
)
internal_group
.
add_user
(
user
,
Gitlab
::
Access
::
MASTER
)
...
@@ -39,7 +39,7 @@ describe Groups::UpdateService, services: true do
...
@@ -39,7 +39,7 @@ describe Groups::UpdateService, services: true do
end
end
context
"unauthorized visibility_level validation"
do
context
"unauthorized visibility_level validation"
do
let!
(
:service
)
{
described_class
.
new
(
internal_group
,
user
,
visibility_level:
99
)
}
let!
(
:service
)
{
described_class
.
new
(
internal_group
,
user
,
visibility_level:
99
)
}
before
do
before
do
internal_group
.
add_user
(
user
,
Gitlab
::
Access
::
MASTER
)
internal_group
.
add_user
(
user
,
Gitlab
::
Access
::
MASTER
)
end
end
...
@@ -49,4 +49,39 @@ describe Groups::UpdateService, services: true do
...
@@ -49,4 +49,39 @@ describe Groups::UpdateService, services: true do
expect
(
internal_group
.
errors
.
count
).
to
eq
(
1
)
expect
(
internal_group
.
errors
.
count
).
to
eq
(
1
)
end
end
end
end
context
'rename group'
do
let!
(
:service
)
{
described_class
.
new
(
internal_group
,
user
,
path:
'new_path'
)
}
before
do
internal_group
.
add_user
(
user
,
Gitlab
::
Access
::
MASTER
)
create
(
:project
,
:internal
,
group:
internal_group
)
end
it
'returns true'
do
puts
internal_group
.
errors
.
full_messages
expect
(
service
.
execute
).
to
eq
(
true
)
end
context
'error moving group'
do
before
do
allow
(
internal_group
).
to
receive
(
:move_dir
).
and_raise
(
Gitlab
::
UpdatePathError
)
end
it
'does not raise an error'
do
expect
{
service
.
execute
}.
not_to
raise_error
end
it
'returns false'
do
expect
(
service
.
execute
).
to
eq
(
false
)
end
it
'has the right error'
do
service
.
execute
expect
(
internal_group
.
errors
.
full_messages
.
first
).
to
eq
(
'Gitlab::UpdatePathError'
)
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