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
42604d4c
Commit
42604d4c
authored
May 09, 2017
by
Jose Ivan Vargas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent project transfer if a new group is not selected
parent
18a6d9c5
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
82 additions
and
5 deletions
+82
-5
app/assets/javascripts/dispatcher.js
app/assets/javascripts/dispatcher.js
+4
-0
app/assets/javascripts/project_edit.js
app/assets/javascripts/project_edit.js
+16
-0
app/services/projects/transfer_service.rb
app/services/projects/transfer_service.rb
+6
-1
app/views/projects/edit.html.haml
app/views/projects/edit.html.haml
+6
-4
changelogs/unreleased/prevent-project-transfer.yml
changelogs/unreleased/prevent-project-transfer.yml
+4
-0
spec/controllers/projects_controller_spec.rb
spec/controllers/projects_controller_spec.rb
+45
-0
spec/services/projects/transfer_service_spec.rb
spec/services/projects/transfer_service_spec.rb
+1
-0
No files found.
app/assets/javascripts/dispatcher.js
View file @
42604d4c
...
...
@@ -40,6 +40,7 @@ import Group from './group';
import
GroupName
from
'
./group_name
'
;
import
GroupsList
from
'
./groups_list
'
;
import
ProjectsList
from
'
./projects_list
'
;
import
ProjectEdit
from
'
./project_edit
'
;
import
MiniPipelineGraph
from
'
./mini_pipeline_graph_dropdown
'
;
import
BlobLinePermalinkUpdater
from
'
./blob/blob_line_permalink_updater
'
;
import
Landing
from
'
./landing
'
;
...
...
@@ -264,6 +265,9 @@ import ShortcutsBlob from './shortcuts_blob';
new
BlobViewer
();
}
break
;
case
'
projects:edit
'
:
new
ProjectEdit
();
break
;
case
'
projects:pipelines:builds
'
:
case
'
projects:pipelines:failures
'
:
case
'
projects:pipelines:show
'
:
...
...
app/assets/javascripts/project_edit.js
0 → 100644
View file @
42604d4c
export
default
class
ProjectEdit
{
constructor
()
{
this
.
transferForm
=
$
(
'
.js-project-transfer-form
'
);
this
.
selectNamespace
=
$
(
'
.js-project-transfer-form
'
).
find
(
'
.select2
'
);
this
.
selectNamespaceChangedWrapper
=
this
.
selectNamespaceChanged
.
bind
(
this
);
this
.
selectNamespace
.
on
(
'
change
'
,
this
.
selectNamespaceChangedWrapper
);
this
.
selectNamespaceChanged
();
}
selectNamespaceChanged
()
{
const
selectedNamespaceValue
=
this
.
selectNamespace
.
val
();
this
.
transferForm
.
find
(
'
:submit
'
).
prop
(
'
disabled
'
,
!
selectedNamespaceValue
);
}
}
app/services/projects/transfer_service.rb
View file @
42604d4c
...
...
@@ -15,7 +15,12 @@ module Projects
if
allowed_transfer?
(
current_user
,
project
,
new_namespace
)
transfer
(
project
,
new_namespace
)
else
project
.
errors
.
add
(
:new_namespace
,
'is invalid'
)
error_message
=
if
new_namespace
.
blank?
'Please select a namespace to transfer the project to'
else
'Transfer failed, please contact an admin'
end
project
.
errors
.
add
(
:new_namespace
,
error_message
)
false
end
rescue
Projects
::
TransferService
::
TransferError
=>
ex
...
...
app/views/projects/edit.html.haml
View file @
42604d4c
...
...
@@ -246,14 +246,16 @@
.row.prepend-top-default
.col-lg-3
%h4
.prepend-top-0.danger-title
Transfer project
Transfer project to new group
%p
.append-bottom-0
Please select the group you want to transfer this project to in the dropdown to the right.
.col-lg-9
=
form_for
([
@project
.
namespace
.
becomes
(
Namespace
),
@project
],
url:
transfer_namespace_project_path
(
@project
.
namespace
,
@project
),
method: :put
,
remote:
true
)
do
|
f
|
=
form_for
([
@project
.
namespace
.
becomes
(
Namespace
),
@project
],
url:
transfer_namespace_project_path
(
@project
.
namespace
,
@project
),
method: :put
,
remote:
true
,
html:
{
class:
'js-project-transfer-form'
}
)
do
|
f
|
.form-group
=
label_tag
:new_namespace_id
,
nil
,
class:
'label-light'
do
%span
Namespace
%span
Select namespace to transfer to
.form-group
=
select_tag
:new_namespace_id
,
namespaces_options
(
@project
.
namespace_id
),
{
prompt:
'Choose a project namespace'
,
class:
'select2'
}
=
select_tag
:new_namespace_id
,
namespaces_options
(
nil
),
include_blank:
true
,
class:
'select2'
%ul
%li
Be careful. Changing the project's namespace can have unintended side effects.
%li
You can only transfer the project to namespaces you manage.
...
...
changelogs/unreleased/prevent-project-transfer.yml
0 → 100644
View file @
42604d4c
---
title
:
Prevent project transfers if a new group is not selected
merge_request
:
author
:
spec/controllers/projects_controller_spec.rb
View file @
42604d4c
...
...
@@ -226,6 +226,51 @@ describe ProjectsController do
end
end
describe
'#transfer'
do
render_views
subject
(
:project
)
{
create
(
:project
)
}
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:new_namespace
)
{
create
(
:namespace
)
}
it
'updates namespace'
do
controller
.
instance_variable_set
(
:@project
,
project
)
sign_in
(
admin
)
put
:transfer
,
namespace_id:
project
.
namespace
.
id
,
new_namespace_id:
new_namespace
.
id
,
id:
project
.
id
,
format: :js
project
.
reload
expect
(
project
.
namespace
.
id
).
to
eq
(
new_namespace
.
id
)
expect
(
response
).
to
have_http_status
(
200
)
end
context
'when new namespace is empty'
do
it
'project namespace is not changed'
do
controller
.
instance_variable_set
(
:@project
,
project
)
sign_in
(
admin
)
old_namespace_id
=
project
.
namespace
.
id
put
:transfer
,
namespace_id:
old_namespace_id
,
new_namespace_id:
nil
,
id:
project
.
id
,
format: :js
project
.
reload
expect
(
project
.
namespace
.
id
).
to
eq
(
old_namespace_id
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
flash
[
:alert
]).
to
eq
'Please select a namespace to transfer the project to'
end
end
end
describe
"#destroy"
do
let
(
:admin
)
{
create
(
:admin
)
}
...
...
spec/services/projects/transfer_service_spec.rb
View file @
42604d4c
...
...
@@ -26,6 +26,7 @@ describe Projects::TransferService, services: true do
it
{
expect
(
@result
).
to
eq
false
}
it
{
expect
(
project
.
namespace
).
to
eq
(
user
.
namespace
)
}
it
{
expect
(
project
.
errors
.
messages
[
:new_namespace
][
0
]).
to
eq
'Please select a namespace to transfer the project to'
}
end
context
'disallow transfering of project with tags'
do
...
...
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