Fix issues api return only relative URLs for uploaded files in description
Summary
Currently if a file is attached to an issue, it is correctly rendered on GitLab itself. But while connecting to the GitLab API (https://docs.gitlab.com/ee/api/issues.html#single-issue) the description returns only the relative URL, resulting in incorrect handling of issues in Clients using the API.
The clients connecting to the GitLab API sure would be able to somehow rebuild the absolute URL but I would expect an API to return content without the need of business logic.
Steps to reproduce
Take a look at gitlab-org/gitter/webapp#2017.
also
GET https://gitlab.com/api/v4/projects/gitlab-org/gitter/webapp/issues/2017
- find relative URLs in the response description
Example Project
Global API, so no specific Project. But I discovered this in the >gitlab-org/gitter/webapp repo.
What is the current bug behavior?
Only relative URLs of uploads in description is returned via the API.
What is the expected correct behavior?
Return absolute URL via the API.
Relevant logs and/or screenshots
GET https://gitlab.com/api/v4/projects/gitlab-org/gitter/webapp/issues/2017
{
"id": 16127988,
"iid": 2017,
"project_id": 3601513,
"title": "Incomplete img src inside activity popover markdown content",
"description": "### Summary\r\n\r\nActivity element in gitter community doesn't display images from issues created on GitLab. I haven't checked on issues created on GitHub, probably the same outcome. Actually as `src` only `http://uploads/19d8c607418f3df7559045e14f738cad/Bildschirmfoto_2018-11-24_um_13.22.50.png` gets inserted for issue https://gitlab.com/gitlab-org/gitter/webapp/issues/2014 which correctly is not pointing anywhere correct.\r\n\r\n### Steps to reproduce\r\n\r\n1. connect https://gitter.im/gitterHQ/gitter\r\n2. check the activity element on the right sidebar from 26.11.2018 17:28 \r\nwhich should be the close event of above-mentioned issue\r\n3. hover over the link to open the issue popover\r\n4. don't see the expected images inside the table\r\n\r\n### What is the current *bug* behavior?\r\n\r\nLinks should contain the correct uri - instead of `http://uploads/19d8c607418f3df7559045e14f738cad/Bildschirmfoto_2018-11-24_um_13.22.50.png` there should be `http://gitlab.com/gitlab-org/gitter/webapp/uploads/19d8c607418f3df7559045e14f738cad/Bildschirmfoto_2018-11-24_um_13.22.50.png` which returns a 301 Moved Permanently to `https`.\r\n\r\n### Relevant logs and/or screenshots\r\n\r\n| issue popover | original issue |\r\n| ------ | ------ |\r\n|![Bildschirmfoto_2018-11-26_um_20.13.51](/uploads/83ccb1060b436c30a8da1d58c97f1e75/Bildschirmfoto_2018-11-26_um_20.13.51.png)|![Bildschirmfoto_2018-11-26_um_20.14.51](/uploads/e8726b19be8c559b230cfa54b5c267b3/Bildschirmfoto_2018-11-26_um_20.14.51.png)|\r\n\r\n\r\n### Possible fixes\r\n\r\nProbably https://gitlab.com/gitlab-org/gitter/webapp/blob/6ca139e25585dda0219fdf7d8ecff6046e358b69/public/js/views/chat/decorators/issuableDecorator.js#L73\r\n\r\nI haven't checked the API yet, probably `/issue-mirror` returns data with incomplete `img src`.",
"state": "opened",
"created_at": "2018-11-26T21:06:19.791Z",
"updated_at": "2018-11-29T21:16:35.509Z",
"closed_at": null,
"closed_by": null,
"labels": [
"Accepting merge requests",
"bug",
"integrations-and-activity"
],
"milestone": null,
"assignees": [],
"author": {
"id": 240836,
"name": "Marc Schwede",
"username": "schwedenmut",
"state": "active",
"avatar_url": "https://assets.gitlab-static.net/uploads/-/system/user/avatar/240836/avatar.png",
"web_url": "https://gitlab.com/schwedenmut"
},
"assignee": null,
"user_notes_count": 1,
"upvotes": 0,
"downvotes": 0,
"due_date": null,
"confidential": false,
"discussion_locked": null,
"web_url": "https://gitlab.com/gitlab-org/gitter/webapp/issues/2017",
"time_stats": {
"time_estimate": 0,
"total_time_spent": 0,
"human_time_estimate": null,
"human_total_time_spent": null
},
"_links": {
"self": "https://gitlab.com/api/v4/projects/3601513/issues/2017",
"notes": "https://gitlab.com/api/v4/projects/3601513/issues/2017/notes",
"award_emoji": "https://gitlab.com/api/v4/projects/3601513/issues/2017/award_emoji",
"project": "https://gitlab.com/api/v4/projects/3601513"
},
"subscribed": true,
"weight": null
}
issue popover | original issue |
---|---|
Output of checks
This bug happens on GitLab.com Also on my local CE 11.5.1 (gitlab-ce@c90ae59a8becf9d31ff7f67fe13c671ba683bb27).
Possible fixes
https://gitlab.com/gitlab-org/gitlab-ce/blob/master/lib/api/issues.rb#L157-166
https://gitlab.com/gitlab-org/gitlab-ce/blob/master/lib/api/entities.rb#L459 (:description)