Commit 5c463a05 authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera

Merge branch 'nfriend-fix-assets-for-guest-users' into 'master'

Fix Release assets for Guest users of private projects

Closes #223926

See merge request gitlab-org/gitlab!35166
parents e90fbc2b e77700a1
......@@ -4,7 +4,7 @@ import Icon from '~/vue_shared/components/icon.vue';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { ASSET_LINK_TYPE } from '../constants';
import { __, s__, sprintf } from '~/locale';
import { difference } from 'lodash';
import { difference, get } from 'lodash';
export default {
name: 'ReleaseBlockAssets',
......@@ -54,7 +54,7 @@ export default {
sections() {
return [
{
links: this.assets.sources.map(s => ({
links: get(this.assets, 'sources', []).map(s => ({
url: s.url,
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';
import { ASSET_LINK_TYPE } from '~/releases/constants';
import { trimText } from 'helpers/text_helper';
import { assets } from '../mock_data';
import { cloneDeep } from 'lodash';
describe('Release block assets', () => {
let wrapper;
......@@ -30,7 +31,7 @@ describe('Release block assets', () => {
wrapper.findAll('h5').filter(h5 => h5.text() === sections[type]);
beforeEach(() => {
defaultProps = { assets };
defaultProps = { assets: cloneDeep(assets) };
});
describe('with default props', () => {
......@@ -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', () => {
const containsExternalSourceIndicator = () =>
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