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
e293ffd4
Commit
e293ffd4
authored
Aug 30, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring Import::BaseController#find_or_create_namespace
parent
325de662
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
53 additions
and
47 deletions
+53
-47
app/assets/javascripts/importer_status.js
app/assets/javascripts/importer_status.js
+9
-6
app/controllers/import/base_controller.rb
app/controllers/import/base_controller.rb
+7
-12
app/controllers/import/bitbucket_controller.rb
app/controllers/import/bitbucket_controller.rb
+7
-5
app/controllers/import/github_controller.rb
app/controllers/import/github_controller.rb
+6
-2
app/controllers/import/gitlab_controller.rb
app/controllers/import/gitlab_controller.rb
+6
-2
app/views/import/base/create.js.haml
app/views/import/base/create.js.haml
+1
-20
app/views/import/base/unauthorized.js.haml
app/views/import/base/unauthorized.js.haml
+14
-0
app/views/import/bitbucket/deploy_key.js.haml
app/views/import/bitbucket/deploy_key.js.haml
+3
-0
No files found.
app/assets/javascripts/importer_status.js
View file @
e293ffd4
...
@@ -10,21 +10,24 @@
...
@@ -10,21 +10,24 @@
ImporterStatus
.
prototype
.
initStatusPage
=
function
()
{
ImporterStatus
.
prototype
.
initStatusPage
=
function
()
{
$
(
'
.js-add-to-import
'
).
off
(
'
click
'
).
on
(
'
click
'
,
(
function
(
_this
)
{
$
(
'
.js-add-to-import
'
).
off
(
'
click
'
).
on
(
'
click
'
,
(
function
(
_this
)
{
return
function
(
e
)
{
return
function
(
e
)
{
var
$btn
,
$namespace_input
,
$target_field
,
$tr
,
id
,
new
_namespace
;
var
$btn
,
$namespace_input
,
$target_field
,
$tr
,
id
,
target
_namespace
;
$btn
=
$
(
e
.
currentTarget
);
$btn
=
$
(
e
.
currentTarget
);
$tr
=
$btn
.
closest
(
'
tr
'
);
$tr
=
$btn
.
closest
(
'
tr
'
);
$target_field
=
$tr
.
find
(
'
.import-target
'
);
$target_field
=
$tr
.
find
(
'
.import-target
'
);
$namespace_input
=
$target_field
.
find
(
'
input
'
);
$namespace_input
=
$target_field
.
find
(
'
input
'
);
id
=
$tr
.
attr
(
'
id
'
).
replace
(
'
repo_
'
,
''
);
id
=
$tr
.
attr
(
'
id
'
).
replace
(
'
repo_
'
,
''
);
new_namespace
=
null
;
target_namespace
=
null
;
if
(
$namespace_input
.
length
>
0
)
{
if
(
$namespace_input
.
length
>
0
)
{
new
_namespace
=
$namespace_input
.
prop
(
'
value
'
);
target
_namespace
=
$namespace_input
.
prop
(
'
value
'
);
$target_field
.
empty
().
append
(
new
_namespace
+
"
/
"
+
(
$target_field
.
data
(
'
project_name
'
)));
$target_field
.
empty
().
append
(
target
_namespace
+
"
/
"
+
(
$target_field
.
data
(
'
project_name
'
)));
}
}
$btn
.
disable
().
addClass
(
'
is-loading
'
);
$btn
.
disable
().
addClass
(
'
is-loading
'
);
return
$
.
post
(
_this
.
import_url
,
{
return
$
.
post
(
_this
.
import_url
,
{
repo_id
:
id
,
repo_id
:
id
,
new_namespace
:
new
_namespace
target_namespace
:
target
_namespace
},
{
},
{
dataType
:
'
script
'
dataType
:
'
script
'
});
});
...
...
app/controllers/import/base_controller.rb
View file @
e293ffd4
...
@@ -2,21 +2,16 @@ class Import::BaseController < ApplicationController
...
@@ -2,21 +2,16 @@ class Import::BaseController < ApplicationController
private
private
def
find_or_create_namespace
(
name
,
owner
)
def
find_or_create_namespace
(
name
,
owner
)
begin
return
current_user
.
namespace
if
name
==
owner
@target_namespace
=
params
[
:new_namespace
].
presence
||
name
return
current_user
.
namespace
unless
current_user
.
can_create_group?
@target_namespace
=
current_user
.
namespace_path
if
name
==
owner
||
!
current_user
.
can_create_group?
namespace
=
Group
.
create!
(
name:
@target_namespace
,
path:
@target_namespace
,
owner:
current_user
)
begin
name
=
params
[
:target_namespace
].
presence
||
name
namespace
=
Group
.
create!
(
name:
name
,
path:
name
,
owner:
current_user
)
namespace
.
add_owner
(
current_user
)
namespace
.
add_owner
(
current_user
)
namespace
rescue
ActiveRecord
::
RecordNotUnique
,
ActiveRecord
::
RecordInvalid
rescue
ActiveRecord
::
RecordNotUnique
,
ActiveRecord
::
RecordInvalid
namespace
=
Namespace
.
find_by_path_or_name
(
@target_namespace
)
Namespace
.
find_by_path_or_name
(
name
)
unless
current_user
.
can?
(
:create_projects
,
namespace
)
@already_been_taken
=
true
return
false
end
end
end
end
namespace
end
end
end
app/controllers/import/bitbucket_controller.rb
View file @
e293ffd4
...
@@ -38,15 +38,17 @@ class Import::BitbucketController < Import::BaseController
...
@@ -38,15 +38,17 @@ class Import::BitbucketController < Import::BaseController
@repo_id
=
params
[
:repo_id
].
to_s
@repo_id
=
params
[
:repo_id
].
to_s
repo
=
client
.
project
(
@repo_id
.
gsub
(
'___'
,
'/'
))
repo
=
client
.
project
(
@repo_id
.
gsub
(
'___'
,
'/'
))
@project_name
=
repo
[
'slug'
]
@project_name
=
repo
[
'slug'
]
namespace
=
find_or_create_namespace
(
repo
[
'owner'
],
client
.
user
[
'user'
][
'username'
])
||
(
render
and
return
)
@target_namespace
=
find_or_create_namespace
(
repo
[
'owner'
],
client
.
user
[
'user'
][
'username'
]
)
unless
Gitlab
::
BitbucketImport
::
KeyAdder
.
new
(
repo
,
current_user
,
access_params
).
execute
unless
Gitlab
::
BitbucketImport
::
KeyAdder
.
new
(
repo
,
current_user
,
access_params
).
execute
@access_denied
=
true
render
'deploy_key'
and
return
render
return
end
end
@project
=
Gitlab
::
BitbucketImport
::
ProjectCreator
.
new
(
repo
,
namespace
,
current_user
,
access_params
).
execute
if
current_user
.
can?
(
:create_projects
,
@target_namespace
)
@project
=
Gitlab
::
BitbucketImport
::
ProjectCreator
.
new
(
repo
,
@target_namespace
,
current_user
,
access_params
).
execute
else
render
'unauthorized'
end
end
end
private
private
...
...
app/controllers/import/github_controller.rb
View file @
e293ffd4
...
@@ -41,9 +41,13 @@ class Import::GithubController < Import::BaseController
...
@@ -41,9 +41,13 @@ class Import::GithubController < Import::BaseController
@repo_id
=
params
[
:repo_id
].
to_i
@repo_id
=
params
[
:repo_id
].
to_i
repo
=
client
.
repo
(
@repo_id
)
repo
=
client
.
repo
(
@repo_id
)
@project_name
=
repo
.
name
@project_name
=
repo
.
name
namespace
=
find_or_create_namespace
(
repo
.
owner
.
login
,
client
.
user
.
login
)
||
(
render
and
retur
n
)
@target_namespace
=
find_or_create_namespace
(
repo
.
owner
.
login
,
client
.
user
.
logi
n
)
@project
=
Gitlab
::
GithubImport
::
ProjectCreator
.
new
(
repo
,
namespace
,
current_user
,
access_params
).
execute
if
current_user
.
can?
(
:create_projects
,
@target_namespace
)
@project
=
Gitlab
::
GithubImport
::
ProjectCreator
.
new
(
repo
,
@target_namespace
,
current_user
,
access_params
).
execute
else
render
'unauthorized'
end
end
end
private
private
...
...
app/controllers/import/gitlab_controller.rb
View file @
e293ffd4
...
@@ -27,9 +27,13 @@ class Import::GitlabController < Import::BaseController
...
@@ -27,9 +27,13 @@ class Import::GitlabController < Import::BaseController
@repo_id
=
params
[
:repo_id
].
to_i
@repo_id
=
params
[
:repo_id
].
to_i
repo
=
client
.
project
(
@repo_id
)
repo
=
client
.
project
(
@repo_id
)
@project_name
=
repo
[
'name'
]
@project_name
=
repo
[
'name'
]
namespace
=
find_or_create_namespace
(
repo
[
'namespace'
][
'path'
],
client
.
user
[
'username'
])
||
(
render
and
return
)
@target_namespace
=
find_or_create_namespace
(
repo
[
'namespace'
][
'path'
],
client
.
user
[
'username'
]
)
@project
=
Gitlab
::
GitlabImport
::
ProjectCreator
.
new
(
repo
,
namespace
,
current_user
,
access_params
).
execute
if
current_user
.
can?
(
:create_projects
,
@target_namespace
)
@project
=
Gitlab
::
GitlabImport
::
ProjectCreator
.
new
(
repo
,
@target_namespace
,
current_user
,
access_params
).
execute
else
render
'unauthorized'
end
end
end
private
private
...
...
app/views/import/base/create.js.haml
View file @
e293ffd4
-
if
@already_been_taken
-
if
@project
.
persisted?
:plain
tr = $("tr#repo_
#{
@repo_id
}
")
target_field = tr.find(".import-target")
import_button = tr.find(".btn-import")
origin_target = target_field.text()
project_name = "
#{
@project_name
}
"
origin_namespace = "
#{
@target_namespace
}
"
target_field.empty()
target_field.append("<p class='alert alert-danger'>This namespace already been taken! Please choose another one</p>")
target_field.append("<input type='text' name='target_namespace' />")
target_field.append("/" + project_name)
target_field.data("project_name", project_name)
target_field.find('input').prop("value", origin_namespace)
import_button.enable().removeClass('is-loading')
-
elsif
@access_denied
:plain
job = $("tr#repo_
#{
@repo_id
}
")
job.find(".import-actions").html("<p class='alert alert-danger'>Access denied! Please verify you can add deploy keys to this repository.</p>")
-
elsif
@project
.
persisted?
:plain
:plain
job = $("tr#repo_
#{
@repo_id
}
")
job = $("tr#repo_
#{
@repo_id
}
")
job.attr("id", "project_
#{
@project
.
id
}
")
job.attr("id", "project_
#{
@project
.
id
}
")
...
...
app/views/import/base/unauthorized.js.haml
0 → 100644
View file @
e293ffd4
:plain
tr = $("tr#repo_
#{
@repo_id
}
")
target_field = tr.find(".import-target")
import_button = tr.find(".btn-import")
origin_target = target_field.text()
project_name = "
#{
@project_name
}
"
origin_namespace = "
#{
@target_namespace
.
path
}
"
target_field.empty()
target_field.append("<p class='alert alert-danger'>This namespace has already been taken! Please choose another one.</p>")
target_field.append("<input type='text' name='target_namespace' />")
target_field.append("/" + project_name)
target_field.data("project_name", project_name)
target_field.find('input').prop("value", origin_namespace)
import_button.enable().removeClass('is-loading')
app/views/import/bitbucket/deploy_key.js.haml
0 → 100644
View file @
e293ffd4
:plain
job = $("tr#repo_
#{
@repo_id
}
")
job.find(".import-actions").html("<p class='alert alert-danger'>Access denied! Please verify you can add deploy keys to this repository.</p>")
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