BigW Consortium Gitlab

Commit 9c0a8cb5 by Grzegorz Bizon

Incorporate permission checks into new CI statuses

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