debian-mirror-gitlab/app/presenters/projects/settings/deploy_keys_presenter.rb

62 lines
1.6 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module Projects
module Settings
class DeployKeysPresenter < Gitlab::View::Presenter::Simple
presents :project
delegate :size, to: :enabled_keys, prefix: true
delegate :size, to: :available_project_keys, prefix: true
delegate :size, to: :available_public_keys, prefix: true
def new_key
2018-03-17 18:26:18 +05:30
@key ||= DeployKey.new.tap { |dk| dk.deploy_keys_projects.build }
2017-08-17 22:00:37 +05:30
end
def enabled_keys
2019-10-12 21:52:04 +05:30
project.deploy_keys
2017-08-17 22:00:37 +05:30
end
def available_keys
2019-10-12 21:52:04 +05:30
current_user
.accessible_deploy_keys
.id_not_in(enabled_keys.select(:id))
.with_projects
2017-08-17 22:00:37 +05:30
end
def available_project_keys
2019-10-12 21:52:04 +05:30
current_user
.project_deploy_keys
.id_not_in(enabled_keys.select(:id))
.with_projects
2017-08-17 22:00:37 +05:30
end
def available_public_keys
2019-10-12 21:52:04 +05:30
DeployKey
.are_public
.id_not_in(enabled_keys.select(:id))
.id_not_in(available_project_keys.select(:id))
.with_projects
2017-08-17 22:00:37 +05:30
end
def as_json
2018-12-05 23:21:45 +05:30
serializer = DeployKeySerializer.new # rubocop: disable CodeReuse/Serializer
2017-08-17 22:00:37 +05:30
opts = { user: current_user }
{
2019-10-12 21:52:04 +05:30
enabled_keys: serializer.represent(enabled_keys.with_projects, opts),
2017-08-17 22:00:37 +05:30
available_project_keys: serializer.represent(available_project_keys, opts),
public_keys: serializer.represent(available_public_keys, opts)
}
end
def to_partial_path
'projects/deploy_keys/index'
end
def form_partial_path
'projects/deploy_keys/form'
end
end
end
end