Commit c535cf15 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'fix-10752-jira-dvcs-import-shows-v3-api-request-errors' into 'master'

Add endpoint for Jira to request user information

Closes #10752

See merge request gitlab-org/gitlab-ee!10482
parents 3c6b8f8d df85905f
---
title: Add missing endpoint for user information to GitHub API
merge_request: 10482
author:
type: fixed
......@@ -115,8 +115,14 @@ module API
class User < Grape::Entity
expose :id
expose :username, as: :login
expose :url do |user|
Gitlab::Routing.url_helpers.user_url(user)
expose :user_url, as: :url
expose :user_url, as: :html_url
expose :avatar_url
private
def user_url
Gitlab::Routing.url_helpers.user_url(object)
end
end
......
......@@ -118,6 +118,13 @@ module API
present paginate(projects), with: ::API::Github::Entities::Repository
end
get ':username' do
forbidden! unless can?(current_user, :read_users_list)
user = UsersFinder.new(current_user, { username: params[:username] }).execute.first
not_found! unless user
present user, with: ::API::Github::Entities::User
end
end
# Jira dev panel integration weirdly requests for "/-/jira/pulls" instead
......
......@@ -44,44 +44,10 @@
"type": "date"
},
"assignee": {
"type": "object",
"required": [
"id",
"login",
"url"
],
"properties": {
"id": {
"type": "integer"
},
"login": {
"type": "string"
},
"url": {
"type": "string"
}
},
"additionalProperties": false
"$ref": "user.json"
},
"author": {
"type": "object",
"required": [
"id",
"login",
"url"
],
"properties": {
"id": {
"type": "integer"
},
"login": {
"type": "string"
},
"url": {
"type": "string"
}
},
"additionalProperties": false
"$ref": "user.json"
},
"head": {
"type": "object",
......
{
"type": "array",
"items": {
"type": "object",
"properties" : {
"title": { "type": "string" },
"created_at": { "type": "string" },
"body": { "type": ["string", "null"] },
"id": { "type": "integer" },
"number": { "type": "integer" },
"state": { "type": "string" },
"html_url": { "type": "string" },
"merged": { "type": "boolean" },
"merged_at": { "type": ["date", "null"] },
"closed_at": { "type": ["date", "null"] },
"updated_at": { "type": "date" },
"assignee": {
"type": "object",
"required": ["id", "login", "url"],
"properties" : {
"id": { "type": "integer" },
"login": { "type": "string" },
"url": { "type": "string" }
},
"additionalProperties": false
},
"author": {
"type": "object",
"required": ["id", "login", "url"],
"properties" : {
"id": { "type": "integer" },
"login": { "type": "string" },
"url": { "type": "string" }
},
"additionalProperties": false
},
"head": {
"type": "object",
"required": ["label", "ref", "repo"],
"properties" : {
"label": { "type": "string" },
"ref": { "type": "string" },
"repo": {
"oneOf": [
{ "type": "null" },
{ "$ref": "repository.json" }
]
}
},
"additionalProperties": false
},
"base": {
"type": "object",
"required": ["label", "ref", "repo"],
"properties" : {
"label": { "type": "string" },
"ref": { "type": "string" },
"repo": {
"oneOf": [
{ "type": "null" },
{ "$ref": "repository.json" }
]
}
},
"additionalProperties": false
},
"additionalProperties": false
}
"$ref": "pull_request.json"
}
}
{
"type": "object",
"required": ["id", "login", "url", "avatar_url"],
"properties" : {
"id": { "type": "integer" },
"login": { "type": "string" },
"url": { "type": "string" },
"avatar_url": { "type": "string" },
"html_url": { "type": "string" }
},
"additionalProperties": false
}
......@@ -121,6 +121,46 @@ describe API::V3::Github do
let(:path) { "#{project.namespace.path}/#{project.path}" }
end
describe 'GET /users/:username' do
let!(:user1) { create(:user, username: 'jane') }
before do
stub_licensed_features(jira_dev_panel_integration: true)
end
context 'user exists' do
it 'responds with the expected user' do
jira_get v3_api('/users/jane', user)
expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('entities/github/user', dir: 'ee')
end
end
context 'user does not exist' do
it 'responds with the expected status' do
jira_get v3_api('/users/unknown_user_name', user)
expect(response).to have_gitlab_http_status(404)
end
end
context 'no rights to request user lists' do
let(:unauthorized_user) { create(:user) }
before do
expect(Ability).to receive(:allowed?).with(unauthorized_user, :read_users_list, :global).and_return(false)
expect(Ability).to receive(:allowed?).at_least(:once).and_call_original
end
it 'responds with forbidden' do
jira_get v3_api('/users/jane', unauthorized_user)
expect(response).to have_gitlab_http_status(403)
end
end
end
describe 'GET events' do
let(:group) { create(:group) }
let(:project) { create(:project, :empty_repo, group: group) }
......
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