Skip to content

Commit

Permalink
add audit functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
blancoj committed Mar 16, 2021
1 parent e614a09 commit 25a51ba
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
10 changes: 1 addition & 9 deletions app/controllers/v1/audits_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions app/jobs/repository_audit_job.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: [email protected]

0 comments on commit 25a51ba

Please sign in to comment.