Commit e77700a1 authored by Nathan Friend's avatar Nathan Friend Committed by Nicolò Maria Mezzopera

Fix release assets for Guests of private projects

This commit fixes a bug that prevented the release assets from rendering
for Guest users of private projects on the Releases page.
parent 358d35e0
...@@ -4,7 +4,7 @@ import Icon from '~/vue_shared/components/icon.vue'; ...@@ -4,7 +4,7 @@ import Icon from '~/vue_shared/components/icon.vue';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { ASSET_LINK_TYPE } from '../constants'; import { ASSET_LINK_TYPE } from '../constants';
import { __, s__, sprintf } from '~/locale'; import { __, s__, sprintf } from '~/locale';
import { difference } from 'lodash'; import { difference, get } from 'lodash';
export default { export default {
name: 'ReleaseBlockAssets', name: 'ReleaseBlockAssets',
...@@ -54,7 +54,7 @@ export default { ...@@ -54,7 +54,7 @@ export default {
sections() { sections() {
return [ return [
{ {
links: this.assets.sources.map(s => ({ links: get(this.assets, 'sources', []).map(s => ({
url: s.url, url: s.url,
name: sprintf(__('Source code (%{fileExtension})'), { fileExtension: s.format }), name: sprintf(__('Source code (%{fileExtension})'), { fileExtension: s.format }),
})), })),
......
---
title: Fix release assets for Guest users of private projects
merge_request: 35166
author:
type: fixed
...@@ -4,6 +4,7 @@ import ReleaseBlockAssets from '~/releases/components/release_block_assets.vue'; ...@@ -4,6 +4,7 @@ import ReleaseBlockAssets from '~/releases/components/release_block_assets.vue';
import { ASSET_LINK_TYPE } from '~/releases/constants'; import { ASSET_LINK_TYPE } from '~/releases/constants';
import { trimText } from 'helpers/text_helper'; import { trimText } from 'helpers/text_helper';
import { assets } from '../mock_data'; import { assets } from '../mock_data';
import { cloneDeep } from 'lodash';
describe('Release block assets', () => { describe('Release block assets', () => {
let wrapper; let wrapper;
...@@ -30,7 +31,7 @@ describe('Release block assets', () => { ...@@ -30,7 +31,7 @@ describe('Release block assets', () => {
wrapper.findAll('h5').filter(h5 => h5.text() === sections[type]); wrapper.findAll('h5').filter(h5 => h5.text() === sections[type]);
beforeEach(() => { beforeEach(() => {
defaultProps = { assets }; defaultProps = { assets: cloneDeep(assets) };
}); });
describe('with default props', () => { describe('with default props', () => {
...@@ -96,6 +97,35 @@ describe('Release block assets', () => { ...@@ -96,6 +97,35 @@ describe('Release block assets', () => {
}); });
}); });
describe('sources', () => {
const testSources = ({ shouldSourcesBeRendered }) => {
assets.sources.forEach(s => {
expect(wrapper.find(`a[href="${s.url}"]`).exists()).toBe(shouldSourcesBeRendered);
});
};
describe('when the release has sources', () => {
beforeEach(() => {
createComponent(defaultProps);
});
it('renders sources', () => {
testSources({ shouldSourcesBeRendered: true });
});
});
describe('when the release does not have sources', () => {
beforeEach(() => {
delete defaultProps.assets.sources;
createComponent(defaultProps);
});
it('does not render any sources', () => {
testSources({ shouldSourcesBeRendered: false });
});
});
});
describe('external vs internal links', () => { describe('external vs internal links', () => {
const containsExternalSourceIndicator = () => const containsExternalSourceIndicator = () =>
wrapper.contains('[data-testid="external-link-indicator"]'); wrapper.contains('[data-testid="external-link-indicator"]');
......
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