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
Boxiang Sun
gitlab-ce
Commits
674cbe93
Commit
674cbe93
authored
Nov 29, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dont allow project creation without repository
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
27cd35de
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
41 deletions
+52
-41
app/controllers/projects_controller.rb
app/controllers/projects_controller.rb
+4
-3
app/models/project.rb
app/models/project.rb
+21
-0
app/services/projects/create_service.rb
app/services/projects/create_service.rb
+26
-24
app/views/projects/create.js.haml
app/views/projects/create.js.haml
+0
-13
app/views/projects/new.html.haml
app/views/projects/new.html.haml
+1
-1
No files found.
app/controllers/projects_controller.rb
View file @
674cbe93
...
@@ -19,10 +19,11 @@ class ProjectsController < ApplicationController
...
@@ -19,10 +19,11 @@ class ProjectsController < ApplicationController
def
create
def
create
@project
=
::
Projects
::
CreateService
.
new
(
current_user
,
project_params
).
execute
@project
=
::
Projects
::
CreateService
.
new
(
current_user
,
project_params
).
execute
flash
[
:notice
]
=
'Project was successfully created.'
if
@project
.
saved?
respond_to
do
|
format
|
if
@project
.
saved?
format
.
js
redirect_to
project_path
(
@project
),
notice:
'Project was successfully created.'
else
render
'new'
end
end
end
end
...
...
app/models/project.rb
View file @
674cbe93
...
@@ -586,4 +586,25 @@ class Project < ActiveRecord::Base
...
@@ -586,4 +586,25 @@ class Project < ActiveRecord::Base
def
origin_merge_requests
def
origin_merge_requests
merge_requests
.
where
(
source_project_id:
self
.
id
)
merge_requests
.
where
(
source_project_id:
self
.
id
)
end
end
def
create_repository
if
gitlab_shell
.
add_repository
(
path_with_namespace
)
true
else
errors
.
add
(
:base
,
"Failed to create repository"
)
false
end
end
def
repository_exists?
!!
repository
.
exists?
end
def
create_wiki
ProjectWiki
.
new
(
self
,
self
.
owner
).
wiki
true
rescue
ProjectWiki
::
CouldNotCreateWikiError
=>
ex
errors
.
add
(
:base
,
"Failed create wiki"
)
false
end
end
end
app/services/projects/create_service.rb
View file @
674cbe93
...
@@ -37,35 +37,22 @@ module Projects
...
@@ -37,35 +37,22 @@ module Projects
@project
.
creator
=
current_user
@project
.
creator
=
current_user
if
@project
.
save
Project
.
transaction
do
log_info
(
"
#{
@project
.
owner
.
name
}
created a new project
\"
#{
@project
.
name_with_namespace
}
\"
"
)
@project
.
save
system_hook_service
.
execute_hooks_for
(
@project
,
:create
)
unless
@project
.
group
unless
@project
.
import?
@project
.
team
<<
[
current_user
,
:master
]
unless
@project
.
create_repository
raise
'Failed to create repository'
end
end
end
@project
.
update_column
(
:last_activity_at
,
@project
.
created_at
)
if
@project
.
import?
@project
.
import_start
else
GitlabShellWorker
.
perform_async
(
:add_repository
,
@project
.
path_with_namespace
)
end
end
if
@project
.
persisted?
if
@project
.
wiki_enabled?
if
@project
.
wiki_enabled?
begin
@project
.
create_wiki
# force the creation of a wiki,
ProjectWiki
.
new
(
@project
,
@project
.
owner
).
wiki
rescue
ProjectWiki
::
CouldNotCreateWikiError
=>
ex
# Prevent project observer crash
# if failed to create wiki
nil
end
end
end
after_create_actions
end
end
@project
@project
...
@@ -84,5 +71,20 @@ module Projects
...
@@ -84,5 +71,20 @@ module Projects
namespace
=
Namespace
.
find_by
(
id:
namespace_id
)
namespace
=
Namespace
.
find_by
(
id:
namespace_id
)
current_user
.
can?
(
:create_projects
,
namespace
)
current_user
.
can?
(
:create_projects
,
namespace
)
end
end
def
after_create_actions
log_info
(
"
#{
@project
.
owner
.
name
}
created a new project
\"
#{
@project
.
name_with_namespace
}
\"
"
)
system_hook_service
.
execute_hooks_for
(
@project
,
:create
)
unless
@project
.
group
@project
.
team
<<
[
current_user
,
:master
]
end
@project
.
update_column
(
:last_activity_at
,
@project
.
created_at
)
if
@project
.
import?
@project
.
import_start
end
end
end
end
end
end
app/views/projects/create.js.haml
deleted
100644 → 0
View file @
27cd35de
-
if
@project
.
saved?
-
if
@project
.
import?
:plain
location.href = "
#{
import_project_path
(
@project
)
}
";
-
else
:plain
location.href = "
#{
project_path
(
@project
)
}
";
-
else
:plain
$(".project-edit-errors").html("
#{
escape_javascript
(
render
(
'errors'
))
}
");
$('.project-submit').enable();
$('.save-project-loader').hide();
$('.project-edit-container').show();
app/views/projects/new.html.haml
View file @
674cbe93
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
=
render
'projects/errors'
=
render
'projects/errors'
.project-edit-content
.project-edit-content
=
form_for
@project
,
remote:
true
,
html:
{
class:
'new_project form-horizontal'
}
do
|
f
|
=
form_for
@project
,
html:
{
class:
'new_project form-horizontal'
}
do
|
f
|
.form-group.project-name-holder
.form-group.project-name-holder
=
f
.
label
:name
,
class:
'control-label'
do
=
f
.
label
:name
,
class:
'control-label'
do
%strong
Project name
%strong
Project name
...
...
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