Commit b480a089 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch 'issue_11240' into 'master'

Expose subscribed attribute for epics on API

See merge request gitlab-org/gitlab!18475
parents 2c2aec77 40a64461
---
title: Expose subscribed attribute for epic on API
merge_request: 18475
author:
type: added
......@@ -147,7 +147,8 @@ Example response:
"closed_at": "2018-08-18T12:22:05.239Z",
"labels": [],
"upvotes": 4,
"downvotes": 0
"downvotes": 0,
"subscribed": true
}
```
......
......@@ -54,7 +54,9 @@ module API
get ':id/(-/)epics/:epic_iid' do
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
desc 'Create a new epic' do
......
......@@ -323,6 +323,15 @@ module EE
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
::Gitlab::Routing.url_helpers.group_epic_url(object.group, object)
end
......
......@@ -42,7 +42,8 @@
"closed_at": { "type": ["string", "null"] },
"web_edit_url": { "type": "string" },
"web_url": { "type": "string" },
"reference": { "type": "string" }
"reference": { "type": "string" },
"subscribed": { "type": ["boolean", "null"] }
},
"required": [
"id", "iid", "group_id", "title"
......
......@@ -422,6 +422,12 @@ describe API::Epics do
expect(response).to match_response_schema('public_api/v4/epic', dir: 'ee')
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
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