Commit baeeb272 authored by Etienne Baqué's avatar Etienne Baqué

Added restriction for guest on Release page

Added restriction for evidence in Release API.
Added restriction in Release controller.
Added relevant tests.
parent 3cb5e9e0
...@@ -10,6 +10,7 @@ class Projects::ReleasesController < Projects::ApplicationController ...@@ -10,6 +10,7 @@ class Projects::ReleasesController < Projects::ApplicationController
push_frontend_feature_flag(:release_evidence_collection, project) push_frontend_feature_flag(:release_evidence_collection, project)
end end
before_action :authorize_update_release!, only: %i[edit update] before_action :authorize_update_release!, only: %i[edit update]
before_action :authorize_download_code!, only: [:evidence]
def index def index
respond_to do |format| respond_to do |format|
......
...@@ -1319,7 +1319,7 @@ module API ...@@ -1319,7 +1319,7 @@ module API
expose :milestones, using: Entities::Milestone, if: -> (release, _) { release.milestones.present? } expose :milestones, using: Entities::Milestone, if: -> (release, _) { release.milestones.present? }
expose :commit_path, expose_nil: false expose :commit_path, expose_nil: false
expose :tag_path, expose_nil: false expose :tag_path, expose_nil: false
expose :evidence_sha, expose_nil: false expose :evidence_sha, expose_nil: false, if: ->(_, _) { can_download_code? }
expose :assets do expose :assets do
expose :assets_count, as: :count do |release, _| expose :assets_count, as: :count do |release, _|
assets_to_exclude = can_download_code? ? [] : [:sources] assets_to_exclude = can_download_code? ? [] : [:sources]
...@@ -1329,7 +1329,7 @@ module API ...@@ -1329,7 +1329,7 @@ module API
expose :links, using: Entities::Releases::Link do |release, options| expose :links, using: Entities::Releases::Link do |release, options|
release.links.sorted release.links.sorted
end end
expose :evidence_file_path, expose_nil: false expose :evidence_file_path, expose_nil: false, if: ->(_, _) { can_download_code? }
end end
expose :_links do expose :_links do
expose :merge_requests_url, expose_nil: false expose :merge_requests_url, expose_nil: false
......
...@@ -184,6 +184,7 @@ describe Projects::ReleasesController do ...@@ -184,6 +184,7 @@ describe Projects::ReleasesController do
sign_in(user) sign_in(user)
end end
context 'when the user is a developer' do
it 'returns the correct evidence summary as a json' do it 'returns the correct evidence summary as a json' do
subject subject
...@@ -201,6 +202,23 @@ describe Projects::ReleasesController do ...@@ -201,6 +202,23 @@ describe Projects::ReleasesController do
end end
end end
context 'when the user is a guest for the project' do
before do
project.add_guest(user)
end
context 'if the project is private' do
let(:project) { private_project }
it_behaves_like 'not found'
end
context 'if the project is public' do
it_behaves_like 'successful request'
end
end
end
private private
def get_index def get_index
......
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