Commit 335d8dfa authored by Lin Jen-Shin's avatar Lin Jen-Shin

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

Separate audit, epic, epic issue and linked epic into own class files

See merge request gitlab-org/gitlab!25592
parents adcac7e4 125501df
---
title: Separate epic, epic_issue, linked epic ee entities into own class file
merge_request: 25592
author: Rajendra Kadam
type: added
......@@ -265,118 +265,6 @@ module EE
end
end
class LinkedEpic < Grape::Entity
expose :id
expose :iid
expose :title
expose :group_id
expose :parent_id
expose :has_children?, as: :has_children
expose :has_issues?, as: :has_issues
expose :reference do |epic|
epic.to_reference(epic.parent.group)
end
expose :url do |epic|
::Gitlab::Routing.url_helpers.group_epic_url(epic.group, epic)
end
expose :relation_url do |epic|
::Gitlab::Routing.url_helpers.group_epic_link_url(epic.parent.group, epic.parent.iid, epic.id)
end
end
class AuditEvent < Grape::Entity
expose :id
expose :author_id
expose :entity_id
expose :entity_type
expose :details do |audit_event|
audit_event.formatted_details
end
expose :created_at
end
class Epic < Grape::Entity
can_admin_epic = ->(epic, opts) { Ability.allowed?(opts[:user], :admin_epic, epic) }
expose :id
expose :iid
expose :group_id
expose :parent_id
expose :title
expose :description
expose :author, using: ::API::Entities::UserBasic
expose :start_date
expose :start_date_is_fixed?, as: :start_date_is_fixed, if: can_admin_epic
expose :start_date_fixed, :start_date_from_inherited_source, if: can_admin_epic
expose :start_date_from_milestones, if: can_admin_epic # @deprecated in favor of start_date_from_inherited_source
expose :end_date # @deprecated in favor of due_date
expose :end_date, as: :due_date
expose :due_date_is_fixed?, as: :due_date_is_fixed, if: can_admin_epic
expose :due_date_fixed, :due_date_from_inherited_source, if: can_admin_epic
expose :due_date_from_milestones, if: can_admin_epic # @deprecated in favor of due_date_from_inherited_source
expose :state
expose :web_edit_url, if: can_admin_epic # @deprecated
expose :web_url
expose :references, with: ::API::Entities::IssuableReferences do |epic|
epic
end
# reference is deprecated in favour of references
# Introduced [Gitlab 12.6](https://gitlab.com/gitlab-org/gitlab/merge_requests/20354)
expose :reference, if: { with_reference: true } do |epic|
epic.to_reference(full: true)
end
expose :created_at
expose :updated_at
expose :closed_at
expose :labels do |epic, options|
if options[:with_labels_details]
::API::Entities::LabelBasic.represent(epic.labels.sort_by(&:title))
else
epic.labels.map(&:title).sort
end
end
expose :upvotes do |epic, options|
if options[:issuable_metadata]
# Avoids an N+1 query when metadata is included
options[:issuable_metadata][epic.id].upvotes
else
epic.upvotes
end
end
expose :downvotes do |epic, options|
if options[:issuable_metadata]
# Avoids an N+1 query when metadata is included
options[:issuable_metadata][epic.id].downvotes
else
epic.downvotes
end
end
# Calculating the value of subscribed field triggers Markdown
# processing. We can't do that for multiple epics
# requests in a single API request.
expose :subscribed, if: -> (_, options) { options.fetch(:include_subscribed, false) } do |epic, options|
user = options[:user]
user.present? ? epic.subscribed?(user) : false
end
def web_url
::Gitlab::Routing.url_helpers.group_epic_url(object.group, object)
end
def web_edit_url
::Gitlab::Routing.url_helpers.group_epic_path(object.group, object)
end
end
class EpicIssue < ::API::Entities::Issue
expose :epic_issue_id
expose :relative_position
end
class EpicIssueLink < Grape::Entity
expose :id
expose :relative_position
......
# frozen_string_literal: true
module EE
module API
module Entities
class AuditEvent < Grape::Entity
expose :id
expose :author_id
expose :entity_id
expose :entity_type
expose :details do |audit_event|
audit_event.formatted_details
end
expose :created_at
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
class Epic < Grape::Entity
can_admin_epic = ->(epic, opts) { Ability.allowed?(opts[:user], :admin_epic, epic) }
expose :id
expose :iid
expose :group_id
expose :parent_id
expose :title
expose :description
expose :author, using: ::API::Entities::UserBasic
expose :start_date
expose :start_date_is_fixed?, as: :start_date_is_fixed, if: can_admin_epic
expose :start_date_fixed, :start_date_from_inherited_source, if: can_admin_epic
expose :start_date_from_milestones, if: can_admin_epic # @deprecated in favor of start_date_from_inherited_source
expose :end_date # @deprecated in favor of due_date
expose :end_date, as: :due_date
expose :due_date_is_fixed?, as: :due_date_is_fixed, if: can_admin_epic
expose :due_date_fixed, :due_date_from_inherited_source, if: can_admin_epic
expose :due_date_from_milestones, if: can_admin_epic # @deprecated in favor of due_date_from_inherited_source
expose :state
expose :web_edit_url, if: can_admin_epic # @deprecated
expose :web_url
expose :references, with: ::API::Entities::IssuableReferences do |epic|
epic
end
# reference is deprecated in favour of references
# Introduced [Gitlab 12.6](https://gitlab.com/gitlab-org/gitlab/merge_requests/20354)
expose :reference, if: { with_reference: true } do |epic|
epic.to_reference(full: true)
end
expose :created_at
expose :updated_at
expose :closed_at
expose :labels do |epic, options|
if options[:with_labels_details]
::API::Entities::LabelBasic.represent(epic.labels.sort_by(&:title))
else
epic.labels.map(&:title).sort
end
end
expose :upvotes do |epic, options|
if options[:issuable_metadata]
# Avoids an N+1 query when metadata is included
options[:issuable_metadata][epic.id].upvotes
else
epic.upvotes
end
end
expose :downvotes do |epic, options|
if options[:issuable_metadata]
# Avoids an N+1 query when metadata is included
options[:issuable_metadata][epic.id].downvotes
else
epic.downvotes
end
end
# Calculating the value of subscribed field triggers Markdown
# processing. We can't do that for multiple epics
# requests in a single API request.
expose :subscribed, if: -> (_, options) { options.fetch(:include_subscribed, false) } do |epic, options|
user = options[:user]
user.present? ? epic.subscribed?(user) : false
end
def web_url
::Gitlab::Routing.url_helpers.group_epic_url(object.group, object)
end
def web_edit_url
::Gitlab::Routing.url_helpers.group_epic_path(object.group, object)
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
class EpicIssue < ::API::Entities::Issue
expose :epic_issue_id
expose :relative_position
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
class LinkedEpic < Grape::Entity
expose :id
expose :iid
expose :title
expose :group_id
expose :parent_id
expose :has_children?, as: :has_children
expose :has_issues?, as: :has_issues
expose :reference do |epic|
epic.to_reference(epic.parent.group)
end
expose :url do |epic|
::Gitlab::Routing.url_helpers.group_epic_url(epic.group, epic)
end
expose :relation_url do |epic|
::Gitlab::Routing.url_helpers.group_epic_link_url(epic.parent.group, epic.parent.iid, epic.id)
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