Commit 61dd92aa authored by Grzegorz Bizon's avatar Grzegorz Bizon

Authorize build update on per object basis

parent 93636753
...@@ -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
......
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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment