Commit 46f9ec8d authored by Enrique Alcántara's avatar Enrique Alcántara

Merge branch '351555-static-object-urls' into 'master'

Ensure static objects URL is correctly formatted for Download button

See merge request gitlab-org/gitlab!82168
parents fb0e0a16 ba100c1a
<script> <script>
import { GlButton, GlButtonGroup, GlTooltipDirective } from '@gitlab/ui'; import { GlButton, GlButtonGroup, GlTooltipDirective } from '@gitlab/ui';
import { sprintf, s__ } from '~/locale'; import { sprintf, s__ } from '~/locale';
import { setUrlParams, relativePathToAbsolute, getBaseURL } from '~/lib/utils/url_utility';
import { import {
BTN_COPY_CONTENTS_TITLE, BTN_COPY_CONTENTS_TITLE,
BTN_DOWNLOAD_TITLE, BTN_DOWNLOAD_TITLE,
...@@ -56,7 +57,7 @@ export default { ...@@ -56,7 +57,7 @@ export default {
}, },
computed: { computed: {
downloadUrl() { downloadUrl() {
return `${this.rawPath}?inline=false`; return setUrlParams({ inline: false }, relativePathToAbsolute(this.rawPath, getBaseURL()));
}, },
copyDisabled() { copyDisabled() {
return this.activeViewer === RICH_BLOB_VIEWER; return this.activeViewer === RICH_BLOB_VIEWER;
......
...@@ -1009,6 +1009,29 @@ RSpec.describe 'File blob', :js do ...@@ -1009,6 +1009,29 @@ RSpec.describe 'File blob', :js do
stub_application_setting(static_objects_external_storage_url: 'https://cdn.gitlab.com') stub_application_setting(static_objects_external_storage_url: 'https://cdn.gitlab.com')
end end
context 'private project' do
let_it_be(:project) { create(:project, :repository, :private) }
let_it_be(:user) { create(:user, static_object_token: 'ABCD1234') }
before do
project.add_developer(user)
sign_in(user)
visit_blob('README.md')
end
it 'shows open raw and download buttons with external storage URL prepended and user token appended to their href' do
path = project_raw_path(project, 'master/README.md')
raw_uri = "https://cdn.gitlab.com#{path}?token=#{user.static_object_token}"
download_uri = "https://cdn.gitlab.com#{path}?token=#{user.static_object_token}&inline=false"
aggregate_failures do
expect(page).to have_link 'Open raw', href: raw_uri
expect(page).to have_link 'Download', href: download_uri
end
end
end
context 'public project' do context 'public project' do
before do before do
visit_blob('README.md') visit_blob('README.md')
...@@ -1061,37 +1084,5 @@ RSpec.describe 'File blob', :js do ...@@ -1061,37 +1084,5 @@ RSpec.describe 'File blob', :js do
end end
end end
end end
context 'when static objects external storage is enabled' do
# We need to unsre that this test runs with the refactor_blob_viewer feature flag enabled
# This will be addressed in https://gitlab.com/gitlab-org/gitlab/-/issues/351555
before do
stub_application_setting(static_objects_external_storage_url: 'https://cdn.gitlab.com')
end
context 'private project' do
let_it_be(:project) { create(:project, :repository, :private) }
let_it_be(:user) { create(:user) }
before do
project.add_developer(user)
sign_in(user)
visit_blob('README.md')
end
it 'shows open raw and download buttons with external storage URL prepended and user token appended to their href' do
path = project_raw_path(project, 'master/README.md')
raw_uri = "https://cdn.gitlab.com#{path}?token=#{user.static_object_token}"
download_uri = "https://cdn.gitlab.com#{path}?inline=false&token=#{user.static_object_token}"
aggregate_failures do
expect(page).to have_link 'Open raw', href: raw_uri
expect(page).to have_link 'Download', href: download_uri
end
end
end
end
end end
end end
...@@ -27,7 +27,7 @@ exports[`Blob Header Default Actions rendering matches the snapshot 1`] = ` ...@@ -27,7 +27,7 @@ exports[`Blob Header Default Actions rendering matches the snapshot 1`] = `
<default-actions-stub <default-actions-stub
activeviewer="simple" activeviewer="simple"
rawpath="/flightjs/flight/snippets/51/raw" rawpath="https://testing.com/flightjs/flight/snippets/51/raw"
/> />
</div> </div>
</div> </div>
......
...@@ -22,7 +22,7 @@ export const Blob = { ...@@ -22,7 +22,7 @@ export const Blob = {
binary: false, binary: false,
name: 'dummy.md', name: 'dummy.md',
path: 'foo/bar/dummy.md', path: 'foo/bar/dummy.md',
rawPath: '/flightjs/flight/snippets/51/raw', rawPath: 'https://testing.com/flightjs/flight/snippets/51/raw',
size: 75, size: 75,
simpleViewer: { simpleViewer: {
...SimpleViewerMock, ...SimpleViewerMock,
......
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