Commit 68aaddce authored by Vitali Tatarintev's avatar Vitali Tatarintev

On-call schedules are GitLab Premium

On-call schedules available in GitLab Premium
parent 599047fe
# frozen_string_literal: true
module IncidentManagement
class OncallSchedulesFinder
def initialize(current_user, project, params = {})
@current_user = current_user
@project = project
@params = params
end
def execute
return IncidentManagement::OncallSchedule.none unless available? && allowed?
project.incident_management_oncall_schedules
end
private
attr_reader :current_user, :project, :params
def available?
project.feature_available?(:oncall_schedules)
end
def allowed?
Ability.allowed?(current_user, :read_incident_management_oncall_schedule, project)
end
end
end
......@@ -8,9 +8,7 @@ module Resolvers
type Types::IncidentManagement::OncallScheduleType.connection_type, null: true
def resolve(**args)
return [] unless Ability.allowed?(current_user, :read_incident_management_oncall_schedule, project)
project.incident_management_oncall_schedules
::IncidentManagement::OncallSchedulesFinder.new(context[:current_user], project).execute
end
end
end
......
......@@ -127,6 +127,7 @@ class License < ApplicationRecord
unprotection_restrictions
ci_project_subscriptions
incident_timeline_view
oncall_schedules
]
EEP_FEATURES.freeze
......
......@@ -13,6 +13,7 @@ module IncidentManagement
end
def execute
return error_no_license unless available?
return error_no_permissions unless allowed?
oncall_schedule = project.incident_management_oncall_schedules.create(params)
......@@ -29,6 +30,10 @@ module IncidentManagement
user&.can?(:modify_incident_management_oncall_schedule, project)
end
def available?
project.feature_available?(:oncall_schedules)
end
def error(message)
ServiceResponse.error(message: message)
end
......@@ -41,6 +46,10 @@ module IncidentManagement
error(_('You have insufficient permissions to create an on-call schedule for this project'))
end
def error_no_license
error(_('Your license does not support on-call schedules'))
end
def error_in_create(oncall_schedule)
error(oncall_schedule.errors.full_messages.to_sentence)
end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe IncidentManagement::OncallSchedulesFinder do
let_it_be(:current_user) { create(:user) }
let_it_be_with_refind(:project) { create(:project) }
let_it_be(:oncall_schedule) { create(:incident_management_oncall_schedule, project: project) }
let_it_be(:another_oncall_schedule) { create(:incident_management_oncall_schedule) }
describe '#execute' do
subject(:execute) { described_class.new(current_user, project).execute }
context 'when feature is available' do
before do
stub_licensed_features(oncall_schedules: true)
end
context 'when user has permissions' do
before do
project.add_maintainer(current_user)
end
it 'returns project on-call schedules' do
is_expected.to contain_exactly(oncall_schedule)
end
end
context 'when user has no permissions' do
it { is_expected.to eq(IncidentManagement::OncallSchedule.none) }
end
end
context 'when feature is not avaiable' do
before do
stub_licensed_features(oncall_schedules: false)
end
it { is_expected.to eq(IncidentManagement::OncallSchedule.none) }
end
end
end
......@@ -21,6 +21,7 @@ RSpec.describe Mutations::IncidentManagement::OncallSchedule::Create do
context 'user has access to project' do
before do
stub_licensed_features(oncall_schedules: true)
project.add_maintainer(current_user)
end
......
......@@ -11,23 +11,17 @@ RSpec.describe Resolvers::IncidentManagement::OncallScheduleResolver do
subject { sync(resolve_oncall_schedules) }
specify do
expect(described_class).to have_nullable_graphql_type(Types::IncidentManagement::OncallScheduleType.connection_type)
end
context 'user does not have permissions' do
it { is_expected.to eq(IncidentManagement::OncallSchedule.none) }
end
context 'user has permissions' do
before do
stub_licensed_features(oncall_schedules: true)
project.add_maintainer(current_user)
end
it { is_expected.to contain_exactly(oncall_schedule) }
specify do
expect(described_class).to have_nullable_graphql_type(Types::IncidentManagement::OncallScheduleType.connection_type)
end
# TODO: check feature flag
# TODO: check license "Premium"
it 'returns on-call schedules' do
is_expected.to contain_exactly(oncall_schedule)
end
private
......
......@@ -34,6 +34,7 @@ RSpec.describe 'Creating a new on-call schedule' do
let(:mutation_response) { graphql_mutation_response(:oncall_schedule_create) }
before do
stub_licensed_features(oncall_schedules: true)
project.add_maintainer(current_user)
end
......
......@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe 'getting Incident Management on-call schedules' do
include GraphqlHelpers
let_it_be(:project) { create(:project) }
let_it_be_with_refind(:project) { create(:project) }
let_it_be(:current_user) { create(:user) }
let(:params) { {} }
......@@ -28,6 +28,10 @@ RSpec.describe 'getting Incident Management on-call schedules' do
let(:oncall_schedules) { graphql_data.dig('project', 'incidentManagementOncallSchedules', 'nodes') }
before do
stub_licensed_features(oncall_schedules: true)
end
context 'without project permissions' do
let(:user) { create(:user) }
......@@ -45,6 +49,17 @@ RSpec.describe 'getting Incident Management on-call schedules' do
project.add_maintainer(current_user)
end
context 'with unavailable feature' do
before do
stub_licensed_features(oncall_schedules: false)
post_graphql(query, current_user: current_user)
end
it_behaves_like 'a working graphql query'
it { expect(oncall_schedules).to be_empty }
end
context 'without on-call schedules' do
before do
post_graphql(query, current_user: current_user)
......
......@@ -5,15 +5,14 @@ require 'spec_helper'
RSpec.describe IncidentManagement::OncallSchedules::CreateService do
let_it_be(:user_with_permissions) { create(:user) }
let_it_be(:user_without_permissions) { create(:user) }
let_it_be_with_reload(:project) { create(:project) }
let_it_be_with_refind(:project) { create(:project) }
let(:current_user) { user_with_permissions }
let(:params) { { name: 'On-call schedule', description: 'On-call schedule description', timezone: 'Europe/Berlin' } }
let(:service) { described_class.new(project, current_user, params) }
before do
stub_licensed_features(oncall_schedules: true)
project.add_maintainer(user_with_permissions)
end
......@@ -39,8 +38,16 @@ RSpec.describe IncidentManagement::OncallSchedules::CreateService do
it_behaves_like 'error response', 'You have insufficient permissions to create an on-call schedule for this project'
end
context 'when feature is not available' do
before do
stub_licensed_features(oncall_schedules: false)
end
it_behaves_like 'error response', 'Your license does not support on-call schedules'
end
context 'when an on-call schedule already exists' do
let_it_be(:oncall_schedule) { create(:incident_management_oncall_schedule, project: project, name: 'On-call schedule') }
let!(:oncall_schedule) { create(:incident_management_oncall_schedule, project: project, name: 'On-call schedule') }
it_behaves_like 'error response', 'Name has already been taken'
end
......
......@@ -31262,6 +31262,9 @@ msgstr ""
msgid "You have insufficient permissions to create an HTTP integration for this project"
msgstr ""
msgid "You have insufficient permissions to create an on-call schedule for this project"
msgstr ""
msgid "You have insufficient permissions to remove this HTTP integration"
msgstr ""
......@@ -31628,6 +31631,9 @@ msgstr ""
msgid "Your issues will be imported in the background. Once finished, you'll get a confirmation email."
msgstr ""
msgid "Your license does not support on-call schedules"
msgstr ""
msgid "Your license is valid from"
msgstr ""
......
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