diff --git a/app/controllers/v1/audits_controller.rb b/app/controllers/v1/audits_controller.rb index b6eb13c9..66e58e22 100644 --- a/app/controllers/v1/audits_controller.rb +++ b/app/controllers/v1/audits_controller.rb @@ -17,16 +17,8 @@ def show def create collection_policy.new(current_user).authorize! :new? + RepositoryAuditJob.perform_later(user: current_user) - packages = Package.stored - audit = Audit.new(user: current_user, packages: packages.count) - - resource_policy.new(current_user, audit).authorize! :save? - audit.save - - packages.each do |package| - AuditFixityCheckJob.perform_later(package: package, user: current_user, audit: audit) - end head 201, location: v1_audit_path(audit) end diff --git a/app/jobs/repository_audit_job.rb b/app/jobs/repository_audit_job.rb new file mode 100644 index 00000000..3f318724 --- /dev/null +++ b/app/jobs/repository_audit_job.rb @@ -0,0 +1,9 @@ +class RepositoryAuditJob < ApplicationJob + def perform(user: User.system_user) + packages = Package.stored + audit = Audit.create(user: user, packages: packages.count) + packages.each do |package| + AuditFixityCheckJob.perform_later(package: package, user: user, audit: audit) + end + end +end \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb index a28ff873..6e15a24f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -12,6 +12,10 @@ class User < ApplicationRecord # Assign an API key after_initialize :add_key, on: :create + def self.system_user + new(username: '(system)', email: Chipmunk.config["admin_email"]) + end + def api_key @api_key ||= if [nil, "x"].include?(api_key_digest) Keycard::DigestKey.new diff --git a/config/settings.yml b/config/settings.yml index e2f7fdcd..4d4b1b2e 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -5,3 +5,6 @@ allow_impersonation: false # Session inactivity timeout; default to one hour session_timeout: 3600 + +# Sys Admin email (used for system audit) +admin_email: darkblue-notification@umich.edu