Commit 9c0a8cb5 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Incorporate permission checks into new CI statuses

[ci skip]
parent 3acf4323
...@@ -3,10 +3,10 @@ module Gitlab ...@@ -3,10 +3,10 @@ module Gitlab
module Status module Status
module Status module Status
class Cancelable < SimpleDelegator class Cancelable < SimpleDelegator
extend Status::Extended include Status::Extended
def has_action?(current_user) def has_action?
can?(current_user, :update_build, subject) can?(user, :update_build, subject)
end end
def action_icon def action_icon
...@@ -14,14 +14,16 @@ module Gitlab ...@@ -14,14 +14,16 @@ module Gitlab
end end
def action_path def action_path
cancel_namespace_project_build_path(subject.project.namespace, subject.project, subject) cancel_namespace_project_build_path(subject.project.namespace,
subject.project,
subject)
end end
def action_method def action_method
:post :post
end end
def self.matches?(build) def self.matches?(build, user)
build.cancelable? build.cancelable?
end end
end end
......
...@@ -3,14 +3,14 @@ module Gitlab ...@@ -3,14 +3,14 @@ module Gitlab
module Status module Status
module Build module Build
module Common module Common
def has_details?(current_user) def has_details?
can?(current_user, :read_build, subject) can?(user, :read_build, subject)
end end
def details_path def details_path
namespace_project_build_path(@subject.project.namespace, namespace_project_build_path(subject.project.namespace,
@subject.project, subject.project,
@subject.pipeline) subject.pipeline)
end end
end end
end end
......
...@@ -3,7 +3,7 @@ module Gitlab ...@@ -3,7 +3,7 @@ module Gitlab
module Status module Status
module Status module Status
class Play < SimpleDelegator class Play < SimpleDelegator
extend Status::Extended include Status::Extended
def text def text
'play' 'play'
...@@ -13,8 +13,8 @@ module Gitlab ...@@ -13,8 +13,8 @@ module Gitlab
'play' 'play'
end end
def has_action?(current_user) def has_action?
can?(current_user, :update_build, subject) can?(user, :update_build, subject)
end end
def action_icon def action_icon
...@@ -22,14 +22,16 @@ module Gitlab ...@@ -22,14 +22,16 @@ module Gitlab
end end
def action_path def action_path
play_namespace_project_build_path(subject.project.namespace, subject.project, subject) play_namespace_project_build_path(subject.project.namespace,
subject.project,
subject)
end end
def action_method def action_method
:post :post
end end
def self.matches?(build) def self.matches?(build, user)
build.playable? && !build.stops_environment? build.playable? && !build.stops_environment?
end end
end end
......
...@@ -3,10 +3,10 @@ module Gitlab ...@@ -3,10 +3,10 @@ module Gitlab
module Status module Status
module Status module Status
class Retryable < SimpleDelegator class Retryable < SimpleDelegator
extend Status::Extended include Status::Extended
def has_action?(current_user) def has_action?
can?(current_user, :update_build, subject) can?(user, :update_build, subject)
end end
def action_icon def action_icon
...@@ -14,14 +14,16 @@ module Gitlab ...@@ -14,14 +14,16 @@ module Gitlab
end end
def action_path def action_path
retry_namespace_project_build_path(subject.project.namespace, subject.project, subject) retry_namespace_project_build_path(subject.project.namespace,
subject.project,
subject)
end end
def action_method def action_method
:post :post
end end
def self.matches?(build) def self.matches?(build, user)
build.retryable? build.retryable?
end end
end end
......
...@@ -3,7 +3,7 @@ module Gitlab ...@@ -3,7 +3,7 @@ module Gitlab
module Status module Status
module Status module Status
class Play < SimpleDelegator class Play < SimpleDelegator
extend Status::Extended include Status::Extended
def text def text
'stop' 'stop'
...@@ -21,8 +21,8 @@ module Gitlab ...@@ -21,8 +21,8 @@ module Gitlab
'stop' 'stop'
end end
def has_action?(current_user) def has_action?
can?(current_user, :update_build, subject) can?(user, :update_build, subject)
end end
def action_icon def action_icon
...@@ -30,14 +30,16 @@ module Gitlab ...@@ -30,14 +30,16 @@ module Gitlab
end end
def action_path def action_path
play_namespace_project_build_path(subject.project.namespace, subject.project, subject) play_namespace_project_build_path(subject.project.namespace,
subject.project,
subject)
end end
def action_method def action_method
:post :post
end end
def self.matches?(build) def self.matches?(build, user)
build.playable? && build.stops_environment? build.playable? && build.stops_environment?
end end
end end
......
...@@ -6,8 +6,11 @@ module Gitlab ...@@ -6,8 +6,11 @@ module Gitlab
class Core class Core
include Gitlab::Routing.url_helpers include Gitlab::Routing.url_helpers
def initialize(subject) attr_reader :subject, :user
def initialize(subject, user)
@subject = subject @subject = subject
@user = user
end end
def icon def icon
...@@ -18,10 +21,6 @@ module Gitlab ...@@ -18,10 +21,6 @@ module Gitlab
raise NotImplementedError raise NotImplementedError
end end
def title
"#{@subject.class.name.demodulize}: #{label}"
end
# Deprecation warning: this method is here because we need to maintain # Deprecation warning: this method is here because we need to maintain
# backwards compatibility with legacy statuses. We often do something # backwards compatibility with legacy statuses. We often do something
# like "ci-status ci-status-#{status}" to set CSS class. # like "ci-status ci-status-#{status}" to set CSS class.
...@@ -33,7 +32,7 @@ module Gitlab ...@@ -33,7 +32,7 @@ module Gitlab
self.class.name.demodulize.downcase.underscore self.class.name.demodulize.downcase.underscore
end end
def has_details?(_user = nil) def has_details?
false false
end end
...@@ -41,7 +40,7 @@ module Gitlab ...@@ -41,7 +40,7 @@ module Gitlab
raise NotImplementedError raise NotImplementedError
end end
def has_action?(_user = nil) def has_action?
false false
end end
......
...@@ -2,10 +2,14 @@ module Gitlab ...@@ -2,10 +2,14 @@ module Gitlab
module Ci module Ci
module Status module Status
module Extended module Extended
extend ActiveSupport::Concern
class_methods do
def matches?(_subject, _user) def matches?(_subject, _user)
raise NotImplementedError raise NotImplementedError
end end
end end
end end
end end
end
end end
...@@ -2,7 +2,7 @@ module Gitlab ...@@ -2,7 +2,7 @@ module Gitlab
module Ci module Ci
module Status module Status
class Factory class Factory
def initialize(subject, user = nil) def initialize(subject, user)
@subject = subject @subject = subject
@user = user @user = user
end end
...@@ -32,7 +32,7 @@ module Gitlab ...@@ -32,7 +32,7 @@ module Gitlab
def core_status def core_status
Gitlab::Ci::Status Gitlab::Ci::Status
.const_get(simple_status.capitalize) .const_get(simple_status.capitalize)
.new(@subject) .new(@subject, @user)
.extend(self.class.common_helpers) .extend(self.class.common_helpers)
end end
......
...@@ -3,14 +3,14 @@ module Gitlab ...@@ -3,14 +3,14 @@ module Gitlab
module Status module Status
module Pipeline module Pipeline
module Common module Common
def has_details?(current_user) def has_details?
can?(current_user, :read_pipeline, subject) can?(user, :read_pipeline, subject)
end end
def details_path def details_path
namespace_project_pipeline_path(@subject.project.namespace, namespace_project_pipeline_path(subject.project.namespace,
@subject.project, subject.project,
@subject) subject)
end end
def has_action? def has_action?
......
...@@ -3,7 +3,7 @@ module Gitlab ...@@ -3,7 +3,7 @@ module Gitlab
module Status module Status
module Pipeline module Pipeline
class SuccessWithWarnings < SimpleDelegator class SuccessWithWarnings < SimpleDelegator
extend Status::Extended include Status::Extended
def text def text
'passed' 'passed'
...@@ -21,7 +21,7 @@ module Gitlab ...@@ -21,7 +21,7 @@ module Gitlab
'success_with_warnings' 'success_with_warnings'
end end
def self.matches?(pipeline) def self.matches?(pipeline, user)
pipeline.success? && pipeline.has_warnings? pipeline.success? && pipeline.has_warnings?
end end
end end
......
...@@ -3,15 +3,15 @@ module Gitlab ...@@ -3,15 +3,15 @@ module Gitlab
module Status module Status
module Stage module Stage
module Common module Common
def has_details?(current_user) def has_details?
can?(current_user, :read_pipeline, subject) can?(user, :read_pipeline, subject)
end end
def details_path def details_path
namespace_project_pipeline_path(@subject.project.namespace, namespace_project_pipeline_path(subject.project.namespace,
@subject.project, subject.project,
@subject.pipeline, subject.pipeline,
anchor: @subject.name) anchor: subject.name)
end end
def has_action? def has_action?
......
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