Class: Projects::Settings::DeployKeysPresenter

Inherits:
Gitlab::View::Presenter::Simple show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/presenters/projects/settings/deploy_keys_presenter.rb

Instance Attribute Summary

Attributes included from Gitlab::View::Presenter::Base

#subject

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods inherited from Gitlab::View::Presenter::Simple

#initialize

Methods included from Gitlab::View::Presenter::Base

#can?, #declarative_policy_delegate, #is_a?, #present, #url_builder, #web_path, #web_url

Methods included from Gitlab::Allowable

#can?

Methods included from Gitlab::Routing

add_helpers, includes_helpers, redirect_legacy_paths, url_helpers

Constructor Details

This class inherits a constructor from Gitlab::View::Presenter::Simple

Instance Method Details

#as_jsonObject


51
52
53
54
55
56
57
58
59
60
# File 'app/presenters/projects/settings/deploy_keys_presenter.rb', line 51

def as_json
  serializer = DeployKeySerializer.new # rubocop: disable CodeReuse/Serializer
  opts = { user: current_user, project: project, readable_project_ids: readable_project_ids }

  {
    enabled_keys: serializer.represent(enabled_keys, opts),
    available_project_keys: serializer.represent(available_project_keys, opts),
    public_keys: serializer.represent(available_public_keys, opts)
  }
end

#available_keysObject


23
24
25
26
27
28
29
30
# File 'app/presenters/projects/settings/deploy_keys_presenter.rb', line 23

def available_keys
  strong_memoize(:available_keys) do
    current_user
      .accessible_deploy_keys
      .id_not_in(enabled_keys.select(:id))
      .with_projects
  end
end

#available_project_keysObject


32
33
34
35
36
37
38
39
# File 'app/presenters/projects/settings/deploy_keys_presenter.rb', line 32

def available_project_keys
  strong_memoize(:available_project_keys) do
    current_user
      .project_deploy_keys
      .id_not_in(enabled_keys.select(:id))
      .with_projects
  end
end

#available_public_keysObject


41
42
43
44
45
46
47
48
49
# File 'app/presenters/projects/settings/deploy_keys_presenter.rb', line 41

def available_public_keys
  strong_memoize(:available_public_keys) do
    DeployKey
      .are_public
      .id_not_in(enabled_keys.select(:id))
      .id_not_in(available_project_keys.select(:id))
      .with_projects
  end
end

#enabled_keysObject


17
18
19
20
21
# File 'app/presenters/projects/settings/deploy_keys_presenter.rb', line 17

def enabled_keys
  strong_memoize(:enabled_keys) do
    project.deploy_keys.with_projects
  end
end

#form_partial_pathObject


66
67
68
# File 'app/presenters/projects/settings/deploy_keys_presenter.rb', line 66

def form_partial_path
  'shared/deploy_keys/project_group_form'
end

#new_keyObject


13
14
15
# File 'app/presenters/projects/settings/deploy_keys_presenter.rb', line 13

def new_key
  @key ||= DeployKey.new.tap { |dk| dk.deploy_keys_projects.build }
end

#to_partial_pathObject


62
63
64
# File 'app/presenters/projects/settings/deploy_keys_presenter.rb', line 62

def to_partial_path
  '../../shared/deploy_keys/index'
end