summaryrefslogtreecommitdiff
path: root/app/serializers/deploy_key_entity.rb
blob: 2678f99510c0e80edc4c091488e794b204925fbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
  expose :created_at
  expose :updated_at
  expose :deploy_keys_projects, using: DeployKeysProjectEntity do |deploy_key|
    deploy_key.deploy_keys_projects
              .without_project_deleted
              .select { |deploy_key_project| Ability.allowed?(options[:user], :read_project, deploy_key_project.project) }
  end
  expose :can_edit

  private

  def can_edit
    Ability.allowed?(options[:user], :update_deploy_key, object)
  end
end