Commit 40a64461 authored by Felipe Artur's avatar Felipe Artur Committed by Jan Provaznik

Expose subscribed attribute for epics on API

Expose if user is subscribed to an epic when getting a
single epic from API.
parent 2c2aec77
---
title: Expose subscribed attribute for epic on API
merge_request: 18475
author:
type: added
...@@ -147,7 +147,8 @@ Example response: ...@@ -147,7 +147,8 @@ Example response:
"closed_at": "2018-08-18T12:22:05.239Z", "closed_at": "2018-08-18T12:22:05.239Z",
"labels": [], "labels": [],
"upvotes": 4, "upvotes": 4,
"downvotes": 0 "downvotes": 0,
"subscribed": true
} }
``` ```
......
...@@ -54,7 +54,9 @@ module API ...@@ -54,7 +54,9 @@ module API
get ':id/(-/)epics/:epic_iid' do get ':id/(-/)epics/:epic_iid' do
authorize_can_read! authorize_can_read!
present epic, with: EE::API::Entities::Epic, user: current_user present epic, options, user: current_user,
with: EE::API::Entities::Epic,
include_subscribed: true
end end
desc 'Create a new epic' do desc 'Create a new epic' do
......
...@@ -323,6 +323,15 @@ module EE ...@@ -323,6 +323,15 @@ module EE
end end
end end
# Calculating the value of subscribed field triggers Markdown
# processing. We can't do that for multiple epics
# requests in a single API request.
expose :subscribed, if: -> (_, options) { options.fetch(:include_subscribed, false) } do |epic, options|
user = options[:user]
user.present? ? epic.subscribed?(user) : false
end
def web_url def web_url
::Gitlab::Routing.url_helpers.group_epic_url(object.group, object) ::Gitlab::Routing.url_helpers.group_epic_url(object.group, object)
end end
......
...@@ -42,7 +42,8 @@ ...@@ -42,7 +42,8 @@
"closed_at": { "type": ["string", "null"] }, "closed_at": { "type": ["string", "null"] },
"web_edit_url": { "type": "string" }, "web_edit_url": { "type": "string" },
"web_url": { "type": "string" }, "web_url": { "type": "string" },
"reference": { "type": "string" } "reference": { "type": "string" },
"subscribed": { "type": ["boolean", "null"] }
}, },
"required": [ "required": [
"id", "iid", "group_id", "title" "id", "iid", "group_id", "title"
......
...@@ -422,6 +422,12 @@ describe API::Epics do ...@@ -422,6 +422,12 @@ describe API::Epics do
expect(response).to match_response_schema('public_api/v4/epic', dir: 'ee') expect(response).to match_response_schema('public_api/v4/epic', dir: 'ee')
end end
it 'exposes subscribed field' do
get api(url, epic.author)
expect(json_response['subscribed']).to eq(true)
end
it 'exposes closed_at attribute' do it 'exposes closed_at attribute' do
epic.close epic.close
......
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