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
61dd92aa
Commit
61dd92aa
authored
May 05, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Authorize build update on per object basis
parent
93636753
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
7 deletions
+24
-7
app/controllers/projects/application_controller.rb
app/controllers/projects/application_controller.rb
+5
-3
app/controllers/projects/builds_controller.rb
app/controllers/projects/builds_controller.rb
+19
-4
No files found.
app/controllers/projects/application_controller.rb
View file @
61dd92aa
...
@@ -55,13 +55,15 @@ class Projects::ApplicationController < ApplicationController
...
@@ -55,13 +55,15 @@ class Projects::ApplicationController < ApplicationController
(
current_user
&&
current_user
.
already_forked?
(
project
))
(
current_user
&&
current_user
.
already_forked?
(
project
))
end
end
def
authorize_project!
(
action
)
def
authorize_action!
(
action
)
return
access_denied!
unless
can?
(
current_user
,
action
,
project
)
unless
can?
(
current_user
,
action
,
project
)
return
access_denied!
end
end
end
def
method_missing
(
method_sym
,
*
arguments
,
&
block
)
def
method_missing
(
method_sym
,
*
arguments
,
&
block
)
if
method_sym
.
to_s
=~
/\Aauthorize_(.*)!\z/
if
method_sym
.
to_s
=~
/\Aauthorize_(.*)!\z/
authorize_
project
!
(
$1
.
to_sym
)
authorize_
action
!
(
$1
.
to_sym
)
else
else
super
super
end
end
...
...
app/controllers/projects/builds_controller.rb
View file @
61dd92aa
class
Projects::BuildsController
<
Projects
::
ApplicationController
class
Projects::BuildsController
<
Projects
::
ApplicationController
before_action
:build
,
except:
[
:index
,
:cancel_all
]
before_action
:build
,
except:
[
:index
,
:cancel_all
]
before_action
:authorize_read_build!
,
only:
[
:index
,
:show
,
:status
,
:raw
,
:trace
]
before_action
:authorize_update_build!
,
except:
[
:index
,
:show
,
:status
,
:raw
,
:trace
]
before_action
:authorize_read_build!
,
only:
[
:index
,
:show
,
:status
,
:raw
,
:trace
]
before_action
:authorize_update_build!
,
except:
[
:index
,
:show
,
:status
,
:raw
,
:trace
,
:cancel_all
]
layout
'project'
layout
'project'
def
index
def
index
...
@@ -28,7 +32,12 @@ class Projects::BuildsController < Projects::ApplicationController
...
@@ -28,7 +32,12 @@ class Projects::BuildsController < Projects::ApplicationController
end
end
def
cancel_all
def
cancel_all
@project
.
builds
.
running_or_pending
.
each
(
&
:cancel
)
return
access_denied!
unless
can?
(
current_user
,
:update_build
,
project
)
@project
.
builds
.
running_or_pending
.
each
do
|
build
|
build
.
cancel
if
can?
(
current_user
,
:update_build
,
build
)
end
redirect_to
namespace_project_builds_path
(
project
.
namespace
,
project
)
redirect_to
namespace_project_builds_path
(
project
.
namespace
,
project
)
end
end
...
@@ -107,8 +116,14 @@ class Projects::BuildsController < Projects::ApplicationController
...
@@ -107,8 +116,14 @@ class Projects::BuildsController < Projects::ApplicationController
private
private
def
authorize_update_build!
return
access_denied!
unless
can?
(
current_user
,
:update_build
,
build
)
end
def
build
def
build
@build
||=
project
.
builds
.
find_by!
(
id:
params
[
:id
]).
present
(
current_user:
current_user
)
@build
||=
project
.
builds
.
find_by!
(
id:
params
[
:id
])
.
present
(
current_user:
current_user
)
end
end
def
build_path
(
build
)
def
build_path
(
build
)
...
...
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