Commit 296680d7 authored by Dmytro Zaporozhets's avatar Dmytro Zaporozhets

Merge branch 'refactoring-ee-entities-4' into 'master'

Separate vulnerability and feature entities into own class files

See merge request gitlab-org/gitlab!26088
parents 96283954 5f357446
---
title: Separate vulnerabilities, feature flags, dependency entities into own class files
merge_request: 26088
author: Rajendra Kadam
type: added
...@@ -832,89 +832,6 @@ module EE ...@@ -832,89 +832,6 @@ module EE
expose :id, :project_id, :name expose :id, :project_id, :name
end end
class Dependency < Grape::Entity
class Vulnerability < Grape::Entity
expose :name, :severity
end
expose :name, :version, :package_manager, :dependency_file_path
expose :dependency_file_path do |dependency|
dependency[:location][:path]
end
expose :vulnerabilities, using: Vulnerability, if: ->(_, opts) { can_read_vulnerabilities?(opts[:user], opts[:project]) }
private
def can_read_vulnerabilities?(user, project)
Ability.allowed?(user, :read_vulnerability, project)
end
end
class FeatureFlag < Grape::Entity
class Scope < Grape::Entity
expose :id
expose :active
expose :environment_scope
expose :strategies
expose :created_at
expose :updated_at
end
class DetailedScope < Scope
expose :name
end
expose :name
expose :description
expose :created_at
expose :updated_at
expose :scopes, using: Scope
end
class Vulnerability < Grape::Entity
expose :id
expose :title
expose :description
expose :state
expose :severity
expose :confidence
expose :report_type
expose :project, using: ::API::Entities::ProjectIdentity
expose :finding
expose :author_id
expose :updated_by_id
expose :last_edited_by_id
expose :resolved_by_id
expose :dismissed_by_id
expose :start_date
expose :due_date
expose :created_at
expose :updated_at
expose :last_edited_at
expose :resolved_at
expose :dismissed_at
end
class VulnerabilityRelatedIssue < ::API::Entities::IssueBasic
# vulnerability_link_* attributes come from joined Vulnerabilities::IssueLink record
expose :vulnerability_link_id
expose :vulnerability_link_type do |related_issue|
::Vulnerabilities::IssueLink.link_types.key(related_issue.vulnerability_link_type)
end
end
class VulnerabilityIssueLink < Grape::Entity
expose :vulnerability, using: ::EE::API::Entities::Vulnerability
expose :issue, using: ::API::Entities::IssueBasic
expose :link_type
end
module Analytics module Analytics
module CodeReview module CodeReview
class MergeRequest < ::API::Entities::MergeRequestSimple class MergeRequest < ::API::Entities::MergeRequestSimple
......
# frozen_string_literal: true
module EE
module API
module Entities
class Dependency < Grape::Entity
expose :name, :version, :package_manager, :dependency_file_path
expose :dependency_file_path do |dependency|
dependency[:location][:path]
end
expose :vulnerabilities, using: Dependency::Vulnerability, if: ->(_, opts) { can_read_vulnerabilities?(opts[:user], opts[:project]) }
private
def can_read_vulnerabilities?(user, project)
Ability.allowed?(user, :read_vulnerability, project)
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
class Dependency < Grape::Entity
class Vulnerability < Grape::Entity
expose :name, :severity
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
class FeatureFlag < Grape::Entity
expose :name
expose :description
expose :created_at
expose :updated_at
expose :scopes, using: FeatureFlag::Scope
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
class FeatureFlag < Grape::Entity
class DetailedScope < Scope
expose :name
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
class FeatureFlag < Grape::Entity
class Scope < Grape::Entity
expose :id
expose :active
expose :environment_scope
expose :strategies
expose :created_at
expose :updated_at
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
class Vulnerability < Grape::Entity
expose :id
expose :title
expose :description
expose :state
expose :severity
expose :confidence
expose :report_type
expose :project, using: ::API::Entities::ProjectIdentity
expose :finding
expose :author_id
expose :updated_by_id
expose :last_edited_by_id
expose :resolved_by_id
expose :dismissed_by_id
expose :start_date
expose :due_date
expose :created_at
expose :updated_at
expose :last_edited_at
expose :resolved_at
expose :dismissed_at
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
class VulnerabilityIssueLink < Grape::Entity
expose :vulnerability, using: ::EE::API::Entities::Vulnerability
expose :issue, using: ::API::Entities::IssueBasic
expose :link_type
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
class VulnerabilityRelatedIssue < ::API::Entities::IssueBasic
# vulnerability_link_* attributes come from joined Vulnerabilities::IssueLink record
expose :vulnerability_link_id
expose :vulnerability_link_type do |related_issue|
::Vulnerabilities::IssueLink.link_types.key(related_issue.vulnerability_link_type)
end
end
end
end
end
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