mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-21 15:54:22 +01:00
Merge branch 'dev' for release 5.5.2
This commit is contained in:
commit
b07d70fbdd
@ -1,5 +1,9 @@
|
|||||||
# Changelog Fab-manager
|
# Changelog Fab-manager
|
||||||
|
|
||||||
|
## v5.5.2 2022 November 16
|
||||||
|
|
||||||
|
- Fix a bug: unable to export statistics
|
||||||
|
|
||||||
## v5.5.1 2022 November 15
|
## v5.5.1 2022 November 15
|
||||||
|
|
||||||
- Fix a bug: free disk space not verified in some cases
|
- Fix a bug: free disk space not verified in some cases
|
||||||
|
@ -8,16 +8,17 @@ class API::ExportsController < API::ApiController
|
|||||||
|
|
||||||
def download
|
def download
|
||||||
authorize @export
|
authorize @export
|
||||||
mime_type = if @export.extension == 'xlsx'
|
mime_type = case @export.extension
|
||||||
|
when 'xlsx'
|
||||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||||
elsif @export.extension == 'csv'
|
when 'csv'
|
||||||
'text/csv'
|
'text/csv'
|
||||||
else
|
else
|
||||||
'application/octet-stream'
|
'application/octet-stream'
|
||||||
end
|
end
|
||||||
|
|
||||||
if FileTest.exist?(@export.file)
|
if FileTest.exist?(@export.file)
|
||||||
send_file File.join(Rails.root, @export.file),
|
send_file Rails.root.join(@export.file),
|
||||||
type: mime_type,
|
type: mime_type,
|
||||||
disposition: 'attachment'
|
disposition: 'attachment'
|
||||||
else
|
else
|
||||||
@ -28,14 +29,7 @@ class API::ExportsController < API::ApiController
|
|||||||
def status
|
def status
|
||||||
authorize Export
|
authorize Export
|
||||||
|
|
||||||
exports = Export.where(
|
export = ExportService.last_export("#{params[:category]}/#{params[:type]}", params[:query], params[:key], params[:extension])
|
||||||
category: params[:category],
|
|
||||||
export_type: params[:type],
|
|
||||||
query: params[:query],
|
|
||||||
key: params[:key],
|
|
||||||
extension: params[:extension]
|
|
||||||
)
|
|
||||||
export = retrieve_last_export(exports, params[:category], params[:type])
|
|
||||||
|
|
||||||
if export.nil? || !FileTest.exist?(export.file)
|
if export.nil? || !FileTest.exist?(export.file)
|
||||||
render json: { exists: false, id: nil }, status: :ok
|
render json: { exists: false, id: nil }, status: :ok
|
||||||
@ -46,41 +40,6 @@ class API::ExportsController < API::ApiController
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def retrieve_last_export(export, category, type)
|
|
||||||
case category
|
|
||||||
when 'users'
|
|
||||||
case type
|
|
||||||
when 'subscriptions'
|
|
||||||
export = export.where('created_at > ?', Subscription.maximum('updated_at'))
|
|
||||||
when 'reservations'
|
|
||||||
export = export.where('created_at > ?', Reservation.maximum('updated_at'))
|
|
||||||
when 'members'
|
|
||||||
export = export.where('created_at > ?', User.members.maximum('updated_at'))
|
|
||||||
else
|
|
||||||
raise ArgumentError, "Unknown export users/#{type}"
|
|
||||||
end
|
|
||||||
when 'availabilities'
|
|
||||||
case type
|
|
||||||
when 'index'
|
|
||||||
export = export.where('created_at > ?', [Availability.maximum('updated_at'), Reservation.maximum('updated_at')].max)
|
|
||||||
else
|
|
||||||
raise ArgumentError, "Unknown type availabilities/#{type}"
|
|
||||||
end
|
|
||||||
when 'accounting'
|
|
||||||
case type
|
|
||||||
when 'acd'
|
|
||||||
export = export.where('created_at > ?', Invoice.maximum('updated_at'))
|
|
||||||
when 'vat'
|
|
||||||
export = export.where('created_at > ?', Invoice.maximum('updated_at'))
|
|
||||||
else
|
|
||||||
raise ArgumentError, "Unknown type accounting/#{type}"
|
|
||||||
end
|
|
||||||
else
|
|
||||||
raise ArgumentError, "Unknown category #{category}"
|
|
||||||
end
|
|
||||||
export.last
|
|
||||||
end
|
|
||||||
|
|
||||||
def set_export
|
def set_export
|
||||||
@export = Export.find(params[:id])
|
@export = Export.find(params[:id])
|
||||||
end
|
end
|
||||||
|
@ -19,7 +19,8 @@ class API::StatisticsController < API::ApiController
|
|||||||
def export_#{path} # def export_account
|
def export_#{path} # def export_account
|
||||||
authorize :statistic, :export_#{path}? # authorize :statistic, :export_account?
|
authorize :statistic, :export_#{path}? # authorize :statistic, :export_account?
|
||||||
|
|
||||||
@export = Statistics::QueryService.export('#{path}', params) # @export = Statistics::QueryService.export('account', params)
|
@export = Statistics::QueryService.export('#{path}', params, # @export = Statistics::QueryService.export('account', params,
|
||||||
|
current_user)
|
||||||
if @export.is_a?(Export)
|
if @export.is_a?(Export)
|
||||||
if @export.save
|
if @export.save
|
||||||
render json: { export_id: @export.id }, status: :ok
|
render json: { export_id: @export.id }, status: :ok
|
||||||
@ -32,13 +33,13 @@ class API::StatisticsController < API::ApiController
|
|||||||
disposition: 'attachment'
|
disposition: 'attachment'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
}, __FILE__, __LINE__ - 22
|
}, __FILE__, __LINE__ - 23
|
||||||
end
|
end
|
||||||
|
|
||||||
def export_global
|
def export_global
|
||||||
authorize :statistic, :export_global?
|
authorize :statistic, :export_global?
|
||||||
|
|
||||||
@export = Statistics::QueryService.export(global, params)
|
@export = Statistics::QueryService.export('global', params, current_user)
|
||||||
if @export.is_a?(Export)
|
if @export.is_a?(Export)
|
||||||
if @export.save
|
if @export.save
|
||||||
render json: { export_id: @export.id }, status: :ok
|
render json: { export_id: @export.id }, status: :ok
|
||||||
|
@ -4,16 +4,20 @@
|
|||||||
class ExportService
|
class ExportService
|
||||||
class << self
|
class << self
|
||||||
# Check if the last export of the provided type is still accurate or if it must be regenerated
|
# Check if the last export of the provided type is still accurate or if it must be regenerated
|
||||||
def last_export(type)
|
def last_export(type, query = nil, key = nil, extension = nil)
|
||||||
case type
|
case type
|
||||||
when 'users/members'
|
when 'users/members'
|
||||||
last_export_members
|
last_export_members(query, key, extension)
|
||||||
when 'users/reservations'
|
when 'users/reservations'
|
||||||
last_export_reservations
|
last_export_reservations(query, key, extension)
|
||||||
when 'users/subscription'
|
when 'users/subscription'
|
||||||
last_export_subscriptions
|
last_export_subscriptions(query, key, extension)
|
||||||
|
when 'availabilities/index'
|
||||||
|
last_export_availabilities(query, key, extension)
|
||||||
|
when %r{accounting/.*}
|
||||||
|
last_export_accounting(type, query, key, extension)
|
||||||
when %r{statistics/.*}
|
when %r{statistics/.*}
|
||||||
last_export_statistics(type.split('/')[1])
|
last_export_statistics(type, query, key, extension)
|
||||||
else
|
else
|
||||||
raise TypeError "unknown export type: #{type}"
|
raise TypeError "unknown export type: #{type}"
|
||||||
end
|
end
|
||||||
@ -21,19 +25,29 @@ class ExportService
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def last_export_subscriptions
|
def query_last_export(category, export_type, query = nil, key = nil, extension = nil)
|
||||||
Export.where(category: 'users', export_type: 'subscriptions')
|
export = Export.where(category: category, export_type: export_type)
|
||||||
|
export.where(query: query) unless query.nil?
|
||||||
|
export.where(key: key) unless key.nil?
|
||||||
|
export.where(extension: extension) unless extension.nil?
|
||||||
|
export
|
||||||
|
end
|
||||||
|
|
||||||
|
def last_export_subscriptions(query, key, extension)
|
||||||
|
query_last_export('users', 'subscriptions', query, key, extension)
|
||||||
.where('created_at > ?', Subscription.maximum('updated_at'))
|
.where('created_at > ?', Subscription.maximum('updated_at'))
|
||||||
.last
|
.order(created_at: :desc)
|
||||||
|
.first
|
||||||
end
|
end
|
||||||
|
|
||||||
def last_export_reservations
|
def last_export_reservations(query, key, extension)
|
||||||
Export.where(category: 'users', export_type: 'reservations')
|
query_last_export('users', 'reservations', query, key, extension)
|
||||||
.where('created_at > ?', Reservation.maximum('updated_at'))
|
.where('created_at > ?', Reservation.maximum('updated_at'))
|
||||||
.last
|
.order(created_at: :desc)
|
||||||
|
.first
|
||||||
end
|
end
|
||||||
|
|
||||||
def last_export_members
|
def last_export_members(query, key, extension)
|
||||||
last_update = [
|
last_update = [
|
||||||
User.members.maximum('updated_at'),
|
User.members.maximum('updated_at'),
|
||||||
Profile.where(user_id: User.members).maximum('updated_at'),
|
Profile.where(user_id: User.members).maximum('updated_at'),
|
||||||
@ -42,14 +56,30 @@ class ExportService
|
|||||||
Subscription.maximum('updated_at') || DateTime.current
|
Subscription.maximum('updated_at') || DateTime.current
|
||||||
].max
|
].max
|
||||||
|
|
||||||
Export.where(category: 'users', export_type: 'members')
|
query_last_export('users', 'members', query, key, extension)
|
||||||
.where('created_at > ?', last_update)
|
.where('created_at > ?', last_update)
|
||||||
.last
|
.order(created_at: :desc)
|
||||||
|
.first
|
||||||
end
|
end
|
||||||
|
|
||||||
def last_export_statistics(type)
|
def last_export_availabilities(query, key, extension)
|
||||||
Export.where(category: 'statistics', export_type: type, query: params[:body], key: params[:type_key])
|
query_last_export('availabilities', 'index', query, key, extension)
|
||||||
.last
|
.where('created_at > ?', [Availability.maximum('updated_at'), Reservation.maximum('updated_at')].max)
|
||||||
|
.order(created_at: :desc)
|
||||||
|
.first
|
||||||
|
end
|
||||||
|
|
||||||
|
def last_export_accounting(type, query, key, extension)
|
||||||
|
query_last_export('accounting', type.split('/')[1], query, key, extension)
|
||||||
|
.where('created_at > ?', Invoice.maximum('updated_at'))
|
||||||
|
.order(created_at: :desc)
|
||||||
|
.first
|
||||||
|
end
|
||||||
|
|
||||||
|
def last_export_statistics(type, query, key, extension)
|
||||||
|
query_last_export('statistics', type.split('/')[1], query, key, extension)
|
||||||
|
.order(created_at: :desc)
|
||||||
|
.first
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -21,8 +21,8 @@ class Statistics::QueryService
|
|||||||
results
|
results
|
||||||
end
|
end
|
||||||
|
|
||||||
def export(statistic_index, params)
|
def export(statistic_index, params, current_user)
|
||||||
export = ExportService.last_export("statistics/#{statistic_index}")
|
export = ExportService.last_export("statistics/#{statistic_index}", params[:body], params[:type_key])
|
||||||
if export.nil? || !FileTest.exist?(export.file)
|
if export.nil? || !FileTest.exist?(export.file)
|
||||||
Export.new(category: 'statistics',
|
Export.new(category: 'statistics',
|
||||||
export_type: statistic_index,
|
export_type: statistic_index,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "fab-manager",
|
"name": "fab-manager",
|
||||||
"version": "5.5.1",
|
"version": "5.5.2",
|
||||||
"description": "Fab-manager is the FabLab management solution. It provides a comprehensive, web-based, open-source tool to simplify your administrative tasks and your marker's projects.",
|
"description": "Fab-manager is the FabLab management solution. It provides a comprehensive, web-based, open-source tool to simplify your administrative tasks and your marker's projects.",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"fablab",
|
"fablab",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user