Class: DeployKey

Inherits:
Key show all
Includes:
FromUnion, IgnorableColumns
Defined in:
app/models/deploy_key.rb

Constant Summary

Constants included from Expirable

Expirable::DAYS_TO_EXPIRE

Instance Method Summary collapse

Methods inherited from Key

#add_to_authorized_keys, #can_delete?, #key=, #post_create_hook, #post_destroy_hook, #projects, #public_key, #publishable_key, #refresh_user_cache, regular_keys, #remove_from_authorized_keys, #shell_id, #update_last_used_at

Methods included from Expirable

#expired?, #expires?, #expires_soon?

Methods included from AfterCommitQueue

#run_after_commit, #run_after_commit_or_now

Methods inherited from ApplicationRecord

at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, without_order

Instance Method Details

#almost_orphaned?Boolean

Returns:

  • (Boolean)

26
27
28
# File 'app/models/deploy_key.rb', line 26

def almost_orphaned?
  self.deploy_keys_projects.size == 1
end

#can_push_to?(project) ⇒ Boolean

Returns:

  • (Boolean)

42
43
44
# File 'app/models/deploy_key.rb', line 42

def can_push_to?(project)
  !!deploy_keys_project_for(project)&.can_push?
end

#deploy_keys_project_for(project) ⇒ Object


46
47
48
49
50
51
52
# File 'app/models/deploy_key.rb', line 46

def deploy_keys_project_for(project)
  if association(:deploy_keys_projects).loaded?
    deploy_keys_projects.find { |dkp| dkp.project_id.eql?(project&.id) }
  else
    deploy_keys_projects.find_by(project: project)
  end
end

#destroyed_when_orphaned?Boolean

Returns:

  • (Boolean)

30
31
32
# File 'app/models/deploy_key.rb', line 30

def destroyed_when_orphaned?
  self.private?
end

#has_access_to?(project) ⇒ Boolean

Returns:

  • (Boolean)

38
39
40
# File 'app/models/deploy_key.rb', line 38

def has_access_to?(project)
  deploy_keys_project_for(project).present?
end

#orphaned?Boolean

Returns:

  • (Boolean)

22
23
24
# File 'app/models/deploy_key.rb', line 22

def orphaned?
  self.deploy_keys_projects.empty?
end

#private?Boolean

Returns:

  • (Boolean)

18
19
20
# File 'app/models/deploy_key.rb', line 18

def private?
  !public?
end

#projects_with_write_accessObject


54
55
56
# File 'app/models/deploy_key.rb', line 54

def projects_with_write_access
  Project.with_route.where(id: deploy_keys_projects.with_write_access.select(:project_id))
end

#userObject


34
35
36
# File 'app/models/deploy_key.rb', line 34

def user
  super || User.ghost
end