Class: Debci::SelfService

Inherits:
App
  • Object
show all
Includes:
HTMLHelpers, TestHandler, Validators::APTSource
Defined in:
lib/debci/self_service.rb

Defined Under Namespace

Classes: InvalidRequest

Constant Summary

Constants included from HTMLHelpers

HTMLHelpers::ICONS

Instance Method Summary collapse

Methods included from Validators::APTSource

#invalid_extra_apt_sources

Methods included from HTMLHelpers

#expand_pin_packages, #expand_url, #filesize, #history_url, #icon, #package_url, #title_test_trigger_pin

Methods included from TestHandler

#enqueue, #request_batch_tests, #request_tests, #valid_package_name?, #validate_batch_test, #validate_priority, #validate_tests

Methods inherited from App

#get_page_params, get_page_range, #get_page_range, #pagination_params

Instance Method Details

#authenticate!Object



53
54
55
56
57
58
# File 'lib/debci/self_service.rb', line 53

def authenticate!
  return unless session[:user].nil?
  session[:original_url] = request.path
  redirect('/user/login')
  halt
end

#get_job_to_retry(run_id) ⇒ Object



274
275
276
277
278
279
280
281
282
# File 'lib/debci/self_service.rb', line 274

def get_job_to_retry(run_id)
  begin
    job = Debci::Job.find(run_id)
  rescue ActiveRecord::RecordNotFound
    halt(400, "Job ID not known: #{run_id}")
  end
  halt(403, "Package #{job.package.name} is in the REJECT list and cannot be retried") if Debci.reject_list.include?(job.package, suite: job.suite, arch: job.arch)
  job
end

#get_same_pending_jobs(job) ⇒ Object



284
285
286
287
288
289
290
291
292
293
294
# File 'lib/debci/self_service.rb', line 284

def get_same_pending_jobs(job)
  Debci::Job.pending.where(
    package_id: job.package_id,
    suite: job.suite,
    arch: job.arch,
    requestor: job.requestor,
    trigger: job.trigger,
    is_private: job.is_private
  ).select { |j| Set.new(j.pin_packages) == Set.new(job.pin_packages) }
            .select { |j| Set.new(j.extra_apt_sources) == Set.new(job.extra_apt_sources) }
end

#login_callback(uid, username) ⇒ Object



296
297
298
299
300
301
302
303
304
305
# File 'lib/debci/self_service.rb', line 296

def (uid, username)
  user = Debci::User.find_or_create_by!(uid: uid) do |c|
    c.username = username
  end
  user.update(username: username) if user.username != username
  session[:user] = user
  original_url = session[:original_url]
  session.delete(:original_url)
  redirect(original_url || "/user/#{user.username}")
end

#validate_form_submission(package, suite, archs, extra_apt_sources) ⇒ Object

Raises:



198
199
200
201
202
203
204
# File 'lib/debci/self_service.rb', line 198

def validate_form_submission(package, suite, archs, extra_apt_sources)
  raise InvalidRequest.new('Please enter a valid package name') unless valid_package_name?(package)
  raise InvalidRequest.new('Please select a suite') if suite == ''
  raise InvalidRequest.new('Please select an architecture') if archs.empty?
  invalid_extra_apt_sources = invalid_extra_apt_sources(extra_apt_sources)
  raise InvalidRequest.new("Please enter valid extra apt sources: Invalid apt sources: #{invalid_extra_apt_sources}") unless invalid_extra_apt_sources.empty?
end