Project

General

Profile

Revision abf1341e

Added by Ondřej Pražák almost 8 years ago

working widgets

View differences:

app/controllers/foreman_pipeline/api/jobs_controller.rb
9 9
    before_filter :find_job, :only => [:update, :show, :destroy, :set_content_view,
10 10
                                       :set_hostgroup, :set_resource, :available_resources,
11 11
                                       :set_jenkins, :set_environment, :run_job,
12
                                       :add_projects, :remove_projects, :set_paths,
13
                                       :remove_paths, :add_paths, :current_paths, :available_paths]
12
                                       :add_projects, :remove_projects, :set_to_environments,
13
                                       :available_paths]
14 14

  
15 15
    before_filter :load_search_service, :only => [:index]
16 16

  
......
109 109
    param :environment_id, :number, :desc => N_("Environment id which will be set"), :required => true
110 110
    def set_environment
111 111
      @job.environment = Katello::KTEnvironment.find(params[:environment_id])
112
      @job.to_environments = []
112 113
      @job.save!
113 114
      respond_for_show
114 115
    end    
......
126 127
      end
127 128
    end
128 129

  
129
    api :PUT, "/organizations/:organization_id/jobs/:id/add_paths", N_("Add environment paths for job")
130
    param_group :job_id
131
    param :path_ids, Array, :desc => N_("Identifiers of environments which are library's successors in corresponding paths")
132
    def add_paths
133
      @job.path_ids = (@job.path_ids + params[:path_ids]).uniq
134
      @job.save!
135
      respond_for_show
136
    end
137

  
138
    api :PUT, "/organizations/:organization_id/jobs/:id/remove_paths", N_("Remove environment paths for job")
139
    param_group :job_id
140
    param :path_ids, Array, :desc => N_("Identifiers of environments which are library's successors in corresponding paths")
141
    def remove_paths
142
      @job.path_ids = (@job.path_ids - params[:path_ids]).uniq
143
      @job.environment = nil unless @job.environment_in_paths? @job.environment_id
144
      @job.save!
145
      respond_for_show
130
    # api :PUT, "/organizations/:organization_id/jobs/:id/add_paths", N_("Add environment paths for job")
131
    # param_group :job_id
132
    # param :path_ids, Array, :desc => N_("Identifiers of environments which are library's successors in corresponding paths")
133
    def set_to_environments
134
      is_ok = params[:to_environment_ids].map do |new_id|
135
        @job.environment.successors.map(&:id).include? new_id
136
      end.all?
137
      if is_ok
138
        @job.to_environment_ids
139
        @job.save!
140
        respond_for_show
141
      else
142
        fail Katello::HttpErrors::Conflict, "Only Environments that are direct successors of Job's Environment may be set as target Environments." 
143
      end
146 144
    end
147 145

  
148 146
    api :GET, "/organizations/:organization_id/jobs/:id/available_paths", N_("List environment paths available for a job")

Also available in: Unified diff