Welcome to mirror list, hosted at ThFree Co, Russian Federation.

fork_namespace_entity.rb « serializers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 997abb0f148fa4a372b0b3e98646086404a08ebe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 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 = options.dig(:forked_projects, namespace.id)
      project_path(forked_project)
    end
  end

  expose :permission do |namespace, options|
    membership(options[:current_user], namespace, options[:memberships])&.human_access
  end

  expose :relative_path do |namespace|
    group_path(namespace)
  end

  expose :markdown_description do |namespace|
    markdown_description(namespace)
  end

  private

  # rubocop: disable CodeReuse/ActiveRecord
  def membership(user, object, memberships)
    return unless user

    memberships[object.id]
  end
  # rubocop: enable CodeReuse/ActiveRecord

  def markdown_description(namespace)
    markdown_field(namespace, :description)
  end
end

ForkNamespaceEntity.prepend_mod_with('ForkNamespaceEntity')