Project

General

Profile

Download (826 Bytes) Statistics
| Branch: | Tag: | Revision:

foreman_pipeline / app / models / foreman_pipeline / job_jenkins_project.rb @ 720671b8

1
module ForemanPipeline
2
  class JobJenkinsProject < Katello::Model
3
    self.include_root_in_json = false
4

    
5
    belongs_to :job, :inverse_of => :job_jenkins_projects, :class_name => 'ForemanPipeline::Job'
6
    belongs_to :jenkins_project, :inverse_of => :job_jenkins_projects, :class_name => 'ForemanPipeline::JenkinsProject'
7
    belongs_to :organization
8
    validate :org_membership
9

    
10
    after_destroy :remove_orphaned_projects
11

    
12
    attr_accessible :job_id, :jenkins_project_id
13

    
14
    private
15

    
16
    def org_membership
17
      unless self.job.organization == self.jenkins_project.organization
18
        errors.add(:base, "Cannot add a project from different organization than #{job.organization.name}")
19
      end
20
    end
21

    
22
    def remove_orphaned_projects
23
      JenkinsProject.all.map { |p| p.destroy if p.jobs.empty? }
24
    end
25

    
26
  end
27
end