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
Léo-Paul Géneau
gitlab-ce
Commits
79fe18d9
Commit
79fe18d9
authored
Dec 17, 2015
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move build artifacts implementation to separate controller
parent
a385d39f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
29 deletions
+46
-29
app/controllers/projects/builds/artifacts_controller.rb
app/controllers/projects/builds/artifacts_controller.rb
+36
-0
app/controllers/projects/builds_controller.rb
app/controllers/projects/builds_controller.rb
+0
-27
app/models/ci/build.rb
app/models/ci/build.rb
+1
-1
config/routes.rb
config/routes.rb
+9
-1
No files found.
app/controllers/projects/builds/artifacts_controller.rb
0 → 100644
View file @
79fe18d9
class
Projects::Builds::ArtifactsController
<
Projects
::
ApplicationController
layout
'project'
before_action
:authorize_download_build_artifacts!
def
download
unless
artifacts_file
.
file_storage?
return
redirect_to
artifacts_file
.
url
end
unless
artifacts_file
.
exists?
return
not_found!
end
send_file
artifacts_file
.
path
,
disposition:
'attachment'
end
private
def
build
@build
||=
project
.
builds
.
unscoped
.
find_by!
(
id:
params
[
:build_id
])
end
def
artifacts_file
@artifacts_file
||=
build
.
artifacts_file
end
def
authorize_download_build_artifacts!
unless
can?
(
current_user
,
:download_build_artifacts
,
@project
)
if
current_user
.
nil?
return
authenticate_user!
else
return
render_404
end
end
end
end
app/controllers/projects/builds_controller.rb
View file @
79fe18d9
...
@@ -2,7 +2,6 @@ class Projects::BuildsController < Projects::ApplicationController
...
@@ -2,7 +2,6 @@ class Projects::BuildsController < Projects::ApplicationController
before_action
:build
,
except:
[
:index
,
:cancel_all
]
before_action
:build
,
except:
[
:index
,
:cancel_all
]
before_action
:authorize_manage_builds!
,
except:
[
:index
,
:show
,
:status
]
before_action
:authorize_manage_builds!
,
except:
[
:index
,
:show
,
:status
]
before_action
:authorize_download_build_artifacts!
,
only:
[
:download
]
layout
"project"
layout
"project"
...
@@ -51,18 +50,6 @@ class Projects::BuildsController < Projects::ApplicationController
...
@@ -51,18 +50,6 @@ class Projects::BuildsController < Projects::ApplicationController
redirect_to
build_path
(
build
)
redirect_to
build_path
(
build
)
end
end
def
download
unless
artifacts_file
.
file_storage?
return
redirect_to
artifacts_file
.
url
end
unless
artifacts_file
.
exists?
return
not_found!
end
send_file
artifacts_file
.
path
,
disposition:
'attachment'
end
def
status
def
status
render
json:
@build
.
to_json
(
only:
[
:status
,
:id
,
:sha
,
:coverage
],
methods: :sha
)
render
json:
@build
.
to_json
(
only:
[
:status
,
:id
,
:sha
,
:coverage
],
methods: :sha
)
end
end
...
@@ -79,10 +66,6 @@ class Projects::BuildsController < Projects::ApplicationController
...
@@ -79,10 +66,6 @@ class Projects::BuildsController < Projects::ApplicationController
@build
||=
project
.
builds
.
unscoped
.
find_by!
(
id:
params
[
:id
])
@build
||=
project
.
builds
.
unscoped
.
find_by!
(
id:
params
[
:id
])
end
end
def
artifacts_file
build
.
artifacts_file
end
def
build_path
(
build
)
def
build_path
(
build
)
namespace_project_build_path
(
build
.
project
.
namespace
,
build
.
project
,
build
)
namespace_project_build_path
(
build
.
project
.
namespace
,
build
.
project
,
build
)
end
end
...
@@ -92,14 +75,4 @@ class Projects::BuildsController < Projects::ApplicationController
...
@@ -92,14 +75,4 @@ class Projects::BuildsController < Projects::ApplicationController
return
page_404
return
page_404
end
end
end
end
def
authorize_download_build_artifacts!
unless
can?
(
current_user
,
:download_build_artifacts
,
@project
)
if
current_user
.
nil?
return
authenticate_user!
else
return
render_404
end
end
end
end
end
app/models/ci/build.rb
View file @
79fe18d9
...
@@ -326,7 +326,7 @@ module Ci
...
@@ -326,7 +326,7 @@ module Ci
def
download_url
def
download_url
if
artifacts_file
.
exists?
if
artifacts_file
.
exists?
Gitlab
::
Application
.
routes
.
url_helpers
.
Gitlab
::
Application
.
routes
.
url_helpers
.
download_namespace_project_build_path
(
project
.
namespace
,
project
,
self
)
download_namespace_project_build_
artifacts_
path
(
project
.
namespace
,
project
,
self
)
end
end
end
end
...
...
config/routes.rb
View file @
79fe18d9
...
@@ -603,10 +603,18 @@ Rails.application.routes.draw do
...
@@ -603,10 +603,18 @@ Rails.application.routes.draw do
member
do
member
do
get
:status
get
:status
post
:cancel
get
:download
get
:download
post
:cancel
post
:retry
post
:retry
end
end
scope
module: :builds
do
resources
:artifacts
do
collection
do
get
:download
end
end
end
end
end
resources
:hooks
,
only:
[
:index
,
:create
,
:destroy
],
constraints:
{
id:
/\d+/
}
do
resources
:hooks
,
only:
[
:index
,
:create
,
:destroy
],
constraints:
{
id:
/\d+/
}
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