Class: V1::AuditsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/v1/audits_controller.rb

Instance Attribute Summary

Attributes inherited from ApplicationController

#current_user

Instance Method Summary collapse

Methods inherited from ApplicationController

#fake_user

Instance Method Details

#createObject


15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/v1/audits_controller.rb', line 15

def create
  AuditsPolicy.new(current_user).authorize! :create?

  packages = Package.stored
  audit = Audit.create!(user: current_user, packages: packages.count)
  packages.each do |package|
    AuditFixityCheckJob.perform_later(package: package, user: current_user, audit: audit)
  end
  head 201, location: v1_audit_path(audit)
end

#indexObject


5
6
7
8
9
# File 'app/controllers/v1/audits_controller.rb', line 5

def index
  policy = AuditsPolicy.new(current_user)
  policy.authorize! :index?
  @audits = policy.resolve.map {|audit| AuditPresenter.new(audit, expand: expand?) }
end

#showObject


11
12
13
# File 'app/controllers/v1/audits_controller.rb', line 11

def show
  @audit = AuditPresenter.new(Audit.find(params[:id]).tap {|a| AuditPolicy.new(current_user, a).authorize! :show? }, expand: expand?)
end