diff --git a/config/feature_flags/development/self_managed_code_suggestions.yml b/config/feature_flags/development/self_managed_code_suggestions.yml new file mode 100644 index 0000000000000000000000000000000000000000..1c0f636bd8bfa386ecab0016c9d506cba6ba0fcf --- /dev/null +++ b/config/feature_flags/development/self_managed_code_suggestions.yml @@ -0,0 +1,8 @@ +--- +name: self_managed_code_suggestions +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/138490 +rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/432983 +milestone: '16.7' +type: development +group: group::purchase +default_enabled: false diff --git a/ee/app/graphql/resolvers/gitlab_subscriptions/add_on_eligible_users_resolver.rb b/ee/app/graphql/resolvers/gitlab_subscriptions/add_on_eligible_users_resolver.rb index 18ece6a0bb8e35fa6577609ab3c247602ff34c48..2e58b640b47b0d76b9a7470b738d11b22d854b5d 100644 --- a/ee/app/graphql/resolvers/gitlab_subscriptions/add_on_eligible_users_resolver.rb +++ b/ee/app/graphql/resolvers/gitlab_subscriptions/add_on_eligible_users_resolver.rb @@ -4,6 +4,7 @@ module Resolvers module GitlabSubscriptions class AddOnEligibleUsersResolver < BaseResolver include Gitlab::Graphql::Authorize::AuthorizeResource + include ::GitlabSubscriptions::CodeSuggestionsHelper argument :search, type: GraphQL::Types::String, @@ -23,7 +24,7 @@ class AddOnEligibleUsersResolver < BaseResolver def resolve(add_on_type:, search: nil) authorize!(namespace) - return [] unless Feature.enabled?(:hamilton_seat_management, namespace) + return [] unless code_suggestions_available?(namespace) ::GitlabSubscriptions::AddOnEligibleUsersFinder.new( namespace, diff --git a/ee/app/graphql/resolvers/gitlab_subscriptions/self_managed/add_on_eligible_users_resolver.rb b/ee/app/graphql/resolvers/gitlab_subscriptions/self_managed/add_on_eligible_users_resolver.rb index 9371b6075f2c5f49b669ab0db053e6b947c2dae5..7492215224216fdc7c35b038672a9eb71e6f9fe0 100644 --- a/ee/app/graphql/resolvers/gitlab_subscriptions/self_managed/add_on_eligible_users_resolver.rb +++ b/ee/app/graphql/resolvers/gitlab_subscriptions/self_managed/add_on_eligible_users_resolver.rb @@ -5,6 +5,7 @@ module GitlabSubscriptions module SelfManaged class AddOnEligibleUsersResolver < BaseResolver include Gitlab::Graphql::Authorize::AuthorizeResource + include ::GitlabSubscriptions::CodeSuggestionsHelper type [::Types::GitlabSubscriptions::AddOnUserType.connection_type], null: true @@ -21,6 +22,8 @@ class AddOnEligibleUsersResolver < BaseResolver def resolve(add_on_type:, search: nil) authorize! + return [] unless code_suggestions_available? + ::GitlabSubscriptions::SelfManaged::AddOnEligibleUsersFinder.new( add_on_type: add_on_type, search_term: search diff --git a/ee/app/helpers/gitlab_subscriptions/code_suggestions_helper.rb b/ee/app/helpers/gitlab_subscriptions/code_suggestions_helper.rb new file mode 100644 index 0000000000000000000000000000000000000000..458ab4f2775e248aa67529eba5e173dfbede7e5b --- /dev/null +++ b/ee/app/helpers/gitlab_subscriptions/code_suggestions_helper.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module GitlabSubscriptions + module CodeSuggestionsHelper + def code_suggestions_available?(namespace = nil) + if gitlab_saas? + Feature.enabled?(:hamilton_seat_management, namespace) + else + Feature.enabled?(:self_managed_code_suggestions) + end + end + + private + + def gitlab_saas? + ::Gitlab::Saas.feature_available?(:code_suggestions) + end + end +end diff --git a/ee/spec/helpers/gitlab_subscriptions/code_suggestions_helper_spec.rb b/ee/spec/helpers/gitlab_subscriptions/code_suggestions_helper_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..8bf12f8dcf23b6562fbdee9bc8cc027f15938ff6 --- /dev/null +++ b/ee/spec/helpers/gitlab_subscriptions/code_suggestions_helper_spec.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSubscriptions::CodeSuggestionsHelper, feature_category: :seat_cost_management do + describe '#code_suggestions_available?' do + context 'when GitLab is SaaS' do + let_it_be(:namespace) { build_stubbed(:group) } + + before do + stub_saas_features(code_suggestions: true) + end + + context 'when SaaS feature flag is globally enabled' do + it 'returns true' do + expect(helper.code_suggestions_available?(namespace)).to be_truthy + end + end + + context 'when SaaS feature flag is globally disabled' do + before do + stub_feature_flags(hamilton_seat_management: false) + end + + it 'returns false' do + expect(helper.code_suggestions_available?(namespace)).to be_falsy + end + + context 'when SaaS feature flag is enabled for a specific namespace' do + before do + stub_feature_flags(hamilton_seat_management: namespace) + end + + it 'returns true' do + expect(helper.code_suggestions_available?(namespace)).to be_truthy + end + end + end + end + + context 'when GitLab is self-managed' do + before do + stub_saas_features(code_suggestions: false) + end + + context 'when self-managed feature flag is enabled' do + it 'returns true' do + expect(helper.code_suggestions_available?).to be_truthy + end + end + + context 'when self-managed feature flag is disabled' do + before do + stub_feature_flags(self_managed_code_suggestions: false) + end + + it 'returns false' do + expect(helper.code_suggestions_available?).to be_falsy + end + end + end + end +end diff --git a/ee/spec/requests/api/graphql/gitlab_subscriptions/add_on_eligible_users_spec.rb b/ee/spec/requests/api/graphql/gitlab_subscriptions/add_on_eligible_users_spec.rb index c6b3df9cb4ad473155b9696c137dbd3db0c8d583..4b81f3f9d40d882adbe251230d3adb5edd143ebf 100644 --- a/ee/spec/requests/api/graphql/gitlab_subscriptions/add_on_eligible_users_spec.rb +++ b/ee/spec/requests/api/graphql/gitlab_subscriptions/add_on_eligible_users_spec.rb @@ -22,6 +22,10 @@ ]) end + before do + stub_saas_features(code_suggestions: true) + end + context 'when the user is not eligible to admin add-on purchases on the namespace' do let(:query) do graphql_query_for( diff --git a/ee/spec/requests/api/graphql/gitlab_subscriptions/self_managed/add_on_eligible_users_spec.rb b/ee/spec/requests/api/graphql/gitlab_subscriptions/self_managed/add_on_eligible_users_spec.rb index 751ac21e0da897b8720cb8bb449882d602a2dc80..e880ca4d06ead3de302bd59d31b35bda53044b9a 100644 --- a/ee/spec/requests/api/graphql/gitlab_subscriptions/self_managed/add_on_eligible_users_spec.rb +++ b/ee/spec/requests/api/graphql/gitlab_subscriptions/self_managed/add_on_eligible_users_spec.rb @@ -92,6 +92,18 @@ create(:gitlab_subscription_user_add_on_assignment, user: active_user, add_on_purchase: add_on_purchase) end + context 'when the :self_managed_code_suggestions FF is disabled' do + before do + stub_feature_flags(self_managed_code_suggestions: false) + end + + it 'returns an empty collection' do + post_graphql(query, current_user: current_user) + + expect(graphql_data_at(:self_managed_add_on_eligible_users, :nodes)).to match_array([]) + end + end + context 'when there are search args' do let(:query) do graphql_query_for(