Commit 3b5cff44 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch 'issue#227542-rename-read_vulnerability-policy' into 'master'

Rename read_vulnerability to read_security_resource policy

See merge request gitlab-org/gitlab!58704
parents 7f30efce ee4fe811
...@@ -276,6 +276,10 @@ class Note < ApplicationRecord ...@@ -276,6 +276,10 @@ class Note < ApplicationRecord
noteable_type == 'AlertManagement::Alert' noteable_type == 'AlertManagement::Alert'
end end
def for_vulnerability?
noteable_type == "Vulnerability"
end
def for_project_snippet? def for_project_snippet?
noteable.is_a?(ProjectSnippet) noteable.is_a?(ProjectSnippet)
end end
...@@ -411,6 +415,8 @@ class Note < ApplicationRecord ...@@ -411,6 +415,8 @@ class Note < ApplicationRecord
'snippet' 'snippet'
elsif for_alert_mangement_alert? elsif for_alert_mangement_alert?
'alert_management_alert' 'alert_management_alert'
elsif for_vulnerability?
'security_resource'
else else
noteable_type.demodulize.underscore noteable_type.demodulize.underscore
end end
......
...@@ -117,7 +117,7 @@ module EE ...@@ -117,7 +117,7 @@ module EE
end end
def populate_vulnerability_id def populate_vulnerability_id
self.vulnerability_id = params[:vulnerability_id] if can?(current_user, :read_vulnerability, project) self.vulnerability_id = params[:vulnerability_id] if can?(current_user, :read_security_resource, project)
end end
def redirect_if_test_case def redirect_if_test_case
......
...@@ -26,7 +26,7 @@ module Projects ...@@ -26,7 +26,7 @@ module Projects
def can_access_vulnerable? def can_access_vulnerable?
return true unless query_params[:filter] == 'vulnerable' return true unless query_params[:filter] == 'vulnerable'
can?(current_user, :read_vulnerability, project) can?(current_user, :read_security_resource, project)
end end
def can_collect_dependencies? def can_collect_dependencies?
......
...@@ -51,7 +51,7 @@ module Projects ...@@ -51,7 +51,7 @@ module Projects
end end
def authorize_read_vulnerability! def authorize_read_vulnerability!
return if can?(current_user, :read_vulnerability, project) return if can?(current_user, :read_security_resource, project)
render_404 render_404
end end
......
...@@ -28,7 +28,7 @@ module Projects ...@@ -28,7 +28,7 @@ module Projects
def vulnerability def vulnerability
@vulnerability ||= @project.vulnerabilities.find(params[:vulnerability_id]) @vulnerability ||= @project.vulnerabilities.find(params[:vulnerability_id])
return render_404 unless can?(current_user, :read_vulnerability, @vulnerability) return render_404 unless can?(current_user, :read_security_resource, @vulnerability)
@vulnerability @vulnerability
end end
......
...@@ -172,7 +172,7 @@ module EE ...@@ -172,7 +172,7 @@ module EE
end end
def api_fuzzing_ci_configuration def api_fuzzing_ci_configuration
return unless Ability.allowed?(current_user, :read_vulnerability, object) return unless Ability.allowed?(current_user, :read_security_resource, object)
configuration = ::AppSec::Fuzzing::Api::CiConfiguration.new(project: object) configuration = ::AppSec::Fuzzing::Api::CiConfiguration.new(project: object)
......
...@@ -37,7 +37,7 @@ module Mutations ...@@ -37,7 +37,7 @@ module Mutations
def add_project(project) def add_project(project)
Dashboard::Projects::CreateService Dashboard::Projects::CreateService
.new(current_user, current_user.security_dashboard_projects, ability: :read_vulnerability) .new(current_user, current_user.security_dashboard_projects, ability: :read_security_resource)
.execute([project.id]) .execute([project.id])
end end
......
...@@ -6,7 +6,7 @@ module Resolvers ...@@ -6,7 +6,7 @@ module Resolvers
include Gitlab::Graphql::Authorize::AuthorizeResource include Gitlab::Graphql::Authorize::AuthorizeResource
type Types::VulnerabilitySeveritiesCountType, null: true type Types::VulnerabilitySeveritiesCountType, null: true
authorize :read_vulnerability authorize :read_security_resource
authorizes_object! authorizes_object!
argument :project_id, [GraphQL::ID_TYPE], argument :project_id, [GraphQL::ID_TYPE],
......
...@@ -6,7 +6,7 @@ module Types ...@@ -6,7 +6,7 @@ module Types
graphql_name 'VulnerabilityExternalIssueLink' graphql_name 'VulnerabilityExternalIssueLink'
description 'Represents an external issue link of a vulnerability' description 'Represents an external issue link of a vulnerability'
authorize :read_vulnerability authorize :read_security_resource
field :id, GlobalIDType[::Vulnerabilities::ExternalIssueLink], null: false, field :id, GlobalIDType[::Vulnerabilities::ExternalIssueLink], null: false,
description: 'GraphQL ID of the external issue link.' description: 'GraphQL ID of the external issue link.'
......
...@@ -7,7 +7,7 @@ module Types ...@@ -7,7 +7,7 @@ module Types
implements(Types::Notes::NoteableType) implements(Types::Notes::NoteableType)
authorize :read_vulnerability authorize :read_security_resource
expose_permissions Types::PermissionTypes::Vulnerability expose_permissions Types::PermissionTypes::Vulnerability
......
...@@ -282,7 +282,7 @@ module EE ...@@ -282,7 +282,7 @@ module EE
rule { can?(:read_group_security_dashboard) }.policy do rule { can?(:read_group_security_dashboard) }.policy do
enable :create_vulnerability_export enable :create_vulnerability_export
enable :read_vulnerability enable :read_security_resource
end end
rule { admin | owner }.policy do rule { admin | owner }.policy do
......
...@@ -196,7 +196,7 @@ module EE ...@@ -196,7 +196,7 @@ module EE
end end
rule { security_dashboard_enabled & can?(:developer_access) }.policy do rule { security_dashboard_enabled & can?(:developer_access) }.policy do
enable :read_vulnerability enable :read_security_resource
enable :read_vulnerability_scanner enable :read_vulnerability_scanner
end end
...@@ -211,7 +211,7 @@ module EE ...@@ -211,7 +211,7 @@ module EE
rule { can?(:read_merge_request) & can?(:read_pipeline) }.enable :read_merge_train rule { can?(:read_merge_request) & can?(:read_pipeline) }.enable :read_merge_train
rule { can?(:read_vulnerability) }.policy do rule { can?(:read_security_resource) }.policy do
enable :read_project_security_dashboard enable :read_project_security_dashboard
enable :create_vulnerability enable :create_vulnerability
enable :create_vulnerability_export enable :create_vulnerability_export
...@@ -271,7 +271,7 @@ module EE ...@@ -271,7 +271,7 @@ module EE
end end
rule { auditor & security_dashboard_enabled }.policy do rule { auditor & security_dashboard_enabled }.policy do
enable :read_vulnerability enable :read_security_resource
enable :read_vulnerability_scanner enable :read_vulnerability_scanner
end end
......
...@@ -8,7 +8,7 @@ class InstanceSecurityDashboardPolicy < BasePolicy ...@@ -8,7 +8,7 @@ class InstanceSecurityDashboardPolicy < BasePolicy
rule { ~anonymous }.policy do rule { ~anonymous }.policy do
enable :read_instance_security_dashboard enable :read_instance_security_dashboard
enable :read_vulnerability enable :read_security_resource
end end
rule { security_dashboard_enabled & can?(:read_instance_security_dashboard) }.enable :create_vulnerability_export rule { security_dashboard_enabled & can?(:read_instance_security_dashboard) }.enable :create_vulnerability_export
......
...@@ -4,7 +4,7 @@ module Security ...@@ -4,7 +4,7 @@ module Security
class ScanPolicy < BasePolicy class ScanPolicy < BasePolicy
delegate { @subject.project } delegate { @subject.project }
rule { can?(:read_vulnerability) }.policy do rule { can?(:read_security_resource) }.policy do
enable :read_scan enable :read_scan
end end
end end
......
...@@ -6,7 +6,7 @@ module EE ...@@ -6,7 +6,7 @@ module EE
extend ActiveSupport::Concern extend ActiveSupport::Concern
def expose_security_dashboard? def expose_security_dashboard?
return false unless can?(current_user, :read_vulnerability, pipeline.project) return false unless can?(current_user, :read_security_resource, pipeline.project)
Ci::JobArtifact::SECURITY_REPORT_FILE_TYPES.any? { |file_type| batch_lookup_report_artifact_for_file_type(file_type.to_sym) } Ci::JobArtifact::SECURITY_REPORT_FILE_TYPES.any? { |file_type| batch_lookup_report_artifact_for_file_type(file_type.to_sym) }
end end
......
...@@ -28,7 +28,7 @@ class DependencyEntity < Grape::Entity ...@@ -28,7 +28,7 @@ class DependencyEntity < Grape::Entity
private private
def can_read_vulnerabilities? def can_read_vulnerabilities?
can?(request.user, :read_vulnerability, request.project) can?(request.user, :read_security_resource, request.project)
end end
def can_read_licenses? def can_read_licenses?
......
...@@ -62,7 +62,7 @@ module EE ...@@ -62,7 +62,7 @@ module EE
end end
expose :can_read_vulnerabilities do |merge_request| expose :can_read_vulnerabilities do |merge_request|
can?(current_user, :read_vulnerability, merge_request.project) can?(current_user, :read_security_resource, merge_request.project)
end end
expose :can_read_vulnerability_feedback do |merge_request| expose :can_read_vulnerability_feedback do |merge_request|
......
...@@ -116,7 +116,7 @@ module VulnerabilityFeedback ...@@ -116,7 +116,7 @@ module VulnerabilityFeedback
def create_vulnerability_issue_link(vulnerability_id, issue) def create_vulnerability_issue_link(vulnerability_id, issue)
return unless vulnerability_id return unless vulnerability_id
raise Gitlab::Access::AccessDeniedError unless can?(current_user, :read_vulnerability, project) raise Gitlab::Access::AccessDeniedError unless can?(current_user, :read_security_resource, project)
vulnerability = project.vulnerabilities.find_by_id(vulnerability_id) vulnerability = project.vulnerabilities.find_by_id(vulnerability_id)
......
...@@ -32,7 +32,7 @@ module API ...@@ -32,7 +32,7 @@ module API
end end
resource :vulnerabilities do resource :vulnerabilities do
before do before do
@vulnerability = find_and_authorize_vulnerability!(:read_vulnerability) @vulnerability = find_and_authorize_vulnerability!(:read_security_resource)
end end
desc 'Get a vulnerability' do desc 'Get a vulnerability' do
...@@ -94,7 +94,7 @@ module API ...@@ -94,7 +94,7 @@ module API
use :pagination use :pagination
end end
get ':id/vulnerabilities' do get ':id/vulnerabilities' do
authorize! :read_vulnerability, user_project authorize! :read_security_resource, user_project
vulnerabilities = paginate( vulnerabilities = paginate(
vulnerabilities_by(user_project) vulnerabilities_by(user_project)
......
...@@ -84,7 +84,7 @@ module API ...@@ -84,7 +84,7 @@ module API
success ::Vulnerabilities::FindingEntity success ::Vulnerabilities::FindingEntity
end end
get ':id/vulnerability_findings' do get ':id/vulnerability_findings' do
authorize! :read_vulnerability, user_project authorize! :read_security_resource, user_project
Gitlab::Vulnerabilities::FindingsPreloader.preload_feedback!(vulnerability_findings) Gitlab::Vulnerabilities::FindingsPreloader.preload_feedback!(vulnerability_findings)
......
...@@ -34,7 +34,7 @@ module API ...@@ -34,7 +34,7 @@ module API
success EE::API::Entities::VulnerabilityRelatedIssue success EE::API::Entities::VulnerabilityRelatedIssue
end end
get ':id/issue_links' do get ':id/issue_links' do
vulnerability = find_and_authorize_vulnerability!(:read_vulnerability) vulnerability = find_and_authorize_vulnerability!(:read_security_resource)
related_issues = vulnerability.related_issues.with_api_entity_associations.with_vulnerability_links related_issues = vulnerability.related_issues.with_api_entity_associations.with_vulnerability_links
present Ability.issues_readable_by_user(related_issues, current_user), present Ability.issues_readable_by_user(related_issues, current_user),
with: EE::API::Entities::VulnerabilityRelatedIssue with: EE::API::Entities::VulnerabilityRelatedIssue
......
...@@ -13,7 +13,7 @@ module EE ...@@ -13,7 +13,7 @@ module EE
private private
def can_read_vulnerabilities?(user, project) def can_read_vulnerabilities?(user, project)
Ability.allowed?(user, :read_vulnerability, project) Ability.allowed?(user, :read_security_resource, project)
end end
end end
end end
......
...@@ -17,7 +17,7 @@ module EE ...@@ -17,7 +17,7 @@ module EE
end end
def can_read_reference?(user, vulnerability) def can_read_reference?(user, vulnerability)
can?(user, :read_vulnerability, vulnerability) can?(user, :read_security_resource, vulnerability)
end end
end end
end end
......
...@@ -47,7 +47,7 @@ RSpec.describe GitlabSchema.types['Vulnerability'] do ...@@ -47,7 +47,7 @@ RSpec.describe GitlabSchema.types['Vulnerability'] do
subject { GitlabSchema.execute(query, context: { current_user: user }).as_json } subject { GitlabSchema.execute(query, context: { current_user: user }).as_json }
it { expect(described_class).to have_graphql_fields(fields) } it { expect(described_class).to have_graphql_fields(fields) }
it { expect(described_class).to require_graphql_authorizations(:read_vulnerability) } it { expect(described_class).to require_graphql_authorizations(:read_security_resource) }
describe 'vulnerability_path' do describe 'vulnerability_path' do
let(:query) do let(:query) do
......
...@@ -848,7 +848,7 @@ RSpec.describe GroupPolicy do ...@@ -848,7 +848,7 @@ RSpec.describe GroupPolicy do
describe 'read_group_security_dashboard & create_vulnerability_export' do describe 'read_group_security_dashboard & create_vulnerability_export' do
let(:abilities) do let(:abilities) do
%i[read_group_security_dashboard create_vulnerability_export read_vulnerability] %i[read_group_security_dashboard create_vulnerability_export read_security_resource]
end end
before do before do
......
...@@ -13,7 +13,7 @@ RSpec.describe InstanceSecurityDashboardPolicy do ...@@ -13,7 +13,7 @@ RSpec.describe InstanceSecurityDashboardPolicy do
subject { described_class.new(current_user, [user]) } subject { described_class.new(current_user, [user]) }
describe 'read_instance_security_dashboard' do describe 'read_instance_security_dashboard' do
let(:abilities) { %i[read_instance_security_dashboard read_vulnerability] } let(:abilities) { %i[read_instance_security_dashboard read_security_resource] }
context 'when the user is not logged in' do context 'when the user is not logged in' do
let(:current_user) { nil } let(:current_user) { nil }
......
...@@ -23,7 +23,7 @@ RSpec.describe ProjectPolicy do ...@@ -23,7 +23,7 @@ RSpec.describe ProjectPolicy do
let(:additional_developer_permissions) do let(:additional_developer_permissions) do
%i[ %i[
admin_vulnerability_feedback read_project_audit_events read_project_security_dashboard admin_vulnerability_feedback read_project_audit_events read_project_security_dashboard
read_vulnerability read_vulnerability_scanner create_vulnerability create_vulnerability_export admin_vulnerability read_security_resource read_vulnerability_scanner create_vulnerability create_vulnerability_export admin_vulnerability
admin_vulnerability_issue_link admin_vulnerability_external_issue_link read_merge_train admin_vulnerability_issue_link admin_vulnerability_external_issue_link read_merge_train
] ]
end end
...@@ -41,7 +41,7 @@ RSpec.describe ProjectPolicy do ...@@ -41,7 +41,7 @@ RSpec.describe ProjectPolicy do
read_pipeline read_build read_commit_status read_container_image read_pipeline read_build read_commit_status read_container_image
read_environment read_deployment read_merge_request read_pages read_environment read_deployment read_merge_request read_pages
create_merge_request_in award_emoji create_merge_request_in award_emoji
read_project_security_dashboard read_vulnerability read_vulnerability_scanner read_project_security_dashboard read_security_resource read_vulnerability_scanner
read_software_license_policy read_software_license_policy
read_threat_monitoring read_merge_train read_threat_monitoring read_merge_train
read_release read_release
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe VulnerabilityPolicy do RSpec.describe VulnerabilityPolicy do
describe 'read_vulnerability' do describe 'read_security_resource' do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:vulnerability) { create(:vulnerability, project: project) } let(:vulnerability) { create(:vulnerability, project: project) }
...@@ -20,11 +20,11 @@ RSpec.describe VulnerabilityPolicy do ...@@ -20,11 +20,11 @@ RSpec.describe VulnerabilityPolicy do
project.add_developer(user) project.add_developer(user)
end end
it { is_expected.to be_allowed(:read_vulnerability) } it { is_expected.to be_allowed(:read_security_resource) }
end end
context "when the current user does not have developer access to the vulnerability's project" do context "when the current user does not have developer access to the vulnerability's project" do
it { is_expected.to be_disallowed(:read_vulnerability) } it { is_expected.to be_disallowed(:read_security_resource) }
end end
end end
...@@ -35,7 +35,7 @@ RSpec.describe VulnerabilityPolicy do ...@@ -35,7 +35,7 @@ RSpec.describe VulnerabilityPolicy do
project.add_developer(user) project.add_developer(user)
end end
it { is_expected.to be_disallowed(:read_vulnerability) } it { is_expected.to be_disallowed(:read_security_resource) }
end end
end end
end end
...@@ -78,7 +78,7 @@ RSpec.describe Dashboard::Projects::CreateService do ...@@ -78,7 +78,7 @@ RSpec.describe Dashboard::Projects::CreateService do
context 'with project for which user has no permission' do context 'with project for which user has no permission' do
let(:input) { [project.id] } let(:input) { [project.id] }
let(:feature) { nil } let(:feature) { nil }
let(:ability) { :read_vulnerability } let(:ability) { :read_security_resource }
let(:permission_available) { false } let(:permission_available) { false }
it 'does not check if feature is available' do it 'does not check if feature is available' do
......
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