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