Project

General

Profile

Revision 937eb715

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

loading environments simplified

View differences:

app/controllers/foreman_pipeline/api/jobs_controller.rb
79 79
    param_group :job_id
80 80
    param :content_view_id, :number, :desc => N_("Content view id which will be set"), :required => true
81 81
    def set_content_view
82
      @job.content_view = Katello::ContentView.find(params[:content_view_id])
82
      cv = Katello::ContentView.find(params[:content_view_id])
83
      fail Katello::HttpErrors::Conflict, "Only non-composite views are accepted" if cv.composite?
84
      @job.content_view = cv
83 85
      @job.save!
84 86
      respond_for_show
85 87
    end
......
131 133
    param_group :job_id
132 134
    param :path_ids, Array, :desc => N_("Identifiers of environments which are successors of job's environment")
133 135
    def set_to_environments
136
      fail Katello::HttpErrors::Conflict, "Job's environment must be assigned before setting 'to environments'." if @job.environment.nil?
137
      fail Katello::HttpErrors::Conflict, "Job's environment does not have any successors" if @job.environment.successors.empty?
134 138
      is_ok = params[:to_environment_ids].map do |new_id|
135 139
        @job.environment.successors.map(&:id).include? new_id
136 140
      end.all?
......
146 150
    api :GET, "/organizations/:organization_id/jobs/:id/available_paths", N_("List environment paths available for a job")
147 151
    param_group :job_id
148 152
    def available_paths
149
      available = @job.environment.full_paths rescue []
150
      
151
      paths = available.inject([]) do |result, path|
152
        result << { :environments => path }
153
      available = []
154
      paths = []
155
      if params[:all_paths]
156
        available = @organization.readable_promotion_paths
157
        paths = available.inject([]) do |result, path|
158
          result << { :environments => [@organization.library] + path }
159
        end
160
        paths = [{ :environments => [@organization.library] }] if paths.empty?
161
      else
162
        available = @job.environment.full_paths rescue []
163
        paths = available.inject([]) do |result, path|
164
          result << { :environments => path }
165
        end
166
        paths = [{ :environments => [] }] if paths.empty?
153 167
      end
154
      paths = [{ :environments => [] }] if paths.empty?
155

  
168
      
156 169
      collection = {
157 170
        :results => paths,
158 171
        :total => paths.size,
......
174 187
    def run_job      
175 188
      if @job.manual_trigger
176 189
        task = async_task(::Actions::ForemanPipeline::Job::RunJobManually, @job)
177
        render :nothing => true            
190
        render :nothing => true
178 191
      else
179 192
        fail ::Katello::HttpErrors::Forbidden, "Running manually not allowed for Job: #{@job.name}. Try setting it's :manual_trigger property."
180 193
      end
......
216 229
      if rollback[:occured]
217 230
        fail ::Katello::HttpErrors::NotFound, "Could not retrieve build params for Jenkins project: #{rollback[:project_name]}"
218 231
      else
219
        respond_for_show        
232
        respond_for_show
220 233
      end
221 234
    end
222 235

  

Also available in: Unified diff