Project

General

Profile

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

foreman_pipeline / app / models / foreman_pipeline / job_jenkins_project.rb @ be52ca64

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
    private 
13

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

    
20
    def remove_orphaned_projects
21
      JenkinsProject.find(:all).map { |p| p.destroy if p.jobs.empty? }
22
    end
23
    
24
  end
25
end