mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-18 07:52:23 +01:00
accounting archive: insert code checksum and previous archive checksum
This commit is contained in:
parent
55ae979213
commit
6e274afe3b
@ -1,4 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
require 'version'
|
||||
|
||||
# API Controller to get the fab-manager version
|
||||
class API::VersionController < API::ApiController
|
||||
@ -6,8 +7,7 @@ class API::VersionController < API::ApiController
|
||||
|
||||
def show
|
||||
authorize :version
|
||||
package = File.read('package.json')
|
||||
version = JSON.parse(package)['version']
|
||||
render json: { version: version }, status: :ok
|
||||
|
||||
render json: { version: Version.current }, status: :ok
|
||||
end
|
||||
end
|
||||
|
@ -1,5 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'checksum'
|
||||
require 'version'
|
||||
|
||||
# AccountingPeriod is a period of N days (N > 0) which as been closed by an admin
|
||||
# to prevent writing new accounting lines (invoices & refunds) during this period of time.
|
||||
class AccountingPeriod < ActiveRecord::Base
|
||||
@ -26,14 +29,27 @@ class AccountingPeriod < ActiveRecord::Base
|
||||
private
|
||||
|
||||
def to_json_archive(invoices)
|
||||
previous_file = previous_period&.archive_file
|
||||
code_checksum = Checksum.code
|
||||
last_archive_checksum = Checksum.file(previous_file)
|
||||
ApplicationController.new.view_context.render(
|
||||
partial: 'archive/accounting',
|
||||
locals: { invoices: invoices },
|
||||
locals: {
|
||||
invoices: invoices,
|
||||
code_checksum: code_checksum,
|
||||
last_archive_checksum: last_archive_checksum,
|
||||
previous_file: previous_file,
|
||||
software_version: Version.current
|
||||
},
|
||||
formats: [:json],
|
||||
handlers: [:jbuilder]
|
||||
)
|
||||
end
|
||||
|
||||
def previous_period
|
||||
AccountingPeriod.order(closed_at: :desc).limit(2).last
|
||||
end
|
||||
|
||||
def archive_closed_data
|
||||
data = Invoice.where('created_at >= :start_date AND created_at < :end_date', start_date: start_at, end_date: end_at)
|
||||
.includes(:invoice_items)
|
||||
|
@ -1,4 +1,5 @@
|
||||
json.array!(invoices) do |invoice|
|
||||
json.invoices do
|
||||
json.array!(invoices) do |invoice|
|
||||
json.extract! invoice, :id, :stp_invoice_id, :created_at, :reference
|
||||
json.total number_to_currency(invoice.total / 100.0)
|
||||
json.invoiced do
|
||||
@ -46,4 +47,16 @@ json.array!(invoices) do |invoice|
|
||||
json.extract! item, :id, :stp_invoice_item_id, :created_at, :description
|
||||
json.amount number_to_currency(item.amount / 100.0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
json.software do
|
||||
json.name 'Fab-Manager'
|
||||
json.version software_version
|
||||
json.code_checksum code_checksum
|
||||
end
|
||||
|
||||
json.previous_archive do
|
||||
json.filename previous_file
|
||||
json.checksum last_archive_checksum
|
||||
end
|
||||
|
45
lib/checksum.rb
Normal file
45
lib/checksum.rb
Normal file
@ -0,0 +1,45 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# provide checksums for archiving control
|
||||
class Checksum
|
||||
class << self
|
||||
def code
|
||||
dir = Dir.pwd
|
||||
|
||||
files = children_files("#{dir}/*")
|
||||
.concat(children_files("#{dir}/app/**/*"))
|
||||
.concat(children_files("#{dir}/bin/**/*"))
|
||||
.concat(children_files("#{dir}/config/**/*"))
|
||||
.concat(children_files("#{dir}/db/**/*"))
|
||||
.concat(children_files("#{dir}/doc/**/*"))
|
||||
.concat(children_files("#{dir}/docker/**/*"))
|
||||
.concat(children_files("#{dir}/lib/**/*"))
|
||||
.concat(children_files("#{dir}/node_modules/**/*"))
|
||||
.concat(children_files("#{dir}/plugins/**/*"))
|
||||
.concat(children_files("#{dir}/provision/**/*"))
|
||||
.concat(children_files("#{dir}/scripts/**/*"))
|
||||
.concat(children_files("#{dir}/test/**/*"))
|
||||
.concat(children_files("#{dir}/vendor/**/*"))
|
||||
|
||||
content = files.map { |f| File.read(f) }.join
|
||||
|
||||
sha256 = Digest::SHA256.new
|
||||
sha256.hexdigest content
|
||||
end
|
||||
|
||||
def file(path)
|
||||
return unless File.exist?(path)
|
||||
|
||||
content = File.read(path)
|
||||
|
||||
sha256 = Digest::SHA256.new
|
||||
sha256.hexdigest content
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def children_files(path)
|
||||
Dir[path].reject { |f| File.directory?(f) }
|
||||
end
|
||||
end
|
||||
end
|
9
lib/version.rb
Normal file
9
lib/version.rb
Normal file
@ -0,0 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# retrieve the current Fab-manager version
|
||||
class Version
|
||||
def self.current
|
||||
package = File.read('package.json')
|
||||
JSON.parse(package)['version']
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user