1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-17 06:52:27 +01:00

improved version check

- use referer from client when available
- save uuid returned by hub
- send uuid to hub on version check
- check the version on each startup to prevent wrong sync
- also: do not save a setting on API update if it has not changed
This commit is contained in:
Sylvain 2020-04-07 17:53:19 +02:00
parent a4cd6e4dc7
commit de9c224a92
11 changed files with 39 additions and 10 deletions

View File

@ -1,5 +1,6 @@
# Changelog Fab-manager
- Improved version check
- Improved setup script for installations without nginx
- Changed some default values for new installations
- Updated documentation

View File

@ -39,9 +39,10 @@ Application.Controllers.controller('ApplicationController', ['$rootScope', '$sco
getNotifications();
// Fab-manager's app-version
if (user.role === 'admin') {
return $scope.version = Version.get();
// get the version
$scope.version = Version.get({origin: window.location.origin});
} else {
return $scope.version = { current: '' };
$scope.version = { current: '' };
}
}
};

View File

@ -1,5 +1,10 @@
'use strict';
Application.Services.factory('Version', ['$resource', function ($resource) {
return $resource('/api/version');
return $resource('/api/version/:origin',
{ origin: '@origin' }, {
query: {
isArray: false
}
});
}]);

View File

@ -11,6 +11,8 @@ class API::SettingsController < API::ApiController
def update
authorize Setting
@setting = Setting.find_or_initialize_by(name: params[:name])
render status: :not_modified and return if setting_params[:value] == @setting.value
if @setting.save && @setting.history_values.create(value: setting_params[:value], invoicing_profile: current_user.invoicing_profile)
SettingService.new.after_update(@setting)
render status: :ok

View File

@ -1,4 +1,5 @@
# frozen_string_literal: true
require 'version'
# API Controller to get the Fab-manager version
@ -7,6 +8,13 @@ class API::VersionController < API::ApiController
def show
authorize :version
# save the origin
origin = Setting.find_or_create_by(name: 'origin')
if origin.value != params[:origin]
origin.value = params[:origin]
origin.save!
end
# get the last version
update_status = Setting.find_by(name: 'hub_last_version')&.value || '{}'
json = JSON.parse(update_status)

View File

@ -73,7 +73,9 @@ class Setting < ApplicationRecord
fab_analytics
link_name
home_content
home_css] }
home_css
origin
uuid] }
def value
last_value = history_values.order(HistoryValue.arel_table['created_at'].desc).first
last_value&.value

View File

@ -21,9 +21,15 @@ class VersionCheckWorker
setting_ver.save!
setting_key = Setting.find_or_initialize_by(name: 'hub_public_key')
return if setting_key.value == res['key']
if setting_key.value != res['key']
setting_key.value = res['key']
setting_key.save!
end
setting_key.value = res['key']
setting_key.save!
setting_uuid = Setting.find_or_initialize_by(name: 'uuid')
return if setting_uuid.value == res['uuid']
setting_uuid.value = res['uuid']
setting_uuid.save!
end
end

View File

@ -159,7 +159,7 @@ Rails.application.routes.draw do
end
# Fab-manager's version
get 'version' => 'version#show'
get 'version/:origin' => 'version#show'
# payments handling
post 'payments/confirm_payment' => 'payments/confirm_payment'

View File

@ -70,6 +70,7 @@ MOMENT_LOCALE=fr
SUMMERNOTE_LOCALE=fr-FR
ANGULAR_LOCALE=fr-fr
FULLCALENDAR_LOCALE=fr
FORCE_VERSION_CHECK=false
ELASTICSEARCH_LANGUAGE_ANALYZER=french

View File

@ -3,8 +3,11 @@
# Fab-manager central hub (remote host)
class FabHub
def self.version_check_payload
uuid = Setting.find_by(name: 'uuid').value
origin = Setting.find_by(name: 'origin').value || "#{Rails.application.secrets.default_protocol}://#{Rails.application.secrets.default_host}"
{
origin: "#{Rails.application.secrets.default_protocol}://#{Rails.application.secrets.default_host}",
uuid: uuid,
origin: origin,
version: Version.current,
lang: I18n.default_locale.to_s
}

View File

@ -32,6 +32,6 @@ class Version
job = Sidekiq::Cron::Job.new(name: job_name, cron: "#{m} #{h} * * #{d}", class: 'VersionCheckWorker')
job.save
end
job.enque! if !job.last_enqueue_time || job.last_enqueue_time < DateTime.current - 24.hours
job.enque!
end
end