Commit 9ecc7849 authored by Stan Hu's avatar Stan Hu

Merge branch '119158-add-trial_ends_on-to-namespaces-api-v4-api' into 'master'

Add trial_ends_on to Namespaces API

Closes #119158

See merge request gitlab-org/gitlab!22121
parents f98e1124 8242c100
......@@ -34,6 +34,7 @@ module EE
accepts_nested_attributes_for :gitlab_subscription
scope :include_gitlab_subscription, -> { includes(:gitlab_subscription) }
scope :with_plan, -> { where.not(plan_id: nil) }
scope :with_shared_runners_minutes_limit, -> { where("namespaces.shared_runners_minutes_limit > 0") }
scope :with_extra_shared_runners_minutes_limit, -> { where("namespaces.extra_shared_runners_minutes_limit > 0") }
......
---
title: Add trial_ends_on to Namespaces API
merge_request: 22121
author:
type: added
......@@ -148,14 +148,19 @@ module EE
extend ActiveSupport::Concern
prepended do
can_admin_namespace = ->(namespace, opts) { ::Ability.allowed?(opts[:current_user], :admin_namespace, namespace) }
expose :shared_runners_minutes_limit, if: ->(_, options) { options[:current_user]&.admin? }
expose :extra_shared_runners_minutes_limit, if: ->(_, options) { options[:current_user]&.admin? }
expose :billable_members_count do |namespace, options|
namespace.billable_members_count(options[:requested_hosted_plan])
end
expose :plan, if: ->(namespace, opts) { ::Ability.allowed?(opts[:current_user], :admin_namespace, namespace) } do |namespace, _|
expose :plan, if: can_admin_namespace do |namespace, _|
namespace.actual_plan_name
end
expose :trial_ends_on, if: can_admin_namespace do |namespace, _|
namespace.trial_ends_on
end
end
end
......
......@@ -22,12 +22,12 @@ describe API::Namespaces do
expect(group_kind_json_response.keys).to contain_exactly('id', 'kind', 'name', 'path', 'full_path',
'parent_id', 'members_count_with_descendants',
'plan', 'shared_runners_minutes_limit',
'avatar_url', 'web_url',
'avatar_url', 'web_url', 'trial_ends_on',
'extra_shared_runners_minutes_limit', 'billable_members_count')
expect(user_kind_json_response.keys).to contain_exactly('id', 'kind', 'name', 'path', 'full_path',
'parent_id', 'plan', 'shared_runners_minutes_limit',
'avatar_url', 'web_url',
'avatar_url', 'web_url', 'trial_ends_on',
'extra_shared_runners_minutes_limit', 'billable_members_count')
end
end
......@@ -40,7 +40,7 @@ describe API::Namespaces do
owned_group_response = json_response.find { |resource| resource['id'] == group1.id }
expect(owned_group_response.keys).to contain_exactly('id', 'kind', 'name', 'path', 'full_path',
expect(owned_group_response.keys).to contain_exactly('id', 'kind', 'name', 'path', 'full_path', 'trial_ends_on',
'plan', 'parent_id', 'members_count_with_descendants',
'avatar_url', 'web_url', 'billable_members_count')
end
......
......@@ -32,6 +32,8 @@ module API
get do
namespaces = current_user.admin ? Namespace.all : current_user.namespaces
namespaces = namespaces.include_gitlab_subscription if Gitlab.ee?
namespaces = namespaces.search(params[:search]) if params[:search].present?
options = { with: Entities::Namespace, current_user: current_user }
......
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