Commit 46c1b26a authored by Jarka Košanová's avatar Jarka Košanová

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

Refactor approver classess into own class file for EE entities

See merge request gitlab-org/gitlab!27336
parents f6507c92 b1e43315
---
title: Separate approval entities into own class files
merge_request: 27336
author: Rajendra Kadam
type: added
......@@ -297,98 +297,6 @@ module EE
expose :wrapped_approval_rules, as: :rules, using: MergeRequestApprovalSettingRule, override: true
end
# @deprecated
class Approver < Grape::Entity
expose :user, using: ::API::Entities::UserBasic
end
# @deprecated
class ApproverGroup < Grape::Entity
expose :group, using: ::API::Entities::Group
end
class ApprovalSettings < Grape::Entity
expose :approvers, using: EE::API::Entities::Approver
expose :approver_groups, using: EE::API::Entities::ApproverGroup
expose :approvals_before_merge
expose :reset_approvals_on_push
expose :disable_overriding_approvers_per_merge_request
expose :merge_requests_author_approval
expose :merge_requests_disable_committers_approval
expose :require_password_to_approve
end
class Approvals < Grape::Entity
expose :user, using: ::API::Entities::UserBasic
end
class ApprovalState < Grape::Entity
expose :merge_request, merge: true, using: ::API::Entities::IssuableEntity
expose(:merge_status) { |approval_state| approval_state.merge_request.merge_status }
expose :approved?, as: :approved
expose :approvals_required
expose :approvals_left
expose :require_password_to_approve do |approval_state|
approval_state.project.require_password_to_approve?
end
expose :approved_by, using: EE::API::Entities::Approvals do |approval_state|
approval_state.merge_request.approvals
end
expose :suggested_approvers, using: ::API::Entities::UserBasic do |approval_state, options|
approval_state.suggested_approvers(current_user: options[:current_user])
end
# @deprecated, reads from first regular rule instead
expose :approvers do |approval_state|
if rule = approval_state.first_regular_rule
rule.users.map do |user|
{ user: ::API::Entities::UserBasic.represent(user) }
end
else
[]
end
end
# @deprecated, reads from first regular rule instead
expose :approver_groups do |approval_state|
if rule = approval_state.first_regular_rule
presenter = ::ApprovalRulePresenter.new(rule, current_user: options[:current_user])
presenter.groups.map do |group|
{ group: ::API::Entities::Group.represent(group) }
end
else
[]
end
end
expose :user_has_approved do |approval_state, options|
approval_state.has_approved?(options[:current_user])
end
expose :user_can_approve do |approval_state, options|
approval_state.can_approve?(options[:current_user])
end
expose :approval_rules_left, using: ApprovalRuleShort
expose :has_approval_rules do |approval_state|
approval_state.user_defined_rules.present?
end
expose :merge_request_approvers_available do |approval_state|
approval_state.project.feature_available?(:merge_request_approvers)
end
expose :multiple_approval_rules_available do |approval_state|
approval_state.project.multiple_approval_rules_available?
end
end
module ConanPackage
class ConanPackageManifest < Grape::Entity
expose :package_urls, merge: true
......
# frozen_string_literal: true
module EE
module API
module Entities
class ApprovalSettings < Grape::Entity
expose :approvers, using: EE::API::Entities::Approver
expose :approver_groups, using: EE::API::Entities::ApproverGroup
expose :approvals_before_merge
expose :reset_approvals_on_push
expose :disable_overriding_approvers_per_merge_request
expose :merge_requests_author_approval
expose :merge_requests_disable_committers_approval
expose :require_password_to_approve
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
class ApprovalState < Grape::Entity
expose :merge_request, merge: true, using: ::API::Entities::IssuableEntity
expose(:merge_status) { |approval_state| approval_state.merge_request.merge_status }
expose :approved?, as: :approved
expose :approvals_required
expose :approvals_left
expose :require_password_to_approve do |approval_state|
approval_state.project.require_password_to_approve?
end
expose :approved_by, using: EE::API::Entities::Approvals do |approval_state|
approval_state.merge_request.approvals
end
expose :suggested_approvers, using: ::API::Entities::UserBasic do |approval_state, options|
approval_state.suggested_approvers(current_user: options[:current_user])
end
# @deprecated, reads from first regular rule instead
expose :approvers do |approval_state|
if rule = approval_state.first_regular_rule
rule.users.map do |user|
{ user: ::API::Entities::UserBasic.represent(user) }
end
else
[]
end
end
# @deprecated, reads from first regular rule instead
expose :approver_groups do |approval_state|
if rule = approval_state.first_regular_rule
presenter = ::ApprovalRulePresenter.new(rule, current_user: options[:current_user])
presenter.groups.map do |group|
{ group: ::API::Entities::Group.represent(group) }
end
else
[]
end
end
expose :user_has_approved do |approval_state, options|
approval_state.has_approved?(options[:current_user])
end
expose :user_can_approve do |approval_state, options|
approval_state.can_approve?(options[:current_user])
end
expose :approval_rules_left, using: ApprovalRuleShort
expose :has_approval_rules do |approval_state|
approval_state.user_defined_rules.present?
end
expose :merge_request_approvers_available do |approval_state|
approval_state.project.feature_available?(:merge_request_approvers)
end
expose :multiple_approval_rules_available do |approval_state|
approval_state.project.multiple_approval_rules_available?
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
class Approvals < Grape::Entity
expose :user, using: ::API::Entities::UserBasic
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
# @deprecated
class Approver < Grape::Entity
expose :user, using: ::API::Entities::UserBasic
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
# @deprecated
class ApproverGroup < Grape::Entity
expose :group, using: ::API::Entities::Group
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