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
36361367
Commit
36361367
authored
Jan 16, 2017
by
Robert Speicher
Committed by
James Lopez
Jan 19, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge branch 'sandish/gitlab-ce-update_ret_val' into 'master'
Ensure updating project settings shows a flash message on success See merge request !8579
parent
f8b0b197
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
84 additions
and
113 deletions
+84
-113
projects_controller.rb
app/controllers/projects_controller.rb
+4
-7
update_service.rb
app/services/projects/update_service.rb
+5
-1
sandish-gitlab-ce-update_ret_val.yml
changelogs/unreleased/sandish-gitlab-ce-update_ret_val.yml
+4
-0
projects.rb
lib/api/projects.rb
+4
-4
projects_controller_spec.rb
spec/controllers/projects_controller_spec.rb
+1
-1
project_settings_spec.rb
spec/features/projects/project_settings_spec.rb
+10
-0
update_service_spec.rb
spec/services/projects/update_service_spec.rb
+56
-100
No files found.
app/controllers/projects_controller.rb
View file @
36361367
...
@@ -42,19 +42,16 @@ class ProjectsController < Projects::ApplicationController
...
@@ -42,19 +42,16 @@ class ProjectsController < Projects::ApplicationController
end
end
def
update
def
update
status
=
::
Projects
::
UpdateService
.
new
(
@project
,
current_user
,
project_params
).
execute
result
=
::
Projects
::
UpdateService
.
new
(
@project
,
current_user
,
project_params
).
execute
# Refresh the repo in case anything changed
# Refresh the repo in case anything changed
@repository
=
project
.
repository
@repository
=
@
project
.
repository
respond_to
do
|
format
|
respond_to
do
|
format
|
if
statu
s
if
result
[
:status
]
==
:succes
s
flash
[
:notice
]
=
"Project '
#{
@project
.
name
}
' was successfully updated."
flash
[
:notice
]
=
"Project '
#{
@project
.
name
}
' was successfully updated."
format
.
html
do
format
.
html
do
redirect_to
(
redirect_to
(
edit_project_path
(
@project
))
edit_project_path
(
@project
),
notice:
"Project '
#{
@project
.
name
}
' was successfully updated."
)
end
end
else
else
format
.
html
{
render
'edit'
}
format
.
html
{
render
'edit'
}
...
...
app/services/projects/update_service.rb
View file @
36361367
...
@@ -9,7 +9,7 @@ module Projects
...
@@ -9,7 +9,7 @@ module Projects
Gitlab
::
VisibilityLevel
.
allowed_for?
(
current_user
,
new_visibility
)
Gitlab
::
VisibilityLevel
.
allowed_for?
(
current_user
,
new_visibility
)
deny_visibility_level
(
project
,
new_visibility
)
deny_visibility_level
(
project
,
new_visibility
)
return
project
return
error
(
'Visibility level unallowed'
)
end
end
end
end
...
@@ -23,6 +23,10 @@ module Projects
...
@@ -23,6 +23,10 @@ module Projects
if
project
.
previous_changes
.
include?
(
'path'
)
if
project
.
previous_changes
.
include?
(
'path'
)
project
.
rename_repo
project
.
rename_repo
end
end
success
else
error
(
'Project could not be updated'
)
end
end
end
end
end
end
...
...
changelogs/unreleased/sandish-gitlab-ce-update_ret_val.yml
0 → 100644
View file @
36361367
---
title
:
Ensure updating project settings shows a flash message on success
merge_request
:
8579
author
:
Sandish Chen
lib/api/projects.rb
View file @
36361367
...
@@ -295,13 +295,13 @@ module API
...
@@ -295,13 +295,13 @@ module API
authorize!
:rename_project
,
user_project
if
attrs
[
:name
].
present?
authorize!
:rename_project
,
user_project
if
attrs
[
:name
].
present?
authorize!
:change_visibility_level
,
user_project
if
attrs
[
:visibility_level
].
present?
authorize!
:change_visibility_level
,
user_project
if
attrs
[
:visibility_level
].
present?
::
Projects
::
UpdateService
.
new
(
user_project
,
current_user
,
attrs
).
execute
result
=
::
Projects
::
UpdateService
.
new
(
user_project
,
current_user
,
attrs
).
execute
if
user_project
.
errors
.
any?
if
result
[
:status
]
==
:success
render_validation_error!
(
user_project
)
else
present
user_project
,
with:
Entities
::
Project
,
present
user_project
,
with:
Entities
::
Project
,
user_can_admin_project:
can?
(
current_user
,
:admin_project
,
user_project
)
user_can_admin_project:
can?
(
current_user
,
:admin_project
,
user_project
)
else
render_validation_error!
(
user_project
)
end
end
end
end
...
...
spec/controllers/projects_controller_spec.rb
View file @
36361367
...
@@ -245,7 +245,7 @@ describe ProjectsController do
...
@@ -245,7 +245,7 @@ describe ProjectsController do
expect
(
project
.
repository
.
path
).
to
include
(
new_path
)
expect
(
project
.
repository
.
path
).
to
include
(
new_path
)
expect
(
assigns
(
:repository
).
path
).
to
eq
(
project
.
repository
.
path
)
expect
(
assigns
(
:repository
).
path
).
to
eq
(
project
.
repository
.
path
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
have_http_status
(
302
)
end
end
end
end
...
...
spec/features/projects/project_settings_spec.rb
View file @
36361367
...
@@ -21,6 +21,16 @@ describe 'Edit Project Settings', feature: true do
...
@@ -21,6 +21,16 @@ describe 'Edit Project Settings', feature: true do
expect
(
page
).
to
have_content
"Name can contain only letters, digits, emojis, '_', '.', dash, space. It must start with letter, digit, emoji or '_'."
expect
(
page
).
to
have_content
"Name can contain only letters, digits, emojis, '_', '.', dash, space. It must start with letter, digit, emoji or '_'."
expect
(
page
).
to
have_button
'Save changes'
expect
(
page
).
to
have_button
'Save changes'
end
end
scenario
'shows a successful notice when the project is updated'
do
visit
edit_namespace_project_path
(
project
.
namespace
,
project
)
fill_in
'project_name_edit'
,
with:
'hello world'
click_button
'Save changes'
expect
(
page
).
to
have_content
"Project 'hello world' was successfully updated."
end
end
end
describe
'Rename repository'
do
describe
'Rename repository'
do
...
...
spec/services/projects/update_service_spec.rb
View file @
36361367
require
'spec_helper'
require
'spec_helper'
describe
Projects
::
UpdateService
,
services:
true
do
describe
Projects
::
UpdateService
,
services:
true
do
describe
:update_by_user
do
let
(
:user
)
{
create
(
:user
)
}
before
do
let
(
:admin
)
{
create
(
:admin
)
}
@user
=
create
:user
let
(
:project
)
{
create
(
:project
,
creator_id:
user
.
id
,
namespace:
user
.
namespace
)
}
@admin
=
create
:user
,
admin:
true
@project
=
create
:project
,
creator_id:
@user
.
id
,
namespace:
@user
.
namespace
@opts
=
{}
end
context
'is private when updated to private'
do
describe
'update_by_user'
do
before
do
context
'when visibility_level is INTERNAL'
do
@created_private
=
@project
.
private?
it
'updates the project to internal'
do
result
=
update_project
(
project
,
user
,
visibility_level:
Gitlab
::
VisibilityLevel
::
INTERNAL
)
@opts
.
merge!
(
visibility_level:
Gitlab
::
VisibilityLevel
::
PRIVATE
)
expect
(
result
).
to
eq
({
status: :success
}
)
update_project
(
@project
,
@user
,
@opts
)
expect
(
project
).
to
be_internal
end
end
it
{
expect
(
@created_private
).
to
be_truthy
}
it
{
expect
(
@project
.
private?
).
to
be_truthy
}
end
end
context
'is internal when updated to internal'
do
context
'when visibility_level is PUBLIC'
do
before
do
it
'updates the project to public'
do
@created_private
=
@project
.
private?
result
=
update_project
(
project
,
user
,
visibility_level:
Gitlab
::
VisibilityLevel
::
PUBLIC
)
expect
(
result
).
to
eq
({
status: :success
})
@opts
.
merge!
(
visibility_level:
Gitlab
::
VisibilityLevel
::
INTERNAL
)
expect
(
project
).
to
be_public
update_project
(
@project
,
@user
,
@opts
)
end
end
it
{
expect
(
@created_private
).
to
be_truthy
}
it
{
expect
(
@project
.
internal?
).
to
be_truthy
}
end
end
context
'
is public when updated to public
'
do
context
'
when visibility levels are restricted to PUBLIC only
'
do
before
do
before
do
@created_private
=
@project
.
private?
@opts
.
merge!
(
visibility_level:
Gitlab
::
VisibilityLevel
::
PUBLIC
)
update_project
(
@project
,
@user
,
@opts
)
end
it
{
expect
(
@created_private
).
to
be_truthy
}
it
{
expect
(
@project
.
public?
).
to
be_truthy
}
end
context
'respect configured visibility restrictions setting'
do
before
(
:each
)
do
stub_application_setting
(
restricted_visibility_levels:
[
Gitlab
::
VisibilityLevel
::
PUBLIC
])
stub_application_setting
(
restricted_visibility_levels:
[
Gitlab
::
VisibilityLevel
::
PUBLIC
])
end
end
context
'is private when updated to private'
do
context
'when visibility_level is INTERNAL'
do
before
do
it
'updates the project to internal'
do
@created_private
=
@project
.
private?
result
=
update_project
(
project
,
user
,
visibility_level:
Gitlab
::
VisibilityLevel
::
INTERNAL
)
expect
(
result
).
to
eq
({
status: :success
})
@opts
.
merge!
(
visibility_level:
Gitlab
::
VisibilityLevel
::
PRIVATE
)
expect
(
project
).
to
be_internal
update_project
(
@project
,
@user
,
@opts
)
end
it
{
expect
(
@created_private
).
to
be_truthy
}
it
{
expect
(
@project
.
private?
).
to
be_truthy
}
end
context
'is internal when updated to internal'
do
before
do
@created_private
=
@project
.
private?
@opts
.
merge!
(
visibility_level:
Gitlab
::
VisibilityLevel
::
INTERNAL
)
update_project
(
@project
,
@user
,
@opts
)
end
end
it
{
expect
(
@created_private
).
to
be_truthy
}
it
{
expect
(
@project
.
internal?
).
to
be_truthy
}
end
end
context
'
is private when updated to public
'
do
context
'
when visibility_level is PUBLIC
'
do
before
do
it
'does not update the project to public'
do
@created_private
=
@project
.
private?
result
=
update_project
(
project
,
user
,
visibility_level:
Gitlab
::
VisibilityLevel
::
PUBLIC
)
@opts
.
merge!
(
visibility_level:
Gitlab
::
VisibilityLevel
::
PUBLIC
)
expect
(
result
).
to
eq
({
status: :error
,
message:
'Visibility level unallowed'
}
)
update_project
(
@project
,
@user
,
@opts
)
expect
(
project
).
to
be_private
end
end
it
{
expect
(
@created_private
).
to
be_truthy
}
context
'when updated by an admin'
do
it
{
expect
(
@project
.
private?
).
to
be_truthy
}
it
'updates the project to public'
do
result
=
update_project
(
project
,
admin
,
visibility_level:
Gitlab
::
VisibilityLevel
::
PUBLIC
)
expect
(
result
).
to
eq
({
status: :success
})
expect
(
project
).
to
be_public
end
end
context
'is public when updated to public by admin'
do
before
do
@created_private
=
@project
.
private?
@opts
.
merge!
(
visibility_level:
Gitlab
::
VisibilityLevel
::
PUBLIC
)
update_project
(
@project
,
@admin
,
@opts
)
end
end
it
{
expect
(
@created_private
).
to
be_truthy
}
it
{
expect
(
@project
.
public?
).
to
be_truthy
}
end
end
end
end
end
end
describe
:visibility_level
do
describe
'visibility_level'
do
let
(
:user
)
{
create
:user
,
admin:
true
}
let
(
:project
)
{
create
(
:project
,
:internal
)
}
let
(
:project
)
{
create
(
:project
,
:internal
)
}
let
(
:forked_project
)
{
create
(
:forked_project_with_submodules
,
:internal
)
}
let
(
:forked_project
)
{
create
(
:forked_project_with_submodules
,
:internal
)
}
let
(
:opts
)
{
{}
}
before
do
before
do
forked_project
.
build_forked_project_link
(
forked_to_project_id:
forked_project
.
id
,
forked_from_project_id:
project
.
id
)
forked_project
.
build_forked_project_link
(
forked_to_project_id:
forked_project
.
id
,
forked_from_project_id:
project
.
id
)
forked_project
.
save
forked_project
.
save
@created_internal
=
project
.
internal?
@fork_created_internal
=
forked_project
.
internal?
end
end
context
'updates forks visibility level when parent set to more restrictive'
do
it
'updates forks visibility level when parent set to more restrictive'
do
before
do
opts
=
{
visibility_level:
Gitlab
::
VisibilityLevel
::
PRIVATE
}
opts
.
merge!
(
visibility_level:
Gitlab
::
VisibilityLevel
::
PRIVATE
)
update_project
(
project
,
user
,
opts
).
inspect
end
it
{
expect
(
@created_internal
).
to
be_truthy
}
expect
(
project
).
to
be_internal
it
{
expect
(
@fork_created_internal
).
to
be_truthy
}
expect
(
forked_project
).
to
be_internal
it
{
expect
(
project
.
private?
).
to
be_truthy
}
it
{
expect
(
project
.
forks
.
first
.
private?
).
to
be_truthy
}
end
context
'does not update forks visibility level when parent set to less restrictive'
do
expect
(
update_project
(
project
,
admin
,
opts
)).
to
eq
({
status: :success
})
before
do
opts
.
merge!
(
visibility_level:
Gitlab
::
VisibilityLevel
::
PUBLIC
)
expect
(
project
).
to
be_private
update_project
(
project
,
user
,
opts
).
inspect
expect
(
forked_project
.
reload
).
to
be_private
end
end
it
{
expect
(
@created_internal
).
to
be_truthy
}
it
'does not update forks visibility level when parent set to less restrictive'
do
it
{
expect
(
@fork_created_internal
).
to
be_truthy
}
opts
=
{
visibility_level:
Gitlab
::
VisibilityLevel
::
PUBLIC
}
it
{
expect
(
project
.
public?
).
to
be_truthy
}
it
{
expect
(
project
.
forks
.
first
.
internal?
).
to
be_truthy
}
expect
(
project
).
to
be_internal
expect
(
forked_project
).
to
be_internal
expect
(
update_project
(
project
,
admin
,
opts
)).
to
eq
({
status: :success
})
expect
(
project
).
to
be_public
expect
(
forked_project
.
reload
).
to
be_internal
end
end
end
it
'returns an error result when record cannot be updated'
do
result
=
update_project
(
project
,
admin
,
{
name:
'foo&bar'
})
expect
(
result
).
to
eq
({
status: :error
,
message:
'Project could not be updated'
})
end
end
def
update_project
(
project
,
user
,
opts
)
def
update_project
(
project
,
user
,
opts
)
Projects
::
UpdateService
.
new
(
project
,
user
,
opts
).
execute
described_class
.
new
(
project
,
user
,
opts
).
execute
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