Commit 0b9856d0 authored by Ethan Urie's avatar Ethan Urie Committed by Rémy Coutable

Expose `plan` and `trial` in the `/users` endpoint

`plan` is hooked up to the models but trial is not yet.
parent 0edd1b14
---
title: Expose `plan` and `trial` to `/users/:id` endpoint
merge_request: 25151
author:
type: added
...@@ -304,10 +304,14 @@ Example Responses: ...@@ -304,10 +304,14 @@ Example Responses:
"external": false, "external": false,
"private_profile": false, "private_profile": false,
"current_sign_in_ip": "196.165.1.102", "current_sign_in_ip": "196.165.1.102",
"last_sign_in_ip": "172.127.2.22" "last_sign_in_ip": "172.127.2.22",
"plan": "gold",
"trial": true
} }
``` ```
NOTE: **Note:** The `plan` and `trial` parameters are only available on GitLab Enterprise Edition.
Users on GitLab [Starter, Bronze, or higher](https://about.gitlab.com/pricing/) will also see Users on GitLab [Starter, Bronze, or higher](https://about.gitlab.com/pricing/) will also see
the `shared_runners_minutes_limit`, `extra_shared_runners_minutes_limit`, and `note` parameters. the `shared_runners_minutes_limit`, `extra_shared_runners_minutes_limit`, and `note` parameters.
......
...@@ -539,6 +539,20 @@ module EE ...@@ -539,6 +539,20 @@ module EE
end end
end end
end end
module UserDetailsWithAdmin
extend ActiveSupport::Concern
prepended do
expose :plan do |user|
user.namespace.try(:gitlab_subscription)&.plan_name
end
expose :trial do |user|
user.namespace.try(:trial?)
end
end
end
end end
end end
end end
...@@ -276,4 +276,60 @@ describe API::Users do ...@@ -276,4 +276,60 @@ describe API::Users do
end end
end end
end end
describe 'GET /user/:id' do
context 'when authenticated' do
context 'as an admin' do
context 'and user has a plan' do
let!(:subscription) { create(:gitlab_subscription, :gold, namespace: user.namespace) }
context 'and user is not a trial user' do
it 'contains plan and trial' do
get api("/users/#{user.id}", admin)
expect(json_response).to include('plan' => 'gold', 'trial' => false)
end
end
context 'and user is a trial user' do
before do
subscription.update!(trial: true)
end
it 'contains plan and trial' do
get api("/users/#{user.id}", admin)
expect(json_response).to include('plan' => 'gold', 'trial' => true)
end
end
end
context 'and user has no plan' do
it 'returns `nil` for both plan and trial' do
get api("/users/#{user.id}", admin)
expect(json_response).to include('plan' => nil, 'trial' => nil)
end
end
end
context 'as a user' do
it 'does not contain plan and trial info' do
get api("/users/#{user.id}", user)
expect(json_response).not_to have_key('plan')
expect(json_response).not_to have_key('trial')
end
end
end
context 'when not authenticated' do
it 'does not contain plan and trial info' do
get api("/users/#{user.id}")
expect(json_response).not_to have_key('plan')
expect(json_response).not_to have_key('trial')
end
end
end
end end
...@@ -9,3 +9,5 @@ module API ...@@ -9,3 +9,5 @@ module API
end end
end end
end end
API::Entities::UserDetailsWithAdmin.prepend_if_ee('EE::API::Entities::UserDetailsWithAdmin')
...@@ -330,6 +330,14 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -330,6 +330,14 @@ describe API::Users, :do_not_mock_admin_mode do
expect(json_response.keys).not_to include 'last_sign_in_ip' expect(json_response.keys).not_to include 'last_sign_in_ip'
end end
it "does not contain plan or trial data" do
get api("/users/#{user.id}", user)
expect(response).to match_response_schema('public_api/v4/user/basic')
expect(json_response.keys).not_to include 'plan'
expect(json_response.keys).not_to include 'trial'
end
context 'when job title is present' do context 'when job title is present' do
let(:job_title) { 'Fullstack Engineer' } let(:job_title) { 'Fullstack Engineer' }
...@@ -367,6 +375,22 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -367,6 +375,22 @@ describe API::Users, :do_not_mock_admin_mode do
expect(json_response['highest_role']).to be(0) expect(json_response['highest_role']).to be(0)
end end
if Gitlab.ee?
it 'does not include values for plan or trial' do
get api("/users/#{user.id}", admin)
expect(response).to match_response_schema('public_api/v4/user/basic')
end
else
it 'does not include plan or trial data' do
get api("/users/#{user.id}", admin)
expect(response).to match_response_schema('public_api/v4/user/basic')
expect(json_response.keys).not_to include 'plan'
expect(json_response.keys).not_to include 'trial'
end
end
context 'when user has not logged in' do context 'when user has not logged in' do
it 'does not include the sign in IPs' do it 'does not include the sign in IPs' do
get api("/users/#{user.id}", admin) get api("/users/#{user.id}", admin)
......
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