Commit 90ee3199 authored by Felipe Artur's avatar Felipe Artur

Expose web_url for epics on API

Expose web_url field on API to be consistent with other API responses.
parent 11472efd
---
title: Expose web_url for epics on API
merge_request:
author:
type: changed
......@@ -67,7 +67,7 @@ Example response:
"title": "Accusamus iste et ullam ratione voluptatem omnis debitis dolor est.",
"description": "Molestias dolorem eos vitae expedita impedit necessitatibus quo voluptatum.",
"state": "opened",
"web_edit_url": "http://localhost:3001/groups/test/-/epics/4",
"web_url": "http://localhost:3001/groups/test/-/epics/4",
"reference": "&4",
"author": {
"id": 10,
......@@ -122,7 +122,7 @@ Example response:
"title": "Ea cupiditate dolores ut vero consequatur quasi veniam voluptatem et non.",
"description": "Molestias dolorem eos vitae expedita impedit necessitatibus quo voluptatum.",
"state": "opened",
"web_edit_url": "http://localhost:3001/groups/test/-/epics/5",
"web_url": "http://localhost:3001/groups/test/-/epics/5",
"reference": "&5",
"author":{
"id": 7,
......@@ -188,7 +188,7 @@ Example response:
"title": "Epic",
"description": "Epic description",
"state": "opened",
"web_edit_url": "http://localhost:3001/groups/test/-/epics/6",
"web_url": "http://localhost:3001/groups/test/-/epics/5",
"reference": "&6",
"author": {
"name" : "Alexandra Bashirian",
......@@ -255,7 +255,7 @@ Example response:
"title": "New Title",
"description": "Epic description",
"state": "opened",
"web_edit_url": "http://localhost:3001/groups/test/-/epics/6",
"web_url": "http://localhost:3001/groups/test/-/epics/5",
"reference": "&6",
"author": {
"name" : "Alexandra Bashirian",
......
......@@ -77,7 +77,7 @@ module EE
reorder('relative_position ASC', 'id DESC')
end
scope :with_api_entity_associations, -> { preload(:author, :labels, :group) }
scope :with_api_entity_associations, -> { preload(:author, :labels, group: :route) }
MAX_HIERARCHY_DEPTH = 5
......
......@@ -241,6 +241,8 @@ module EE
class Epic < Grape::Entity
can_admin_epic = ->(epic, opts) { Ability.allowed?(opts[:user], :admin_epic, epic) }
epic_url = ->(epic) { ::Gitlab::Routing.url_helpers.group_epic_path(epic.group, epic) }
expose :id
expose :iid
expose :group_id
......@@ -257,7 +259,12 @@ module EE
expose :due_date_fixed, :due_date_from_milestones, if: can_admin_epic
expose :state
expose :web_edit_url, if: can_admin_epic do |epic|
::Gitlab::Routing.url_helpers.group_epic_path(epic.group, epic)
epic_url.call(epic)
end
# web_edit_url is already exposed and has the same value of web_url
# this field has been added again with other name to be consistent with other API responses
expose :web_url do |epic|
epic_url.call(epic)
end
expose :reference, if: { with_reference: true } do |epic|
epic.to_reference(full: true)
......
......@@ -40,6 +40,7 @@
"created_at": { "type": ["string", "null"] },
"updated_at": { "type": ["string", "null"] },
"web_edit_url": { "type": "string" },
"web_url": { "type": "string" },
"reference": { "type": "string" }
},
"required": [
......
......@@ -63,6 +63,7 @@ describe API::Epics do
describe 'GET /groups/:id/epics' do
let(:url) { "/groups/#{group.path}/epics" }
let(:params) { { include_descendant_groups: true } }
it_behaves_like 'error requests'
......@@ -70,7 +71,7 @@ describe API::Epics do
before do
stub_licensed_features(epics: true)
get api(url, user)
get api(url, user), params: params
end
it 'returns 200 status' do
......@@ -85,15 +86,19 @@ describe API::Epics do
epic
# Avoid polluting queries with inserts for personal access token
pat = create(:personal_access_token, user: user)
subgroup_1 = create(:group, parent: group)
subgroup_2 = create(:group, parent: subgroup_1)
create(:epic, group: subgroup_1)
create(:epic, group: subgroup_2)
control = ActiveRecord::QueryRecorder.new(skip_cached: false) do
get api(url, personal_access_token: pat)
end
get api(url, personal_access_token: pat), params: params
end.count
label_2 = create(:label)
create_list(:labeled_epic, 2, group: group, labels: [label_2])
expect { get api(url, personal_access_token: pat) }.not_to exceed_all_query_limit(control)
expect { get api(url, personal_access_token: pat), params: params }.not_to exceed_all_query_limit(control)
expect(response).to have_gitlab_http_status(200)
end
end
......
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