Commit 2465848b authored by Yorick Peterse's avatar Yorick Peterse

Move EE code out if API::Entities

parent e5d8ca9e
......@@ -29,7 +29,7 @@ module API
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
desc 'Get project software license policies' do
success Entities::ManagedLicense
success EE::API::Entities::ManagedLicense
end
route_setting :skip_authentication, true
params do
......@@ -39,21 +39,21 @@ module API
authorize_can_read!
software_license_policies = user_project.software_license_policies
present paginate(software_license_policies), with: Entities::ManagedLicense
present paginate(software_license_policies), with: EE::API::Entities::ManagedLicense
end
desc 'Get a specific software license policy from a project' do
success Entities::ManagedLicense
success EE::API::Entities::ManagedLicense
end
get ':id/managed_licenses/:managed_license_id', requirements: { managed_license_id: /.*/ } do
authorize_can_read!
break not_found!('SoftwareLicensePolicy') unless software_license_policy
present software_license_policy, with: Entities::ManagedLicense
present software_license_policy, with: EE::API::Entities::ManagedLicense
end
desc 'Create a new software license policy in a project' do
success Entities::ManagedLicense
success EE::API::Entities::ManagedLicense
end
params do
requires :name, type: String, desc: 'The name of the license'
......@@ -73,14 +73,14 @@ module API
created_software_license_policy = result[:software_license_policy]
if result[:status] == :success
present created_software_license_policy, with: Entities::ManagedLicense
present created_software_license_policy, with: EE::API::Entities::ManagedLicense
else
render_api_error!(result[:message], result[:http_status])
end
end
desc 'Update an existing software license policy from a project' do
success Entities::ManagedLicense
success EE::API::Entities::ManagedLicense
end
params do
optional :name, type: String, desc: 'The name of the license'
......@@ -101,7 +101,7 @@ module API
).execute(@software_license_policy)
if result[:status] == :success
present @software_license_policy, with: Entities::ManagedLicense
present @software_license_policy, with: EE::API::Entities::ManagedLicense
else
render_api_error!(result[:message], result[:http_status])
end
......@@ -109,7 +109,7 @@ module API
# rubocop: enable CodeReuse/ActiveRecord
desc 'Delete an existing software license policy from a project' do
success Entities::ManagedLicense
success EE::API::Entities::ManagedLicense
end
delete ':id/managed_licenses/:managed_license_id', requirements: { managed_license_id: /.*/ } do
authorize_can_admin!
......
......@@ -6,6 +6,21 @@ module EE
#######################
# Entities extensions #
#######################
module Entities
extend ActiveSupport::Concern
class_methods do
def prepend_entity(klass, with: nil)
if with.nil?
raise ArgumentError, 'You need to pass either the :with or :namespace option!'
end
klass.descendants.each { |descendant| descendant.prepend(with) }
klass.prepend(with)
end
end
end
module UserPublic
extend ActiveSupport::Concern
......@@ -63,6 +78,14 @@ module EE
end
end
module ProtectedBranch
extend ActiveSupport::Concern
prepended do
expose :unprotect_access_levels, using: ::API::Entities::ProtectedRefAccess
end
end
module IssueBasic
extend ActiveSupport::Concern
......@@ -650,6 +673,10 @@ module EE
expose :file_name, :size
expose :file_md5, :file_sha1
end
class ManagedLicense < Grape::Entity
expose :id, :name, :approval_status
end
end
end
end
......@@ -504,7 +504,6 @@ module API
class ProtectedRefAccess < Grape::Entity
expose :access_level
expose :access_level_description do |protected_ref_access|
protected_ref_access.humanize
end
......@@ -514,7 +513,6 @@ module API
expose :name
expose :push_access_levels, using: Entities::ProtectedRefAccess
expose :merge_access_levels, using: Entities::ProtectedRefAccess
expose :unprotect_access_levels, using: Entities::ProtectedRefAccess
end
class ProtectedTag < Grape::Entity
......@@ -1539,19 +1537,6 @@ module API
end
end
def self.prepend_entity(klass, with: nil)
if with.nil?
raise ArgumentError, 'You need to pass either the :with or :namespace option!'
end
klass.descendants.each { |descendant| descendant.prepend(with) }
klass.prepend(with)
end
class ManagedLicense < Grape::Entity
expose :id, :name, :approval_status
end
class ResourceLabelEvent < Grape::Entity
expose :id
expose :user, using: Entities::UserBasic
......@@ -1613,6 +1598,7 @@ module API
end
end
API::Entities.prepend(EE::API::Entities::Entities) # rubocop: disable Cop/InjectEnterpriseEditionModule
API::Entities.prepend_entity(::API::Entities::ApplicationSetting, with: EE::API::Entities::ApplicationSetting)
API::Entities.prepend_entity(::API::Entities::Board, with: EE::API::Entities::Board)
API::Entities.prepend_entity(::API::Entities::Group, with: EE::API::Entities::Group)
......@@ -1626,3 +1612,4 @@ API::Entities.prepend_entity(::API::Entities::ProtectedRefAccess, with: EE::API:
API::Entities.prepend_entity(::API::Entities::UserPublic, with: EE::API::Entities::UserPublic)
API::Entities.prepend_entity(::API::Entities::Variable, with: EE::API::Entities::Variable)
API::Entities.prepend_entity(::API::Entities::Todo, with: EE::API::Entities::Todo)
API::Entities.prepend_entity(::API::Entities::ProtectedBranch, with: EE::API::Entities::ProtectedBranch)
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