Commit a5cee529 authored by Paul Slaughter's avatar Paul Slaughter

Merge branch 'nfriend-fix-guest-user-releases' into 'master'

Fix the Releases page for Guest Users

Closes #34862

See merge request gitlab-org/gitlab!28447
parents cf94bb52 53a679f7
...@@ -103,7 +103,7 @@ export default { ...@@ -103,7 +103,7 @@ export default {
<div v-else-if="shouldRenderSuccessState" class="js-success-state"> <div v-else-if="shouldRenderSuccessState" class="js-success-state">
<release-block <release-block
v-for="(release, index) in releases" v-for="(release, index) in releases"
:key="release.tagName" :key="index"
:release="release" :release="release"
:class="{ 'linked-card': releases.length > 1 && index !== releases.length - 1 }" :class="{ 'linked-card': releases.length > 1 && index !== releases.length - 1 }"
/> />
......
...@@ -37,7 +37,11 @@ export default { ...@@ -37,7 +37,11 @@ export default {
}; };
}, },
computed: { computed: {
id() { htmlId() {
if (!this.release.tagName) {
return null;
}
return slugify(this.release.tagName); return slugify(this.release.tagName);
}, },
assets() { assets() {
...@@ -72,7 +76,7 @@ export default { ...@@ -72,7 +76,7 @@ export default {
this.renderGFM(); this.renderGFM();
const hash = getLocationHash(); const hash = getLocationHash();
if (hash && slugify(hash) === this.id) { if (hash && slugify(hash) === this.htmlId) {
this.isHighlighted = true; this.isHighlighted = true;
setTimeout(() => { setTimeout(() => {
this.isHighlighted = false; this.isHighlighted = false;
...@@ -89,7 +93,7 @@ export default { ...@@ -89,7 +93,7 @@ export default {
}; };
</script> </script>
<template> <template>
<div :id="id" :class="{ 'bg-line-target-blue': isHighlighted }" class="card release-block"> <div :id="htmlId" :class="{ 'bg-line-target-blue': isHighlighted }" class="card release-block">
<release-block-header :release="release" /> <release-block-header :release="release" />
<div class="card-body"> <div class="card-body">
<div v-if="shouldRenderMilestoneInfo"> <div v-if="shouldRenderMilestoneInfo">
......
---
title: Fix Releases page for Guest users of private projects
merge_request: 28447
author:
type: fixed
...@@ -3,41 +3,33 @@ ...@@ -3,41 +3,33 @@
require 'spec_helper' require 'spec_helper'
describe 'User views releases', :js do describe 'User views releases', :js do
let!(:project) { create(:project, :repository) } let_it_be(:project) { create(:project, :repository, :private) }
let!(:release) { create(:release, project: project ) } let_it_be(:release) { create(:release, project: project, name: 'The first release' ) }
let!(:user) { create(:user) } let_it_be(:maintainer) { create(:user) }
let_it_be(:guest) { create(:user) }
before do before do
project.add_maintainer(user) project.add_maintainer(maintainer)
project.add_guest(guest)
gitlab_sign_in(user)
end end
it 'sees the release' do context('when the user is a maintainer') do
visit project_releases_path(project) before do
gitlab_sign_in(maintainer)
expect(page).to have_content(release.name) end
expect(page).to have_content(release.tag)
expect(page).not_to have_content('Upcoming Release')
end
context 'when there is a link as an asset' do
let!(:release_link) { create(:release_link, release: release, url: url ) }
let(:url) { "#{project.web_url}/-/jobs/1/artifacts/download" }
let(:direct_asset_link) { Gitlab::Routing.url_helpers.project_release_url(project, release) << release_link.filepath }
it 'sees the link' do it 'sees the release' do
visit project_releases_path(project) visit project_releases_path(project)
page.within('.js-assets-list') do expect(page).to have_content(release.name)
expect(page).to have_link release_link.name, href: direct_asset_link expect(page).to have_content(release.tag)
expect(page).not_to have_content('(external source)') expect(page).not_to have_content('Upcoming Release')
end
end end
context 'when there is a link redirect' do context 'when there is a link as an asset' do
let!(:release_link) { create(:release_link, release: release, name: 'linux-amd64 binaries', filepath: '/binaries/linux-amd64', url: url) } let!(:release_link) { create(:release_link, release: release, url: url ) }
let(:url) { "#{project.web_url}/-/jobs/1/artifacts/download" } let(:url) { "#{project.web_url}/-/jobs/1/artifacts/download" }
let(:direct_asset_link) { Gitlab::Routing.url_helpers.project_release_url(project, release) << release_link.filepath }
it 'sees the link' do it 'sees the link' do
visit project_releases_path(project) visit project_releases_path(project)
...@@ -47,39 +39,73 @@ describe 'User views releases', :js do ...@@ -47,39 +39,73 @@ describe 'User views releases', :js do
expect(page).not_to have_content('(external source)') expect(page).not_to have_content('(external source)')
end end
end end
end
context 'when url points to external resource' do context 'when there is a link redirect' do
let(:url) { 'http://google.com/download' } let!(:release_link) { create(:release_link, release: release, name: 'linux-amd64 binaries', filepath: '/binaries/linux-amd64', url: url) }
let(:url) { "#{project.web_url}/-/jobs/1/artifacts/download" }
it 'sees that the link is external resource' do it 'sees the link' do
visit project_releases_path(project) visit project_releases_path(project)
page.within('.js-assets-list') do page.within('.js-assets-list') do
expect(page).to have_content('(external source)') expect(page).to have_link release_link.name, href: direct_asset_link
expect(page).not_to have_content('(external source)')
end
end
end
context 'when url points to external resource' do
let(:url) { 'http://google.com/download' }
it 'sees that the link is external resource' do
visit project_releases_path(project)
page.within('.js-assets-list') do
expect(page).to have_content('(external source)')
end
end end
end end
end end
end
context 'with an upcoming release' do context 'with an upcoming release' do
let(:tomorrow) { Time.zone.now + 1.day } let(:tomorrow) { Time.zone.now + 1.day }
let!(:release) { create(:release, project: project, released_at: tomorrow ) } let!(:release) { create(:release, project: project, released_at: tomorrow ) }
it 'sees the upcoming tag' do it 'sees the upcoming tag' do
visit project_releases_path(project) visit project_releases_path(project)
expect(page).to have_content('Upcoming Release')
end
end
context 'with a tag containing a slash' do
it 'sees the release' do
release = create :release, :with_evidence, project: project, tag: 'debian/2.4.0-1'
visit project_releases_path(project)
expect(page).to have_content('Upcoming Release') expect(page).to have_content(release.name)
expect(page).to have_content(release.tag)
end
end end
end end
context 'with a tag containing a slash' do context('when the user is a guest') do
it 'sees the release' do before do
release = create :release, :with_evidence, project: project, tag: 'debian/2.4.0-1' gitlab_sign_in(guest)
end
it 'renders release info except for Git-related data' do
visit project_releases_path(project) visit project_releases_path(project)
expect(page).to have_content(release.name) within('.release-block') do
expect(page).to have_content(release.tag) expect(page).to have_content(release.description)
# The following properties (sometimes) include Git info,
# so they are not rendered for Guest users
expect(page).not_to have_content(release.name)
expect(page).not_to have_content(release.tag)
expect(page).not_to have_content(release.commit.short_id)
end
end end
end end
end end
...@@ -165,6 +165,14 @@ describe('Release block', () => { ...@@ -165,6 +165,14 @@ describe('Release block', () => {
}); });
}); });
it('does not set the ID if tagName is missing', () => {
release.tagName = undefined;
return factory(release).then(() => {
expect(wrapper.attributes().id).toBeUndefined();
});
});
describe('evidence block', () => { describe('evidence block', () => {
it('renders the evidence block when the evidence is available and the feature flag is true', () => it('renders the evidence block when the evidence is available and the feature flag is true', () =>
factory(release, { releaseEvidenceCollection: true }).then(() => factory(release, { releaseEvidenceCollection: true }).then(() =>
......
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