Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
0b9856d0
Commit
0b9856d0
authored
Mar 12, 2020
by
Ethan Urie
Committed by
Rémy Coutable
Mar 12, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose `plan` and `trial` in the `/users` endpoint
`plan` is hooked up to the models but trial is not yet.
parent
0edd1b14
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
106 additions
and
1 deletion
+106
-1
changelogs/unreleased/198391-add-user-plan-and-trial-status-to-api.yml
...released/198391-add-user-plan-and-trial-status-to-api.yml
+5
-0
doc/api/users.md
doc/api/users.md
+5
-1
ee/lib/ee/api/entities.rb
ee/lib/ee/api/entities.rb
+14
-0
ee/spec/requests/api/users_spec.rb
ee/spec/requests/api/users_spec.rb
+56
-0
lib/api/entities/user_details_with_admin.rb
lib/api/entities/user_details_with_admin.rb
+2
-0
spec/requests/api/users_spec.rb
spec/requests/api/users_spec.rb
+24
-0
No files found.
changelogs/unreleased/198391-add-user-plan-and-trial-status-to-api.yml
0 → 100644
View file @
0b9856d0
---
title
:
Expose `plan` and `trial` to `/users/:id` endpoint
merge_request
:
25151
author
:
type
:
added
doc/api/users.md
View file @
0b9856d0
...
@@ -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.
...
...
ee/lib/ee/api/entities.rb
View file @
0b9856d0
...
@@ -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
ee/spec/requests/api/users_spec.rb
View file @
0b9856d0
...
@@ -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
lib/api/entities/user_details_with_admin.rb
View file @
0b9856d0
...
@@ -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'
)
spec/requests/api/users_spec.rb
View file @
0b9856d0
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment