gitlab-org--gitlab-foss/app/serializers/deploy_key_entity.rb

27 lines
835 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2017-03-24 06:11:36 -04:00
class DeployKeyEntity < Grape::Entity
expose :id
expose :user_id
expose :title
expose :fingerprint
expose :destroyed_when_orphaned?, as: :destroyed_when_orphaned
expose :almost_orphaned?, as: :almost_orphaned
2017-03-24 06:11:36 -04:00
expose :created_at
expose :updated_at
expose :deploy_keys_projects, using: DeployKeysProjectEntity do |deploy_key|
deploy_key.deploy_keys_projects.select do |deploy_key_project|
!deploy_key_project.project&.pending_delete? &&
Ability.allowed?(options[:user], :read_project, deploy_key_project.project)
end
2017-03-24 06:11:36 -04:00
end
expose :can_edit
private
def can_edit
Ability.allowed?(options[:user], :update_deploy_key, object) ||
Ability.allowed?(options[:user], :update_deploy_keys_project, object.deploy_keys_project_for(options[:project]))
end
2017-03-24 06:11:36 -04:00
end