2020-07-28 23:09:34 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ForkNamespaceEntity < Grape::Entity
|
|
|
|
include ActionView::Helpers::NumberHelper
|
|
|
|
include RequestAwareEntity
|
|
|
|
include MarkupHelper
|
|
|
|
|
|
|
|
expose :id, :name, :description, :visibility, :full_name,
|
2023-06-20 00:43:36 +05:30
|
|
|
:created_at, :updated_at, :avatar_url
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
expose :fork_path do |namespace, options|
|
|
|
|
project_forks_path(options[:project], namespace_key: namespace.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :forked_project_path do |namespace, options|
|
2021-09-04 01:27:46 +05:30
|
|
|
if forked_project = options.dig(:forked_projects, namespace.id)
|
2020-07-28 23:09:34 +05:30
|
|
|
project_path(forked_project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :permission do |namespace, options|
|
2020-11-24 15:15:51 +05:30
|
|
|
membership(options[:current_user], namespace, options[:memberships])&.human_access
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
expose :relative_path do |namespace|
|
2021-04-29 21:17:54 +05:30
|
|
|
group_path(namespace)
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
expose :markdown_description do |namespace|
|
|
|
|
markdown_description(namespace)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2020-11-24 15:15:51 +05:30
|
|
|
def membership(user, object, memberships)
|
2020-07-28 23:09:34 +05:30
|
|
|
return unless user
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
memberships[object.id]
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
|
|
|
|
|
|
|
def markdown_description(namespace)
|
|
|
|
markdown_field(namespace, :description)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
ForkNamespaceEntity.prepend_mod_with('ForkNamespaceEntity')
|