Commit c8286886 authored by Kamil Trzciński's avatar Kamil Trzciński

Add feature flag and specs

Cover `Bridge::Common` with tests
and additional feature flag
parent bc050db6
---
name: ci_bridge_pipeline_details
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/41263
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/250683
group: group::memory
type: development
default_enabled: true
...@@ -10,19 +10,29 @@ module Gitlab ...@@ -10,19 +10,29 @@ module Gitlab
end end
def has_details? def has_details?
can?(user, :read_pipeline, subject.downstream_pipeline) !!details_path
end end
def details_path def details_path
return unless subject.downstream_pipeline return unless Feature.enabled?(:ci_bridge_pipeline_details, subject.project, default_enabled: true)
return unless can?(user, :read_pipeline, downstream_pipeline)
pipeline = subject.downstream_pipeline project_pipeline_path(downstream_project, downstream_pipeline)
project_pipeline_path(pipeline.project, pipeline)
end end
def has_action? def has_action?
false false
end end
private
def downstream_pipeline
subject.downstream_pipeline
end
def downstream_project
downstream_pipeline&.project
end
end end
end end
end end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Ci::Status::Bridge::Common do
let_it_be(:user) { create(:user) }
let_it_be(:bridge) { create(:ci_bridge) }
let_it_be(:downstream_pipeline) { create(:ci_pipeline) }
before_all do
create(:ci_sources_pipeline,
source_pipeline: bridge.pipeline,
source_project: bridge.pipeline.project,
source_job: bridge,
pipeline: downstream_pipeline,
project: downstream_pipeline.project)
end
subject do
Gitlab::Ci::Status::Core
.new(bridge, user)
.extend(described_class)
end
describe '#details_path' do
context 'when user has access to read downstream pipeline' do
before do
downstream_pipeline.project.add_developer(user)
end
it { expect(subject).to have_details }
it { expect(subject.details_path).to include "pipelines/#{downstream_pipeline.id}" }
context 'when ci_bridge_pipeline_details is disabled' do
before do
stub_feature_flags(ci_bridge_pipeline_details: false)
end
it { expect(subject).not_to have_details }
it { expect(subject.details_path).to be_nil }
end
end
context 'when user does not have access to read downstream pipeline' do
it { expect(subject).not_to have_details }
it { expect(subject.details_path).to be_nil }
end
end
end
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