summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2017-07-12 11:36:10 +0000
committerClement Ho <ClemMakesApps@gmail.com>2017-07-12 10:41:12 -0500
commit9355d91c5bec7d2e97bf20d91398d692acce2bcf (patch)
treeef960617ae0a650c71332ff11e2fa7f4fde3bbb0
parent462ef2d83840195ea77c1c41abec6e2bfbe0fa02 (diff)
downloadgitlab-ce-9-3-stable-patch-7.tar.gz
Merge branch '34325-reinstate-is_admin-for-user-api' into 'master'9-3-stable-patch-7
Return `is_admin` attribute in the GET /user endpoint for admins Closes #34325 See merge request !12811
-rw-r--r--changelogs/unreleased/34325-reinstate-is_admin-for-user-api.yml4
-rw-r--r--doc/api/users.md2
-rw-r--r--lib/api/users.rb11
-rw-r--r--spec/fixtures/api/schemas/public_api/v4/user/admin.json34
-rw-r--r--spec/requests/api/users_spec.rb8
5 files changed, 53 insertions, 6 deletions
diff --git a/changelogs/unreleased/34325-reinstate-is_admin-for-user-api.yml b/changelogs/unreleased/34325-reinstate-is_admin-for-user-api.yml
new file mode 100644
index 00000000000..3bed1fbe16e
--- /dev/null
+++ b/changelogs/unreleased/34325-reinstate-is_admin-for-user-api.yml
@@ -0,0 +1,4 @@
+---
+title: Return `is_admin` attribute in the GET /user endpoint for admins
+merge_request: 12811
+author:
diff --git a/doc/api/users.md b/doc/api/users.md
index 43d53756e44..6a8ca8fe564 100644
--- a/doc/api/users.md
+++ b/doc/api/users.md
@@ -356,7 +356,7 @@ GET /user
Parameters:
-- `sudo` (required) - the ID of a user
+- `sudo` (optional) - the ID of a user to make the call in their place
```
GET /user
diff --git a/lib/api/users.rb b/lib/api/users.rb
index db1f0ff392b..861d92e5b21 100644
--- a/lib/api/users.rb
+++ b/lib/api/users.rb
@@ -402,7 +402,16 @@ module API
success Entities::UserPublic
end
get do
- present current_user, with: sudo? ? Entities::UserWithPrivateDetails : Entities::UserPublic
+ entity =
+ if sudo?
+ Entities::UserWithPrivateDetails
+ elsif current_user.admin?
+ Entities::UserWithAdmin
+ else
+ Entities::UserPublic
+ end
+
+ present current_user, with: entity
end
desc "Get the currently authenticated user's SSH keys" do
diff --git a/spec/fixtures/api/schemas/public_api/v4/user/admin.json b/spec/fixtures/api/schemas/public_api/v4/user/admin.json
new file mode 100644
index 00000000000..f733914fbf8
--- /dev/null
+++ b/spec/fixtures/api/schemas/public_api/v4/user/admin.json
@@ -0,0 +1,34 @@
+{
+ "type": "object",
+ "required": [
+ "id",
+ "username",
+ "email",
+ "name",
+ "state",
+ "avatar_url",
+ "web_url",
+ "created_at",
+ "is_admin",
+ "bio",
+ "location",
+ "skype",
+ "linkedin",
+ "twitter",
+ "website_url",
+ "organization",
+ "last_sign_in_at",
+ "confirmed_at",
+ "color_scheme_id",
+ "projects_limit",
+ "current_sign_in_at",
+ "identities",
+ "can_create_group",
+ "can_create_project",
+ "two_factor_enabled",
+ "external"
+ ],
+ "properties": {
+ "$ref": "full.json"
+ }
+}
diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb
index 46f3d78e4e5..da2541fa979 100644
--- a/spec/requests/api/users_spec.rb
+++ b/spec/requests/api/users_spec.rb
@@ -821,11 +821,11 @@ describe API::Users do
expect(response).to have_http_status(403)
end
- it 'returns initial current user without private token when sudo not defined' do
+ it 'returns initial current user without private token but with is_admin when sudo not defined' do
get api("/user?private_token=#{admin_personal_access_token}")
expect(response).to have_http_status(200)
- expect(response).to match_response_schema('public_api/v4/user/public')
+ expect(response).to match_response_schema('public_api/v4/user/admin')
expect(json_response['id']).to eq(admin.id)
end
end
@@ -839,11 +839,11 @@ describe API::Users do
expect(json_response['id']).to eq(user.id)
end
- it 'returns initial current user without private token when sudo not defined' do
+ it 'returns initial current user without private token but with is_admin when sudo not defined' do
get api("/user?private_token=#{admin.private_token}")
expect(response).to have_http_status(200)
- expect(response).to match_response_schema('public_api/v4/user/public')
+ expect(response).to match_response_schema('public_api/v4/user/admin')
expect(json_response['id']).to eq(admin.id)
end
end