Commit 3033fe53 authored by Rajendra Kadam's avatar Rajendra Kadam

Separate module only entities into own class files

parent f76119fa
...@@ -123,131 +123,6 @@ module EE ...@@ -123,131 +123,6 @@ module EE
end end
end end
module Issue
extend ActiveSupport::Concern
prepended do
with_options if: -> (issue, options) { ::Ability.allowed?(options[:current_user], :read_epic, issue.project&.group) } do
expose :epic_iid do |issue|
issue.epic&.iid
end
expose :epic, using: EpicBaseEntity
end
end
end
module MergeRequestBasic
extend ActiveSupport::Concern
prepended do
expose :approvals_before_merge
end
end
module Namespace
extend ActiveSupport::Concern
prepended do
can_admin_namespace = ->(namespace, opts) { ::Ability.allowed?(opts[:current_user], :admin_namespace, namespace) }
expose :shared_runners_minutes_limit, if: ->(_, options) { options[:current_user]&.admin? }
expose :extra_shared_runners_minutes_limit, if: ->(_, options) { options[:current_user]&.admin? }
expose :billable_members_count do |namespace, options|
namespace.billable_members_count(options[:requested_hosted_plan])
end
expose :plan, if: can_admin_namespace do |namespace, _|
namespace.actual_plan_name
end
expose :trial_ends_on, if: can_admin_namespace do |namespace, _|
namespace.trial_ends_on
end
expose :trial, if: can_admin_namespace do |namespace, _|
namespace.trial?
end
end
end
module Board
extend ActiveSupport::Concern
prepended do
# Default filtering configuration
expose :name
expose :group, using: ::API::Entities::BasicGroupDetails
with_options if: ->(board, _) { board.resource_parent.feature_available?(:scoped_issue_board) } do
expose :milestone do |board|
if board.milestone.is_a?(Milestone)
::API::Entities::Milestone.represent(board.milestone)
else
SpecialBoardFilter.represent(board.milestone)
end
end
expose :assignee, using: ::API::Entities::UserBasic
expose :labels, using: ::API::Entities::LabelBasic
expose :weight
end
end
end
module List
extend ActiveSupport::Concern
prepended do
expose :milestone, using: ::API::Entities::Milestone, if: -> (entity, _) { entity.milestone? }
expose :user, as: :assignee, using: ::API::Entities::UserSafe, if: -> (entity, _) { entity.assignee? }
expose :max_issue_count, if: -> (list, _) { list.wip_limits_available? }
expose :max_issue_weight, if: -> (list, _) { list.wip_limits_available? }
end
end
module ApplicationSetting
extend ActiveSupport::Concern
prepended do
expose(*EE::ApplicationSettingsHelper.repository_mirror_attributes, if: ->(_instance, _options) do
::License.feature_available?(:repository_mirrors)
end)
expose(*EE::ApplicationSettingsHelper.merge_request_appovers_rules_attributes, if: ->(_instance, _options) do
::License.feature_available?(:admin_merge_request_approvers_rules)
end)
expose :email_additional_text, if: ->(_instance, _opts) { ::License.feature_available?(:email_additional_text) }
expose :file_template_project_id, if: ->(_instance, _opts) { ::License.feature_available?(:custom_file_templates) }
expose :default_project_deletion_protection, if: ->(_instance, _opts) { ::License.feature_available?(:default_project_deletion_protection) }
expose :deletion_adjourned_period, if: ->(_instance, _opts) { ::License.feature_available?(:adjourned_deletion_for_projects_and_groups) }
expose :updating_name_disabled_for_users, if: ->(_instance, _opts) { ::License.feature_available?(:disable_name_update_for_users) }
expose :npm_package_requests_forwarding, if: ->(_instance, _opts) { ::License.feature_available?(:packages) }
end
end
module Todo
extend ::Gitlab::Utils::Override
extend ActiveSupport::Concern
override :todo_target_class
def todo_target_class(target_type)
super
rescue NameError
# false as second argument prevents looking up in module hierarchy
# see also https://gitlab.com/gitlab-org/gitlab-foss/issues/59719
::EE::API::Entities.const_get(target_type, false)
end
override :todo_target_url
def todo_target_url(todo)
return super unless todo.target_type == ::DesignManagement::Design.name
design = todo.target
path_options = {
anchor: todo_target_anchor(todo),
vueroute: design.filename
}
::Gitlab::Routing.url_helpers.designs_project_issue_url(design.project, design.issue, path_options)
end
end
######################## ########################
# EE-specific entities # # EE-specific entities #
######################## ########################
...@@ -374,20 +249,6 @@ module EE ...@@ -374,20 +249,6 @@ module EE
end end
end end
end end
module UserDetailsWithAdmin
extend ActiveSupport::Concern
prepended do
expose :plan do |user|
user.namespace.try(:gitlab_subscription)&.plan_name
end
expose :trial do |user|
user.namespace.try(:trial?)
end
end
end
end end
end end
end end
# frozen_string_literal: true
module EE
module API
module Entities
module ApplicationSetting
extend ActiveSupport::Concern
prepended do
expose(*EE::ApplicationSettingsHelper.repository_mirror_attributes, if: ->(_instance, _options) do
::License.feature_available?(:repository_mirrors)
end)
expose(*EE::ApplicationSettingsHelper.merge_request_appovers_rules_attributes, if: ->(_instance, _options) do
::License.feature_available?(:admin_merge_request_approvers_rules)
end)
expose :email_additional_text, if: ->(_instance, _opts) { ::License.feature_available?(:email_additional_text) }
expose :file_template_project_id, if: ->(_instance, _opts) { ::License.feature_available?(:custom_file_templates) }
expose :default_project_deletion_protection, if: ->(_instance, _opts) { ::License.feature_available?(:default_project_deletion_protection) }
expose :deletion_adjourned_period, if: ->(_instance, _opts) { ::License.feature_available?(:adjourned_deletion_for_projects_and_groups) }
expose :updating_name_disabled_for_users, if: ->(_instance, _opts) { ::License.feature_available?(:disable_name_update_for_users) }
expose :npm_package_requests_forwarding, if: ->(_instance, _opts) { ::License.feature_available?(:packages) }
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module Board
extend ActiveSupport::Concern
prepended do
# Default filtering configuration
expose :name
expose :group, using: ::API::Entities::BasicGroupDetails
with_options if: ->(board, _) { board.resource_parent.feature_available?(:scoped_issue_board) } do
expose :milestone do |board|
if board.milestone.is_a?(Milestone)
::API::Entities::Milestone.represent(board.milestone)
else
SpecialBoardFilter.represent(board.milestone)
end
end
expose :assignee, using: ::API::Entities::UserBasic
expose :labels, using: ::API::Entities::LabelBasic
expose :weight
end
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module Issue
extend ActiveSupport::Concern
prepended do
with_options if: -> (issue, options) { ::Ability.allowed?(options[:current_user], :read_epic, issue.project&.group) } do
expose :epic_iid do |issue|
issue.epic&.iid
end
expose :epic, using: EpicBaseEntity
end
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module List
extend ActiveSupport::Concern
prepended do
expose :milestone, using: ::API::Entities::Milestone, if: -> (entity, _) { entity.milestone? }
expose :user, as: :assignee, using: ::API::Entities::UserSafe, if: -> (entity, _) { entity.assignee? }
expose :max_issue_count, if: -> (list, _) { list.wip_limits_available? }
expose :max_issue_weight, if: -> (list, _) { list.wip_limits_available? }
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module MergeRequestBasic
extend ActiveSupport::Concern
prepended do
expose :approvals_before_merge
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module Namespace
extend ActiveSupport::Concern
prepended do
can_admin_namespace = ->(namespace, opts) { ::Ability.allowed?(opts[:current_user], :admin_namespace, namespace) }
expose :shared_runners_minutes_limit, if: ->(_, options) { options[:current_user]&.admin? }
expose :extra_shared_runners_minutes_limit, if: ->(_, options) { options[:current_user]&.admin? }
expose :billable_members_count do |namespace, options|
namespace.billable_members_count(options[:requested_hosted_plan])
end
expose :plan, if: can_admin_namespace do |namespace, _|
namespace.actual_plan_name
end
expose :trial_ends_on, if: can_admin_namespace do |namespace, _|
namespace.trial_ends_on
end
expose :trial, if: can_admin_namespace do |namespace, _|
namespace.trial?
end
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module Todo
extend ::Gitlab::Utils::Override
extend ActiveSupport::Concern
override :todo_target_class
def todo_target_class(target_type)
super
rescue NameError
# false as second argument prevents looking up in module hierarchy
# see also https://gitlab.com/gitlab-org/gitlab-foss/issues/59719
::EE::API::Entities.const_get(target_type, false)
end
override :todo_target_url
def todo_target_url(todo)
return super unless todo.target_type == ::DesignManagement::Design.name
design = todo.target
path_options = {
anchor: todo_target_anchor(todo),
vueroute: design.filename
}
::Gitlab::Routing.url_helpers.designs_project_issue_url(design.project, design.issue, path_options)
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module UserDetailsWithAdmin
extend ActiveSupport::Concern
prepended do
expose :plan do |user|
user.namespace.try(:gitlab_subscription)&.plan_name
end
expose :trial do |user|
user.namespace.try(:trial?)
end
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