Commit 92da3222 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Extract on-call schedules license check

Extract on-call schedules license check into policy
and a single method
parent 5890106c
...@@ -9,7 +9,7 @@ module IncidentManagement ...@@ -9,7 +9,7 @@ module IncidentManagement
end end
def execute def execute
return IncidentManagement::OncallSchedule.none unless available? && allowed? return IncidentManagement::OncallSchedule.none unless allowed?
collection = project.incident_management_oncall_schedules collection = project.incident_management_oncall_schedules
collection = by_iid(collection) collection = by_iid(collection)
...@@ -21,11 +21,6 @@ module IncidentManagement ...@@ -21,11 +21,6 @@ module IncidentManagement
attr_reader :current_user, :project, :params attr_reader :current_user, :project, :params
def available?
Feature.enabled?(:oncall_schedules_mvc, project) &&
project.feature_available?(:oncall_schedules)
end
def allowed? def allowed?
Ability.allowed?(current_user, :read_incident_management_oncall_schedule, project) Ability.allowed?(current_user, :read_incident_management_oncall_schedule, project)
end end
......
...@@ -155,8 +155,7 @@ module EE ...@@ -155,8 +155,7 @@ module EE
with_scope :subject with_scope :subject
condition(:oncall_schedules_available) do condition(:oncall_schedules_available) do
::Feature.enabled?(:oncall_schedules_mvc, @subject) && ::Gitlab::IncidentManagement.oncall_schedules_available?(@subject)
@subject.feature_available?(:oncall_schedules)
end end
rule { visual_review_bot }.policy do rule { visual_review_bot }.policy do
......
...@@ -31,8 +31,7 @@ module IncidentManagement ...@@ -31,8 +31,7 @@ module IncidentManagement
end end
def available? def available?
Feature.enabled?(:oncall_schedules_mvc, project) && ::Gitlab::IncidentManagement.oncall_schedules_available?(project)
project.feature_available?(:oncall_schedules)
end end
def error(message) def error(message)
......
...@@ -31,8 +31,7 @@ module IncidentManagement ...@@ -31,8 +31,7 @@ module IncidentManagement
end end
def available? def available?
Feature.enabled?(:oncall_schedules_mvc, project) && ::Gitlab::IncidentManagement.oncall_schedules_available?(project)
project.feature_available?(:oncall_schedules)
end end
def error(message) def error(message)
......
...@@ -33,8 +33,7 @@ module IncidentManagement ...@@ -33,8 +33,7 @@ module IncidentManagement
end end
def available? def available?
Feature.enabled?(:oncall_schedules_mvc, project) && ::Gitlab::IncidentManagement.oncall_schedules_available?(project)
project.feature_available?(:oncall_schedules)
end end
def error(message) def error(message)
......
# frozen_string_literal: true
module Gitlab
module IncidentManagement
def self.oncall_schedules_available?(project)
::Feature.enabled?(:oncall_schedules_mvc, project) &&
project.feature_available?(:oncall_schedules)
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::IncidentManagement do
let_it_be_with_refind(:project) { create(:project) }
describe '.oncall_schedules_available?' do
subject { described_class.oncall_schedules_available?(project) }
before do
stub_licensed_features(oncall_schedules: true)
stub_feature_flags(oncall_schedules_mvc: project)
end
it { is_expected.to be_truthy }
context 'when feature flag is disabled' do
before do
stub_feature_flags(oncall_schedules_mvc: false)
end
it { is_expected.to be_falsey }
end
context 'when there is no license' do
before do
stub_licensed_features(oncall_schedules: false)
end
it { is_expected.to be_falsey }
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