2020-07-09 00:09:11 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ForkNamespaceEntity < Grape::Entity
|
|
|
|
include ActionView::Helpers::NumberHelper
|
|
|
|
include RequestAwareEntity
|
|
|
|
include MarkupHelper
|
|
|
|
|
|
|
|
expose :id, :name, :description, :visibility, :full_name,
|
|
|
|
:created_at, :updated_at, :avatar_url
|
|
|
|
|
|
|
|
expose :fork_path do |namespace, options|
|
|
|
|
project_forks_path(options[:project], namespace_key: namespace.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :forked_project_path do |namespace, options|
|
|
|
|
if forked_project = namespace.find_fork_of(options[:project])
|
|
|
|
project_path(forked_project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :permission do |namespace, options|
|
2020-08-21 00:10:44 +00:00
|
|
|
membership(options[:current_user], namespace, options[:memberships])&.human_access
|
2020-07-09 00:09:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
expose :relative_path do |namespace|
|
2021-03-23 18:09:05 +00:00
|
|
|
group_path(namespace)
|
2020-07-09 00:09:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
expose :markdown_description do |namespace|
|
|
|
|
markdown_description(namespace)
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :can_create_project do |namespace, options|
|
|
|
|
options[:current_user].can?(:create_projects, namespace)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2020-08-21 00:10:44 +00:00
|
|
|
def membership(user, object, memberships)
|
2020-07-09 00:09:11 +00:00
|
|
|
return unless user
|
|
|
|
|
2020-08-21 00:10:44 +00:00
|
|
|
memberships[object.id]
|
2020-07-09 00:09:11 +00:00
|
|
|
end
|
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
|
|
|
|
|
|
|
def markdown_description(namespace)
|
|
|
|
markdown_field(namespace, :description)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
ForkNamespaceEntity.prepend_if_ee('EE::ForkNamespaceEntity')
|