mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-29 18:52:22 +01:00
refactored code to use Setting.get
This commit is contained in:
parent
f47af21b42
commit
f80eb230ca
@ -193,7 +193,7 @@ class API::AvailabilitiesController < API::ApiController
|
||||
end
|
||||
|
||||
def define_max_visibility
|
||||
@visi_max_year = Setting.find_by(name: 'visibility_yearly').value.to_i.months.since
|
||||
@visi_max_other = Setting.find_by(name: 'visibility_others').value.to_i.months.since
|
||||
@visi_max_year = Setting.get('visibility_yearly').to_i.months.since
|
||||
@visi_max_other = Setting.get('visibility_others').to_i.months.since
|
||||
end
|
||||
end
|
||||
|
@ -7,7 +7,7 @@ class API::MachinesController < API::ApiController
|
||||
respond_to :json
|
||||
|
||||
def index
|
||||
sort_by = Setting.find_by(name: 'machines_sort_by').value || 'default'
|
||||
sort_by = Setting.get('machines_sort_by') || 'default'
|
||||
@machines = if sort_by == 'default'
|
||||
Machine.includes(:machine_image, :plans)
|
||||
else
|
||||
|
@ -15,7 +15,7 @@ class API::VersionController < API::ApiController
|
||||
origin.save!
|
||||
end
|
||||
# get the last version
|
||||
update_status = Setting.find_by(name: 'hub_last_version')&.value || '{}'
|
||||
update_status = Setting.get('hub_last_version') || '{}'
|
||||
|
||||
json = JSON.parse(update_status)
|
||||
json['current'] = Version.current
|
||||
|
@ -7,6 +7,6 @@ class Rss::EventsController < Rss::RssController
|
||||
@events = Event.includes(:event_image, :event_files, :availability, :category)
|
||||
.where('availabilities.start_at >= ?', DateTime.current)
|
||||
.order('availabilities.start_at ASC').references(:availabilities).limit(10)
|
||||
@fab_name = Setting.find_by(name: 'fablab_name').value
|
||||
@fab_name = Setting.get('fablab_name')
|
||||
end
|
||||
end
|
||||
|
@ -2,6 +2,6 @@ class Rss::ProjectsController < Rss::RssController
|
||||
|
||||
def index
|
||||
@projects = Project.includes(:project_image, :users).published.order('created_at desc').limit(10)
|
||||
@fab_name = Setting.find_by(name: 'fablab_name').value
|
||||
@fab_name = Setting.get('fablab_name')
|
||||
end
|
||||
end
|
||||
|
@ -10,7 +10,7 @@ class Profile < ApplicationRecord
|
||||
|
||||
validates :first_name, presence: true, length: { maximum: 30 }
|
||||
validates :last_name, presence: true, length: { maximum: 30 }
|
||||
validates_numericality_of :phone, only_integer: true, allow_blank: false, if: -> { Rails.application.secrets.phone_required }
|
||||
validates_numericality_of :phone, only_integer: true, allow_blank: false, if: -> { Setting.get('phone_required') }
|
||||
|
||||
after_commit :update_invoicing_profile, if: :invoicing_data_was_modified?, on: [:update]
|
||||
|
||||
|
@ -91,4 +91,13 @@ class Setting < ApplicationRecord
|
||||
admin = User.admins.first
|
||||
save && history_values.create(invoicing_profile: admin.invoicing_profile, value: val)
|
||||
end
|
||||
|
||||
##
|
||||
# Return the value of the requested setting
|
||||
# Usage: Setting.get('my_setting')
|
||||
# @return {string}
|
||||
##
|
||||
def self.get(name)
|
||||
find_by(name: name)&.value
|
||||
end
|
||||
end
|
||||
|
@ -34,11 +34,11 @@ class Stylesheet < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.primary
|
||||
Setting.find_by(name: 'main_color')&.value
|
||||
Setting.get('main_color')
|
||||
end
|
||||
|
||||
def self.secondary
|
||||
Setting.find_by(name: 'secondary_color')&.value
|
||||
Setting.get('secondary_color')
|
||||
end
|
||||
|
||||
def self.primary_light
|
||||
@ -124,7 +124,7 @@ class Stylesheet < ApplicationRecord
|
||||
## ===== HOME PAGE =====
|
||||
|
||||
def self.home_style
|
||||
style = Setting.find_by(name: 'home_css')&.value
|
||||
style = Setting.get('home_css')
|
||||
".home-page { #{style} }"
|
||||
end
|
||||
|
||||
|
@ -41,8 +41,8 @@ class PDF::Invoice < Prawn::Document
|
||||
else
|
||||
text I18n.t('invoices.invoice_reference', REF: invoice.reference), leading: 3
|
||||
end
|
||||
if Setting.find_by(name: 'invoice_code-active').value == 'true'
|
||||
text I18n.t('invoices.code', CODE: Setting.find_by(name: 'invoice_code-value').value), leading: 3
|
||||
if Setting.get('invoice_code-active') == 'true'
|
||||
text I18n.t('invoices.code', CODE: Setting.get('invoice_code-value')), leading: 3
|
||||
end
|
||||
if invoice.invoiced_type != WalletTransaction.name
|
||||
if invoice.is_a?(Avoir)
|
||||
@ -251,7 +251,7 @@ class PDF::Invoice < Prawn::Document
|
||||
row(0).font_style = :bold
|
||||
column(1).style align: :right
|
||||
|
||||
if Setting.find_by(name: 'invoice_VAT-active').value == 'true'
|
||||
if Setting.get('invoice_VAT-active') == 'true'
|
||||
# Total incl. taxes
|
||||
row(-1).style align: :right
|
||||
row(-1).background_color = 'E4E4E4'
|
||||
@ -332,7 +332,7 @@ class PDF::Invoice < Prawn::Document
|
||||
|
||||
# important information
|
||||
move_down 40
|
||||
txt = parse_html(Setting.find_by(name: 'invoice_text').value)
|
||||
txt = parse_html(Setting.get('invoice_text'))
|
||||
txt.each_line do |line|
|
||||
text line, style: :bold, inline_format: true
|
||||
end
|
||||
@ -340,7 +340,7 @@ class PDF::Invoice < Prawn::Document
|
||||
|
||||
# address and legals information
|
||||
move_down 40
|
||||
txt = parse_html(Setting.find_by(name: 'invoice_legals').value)
|
||||
txt = parse_html(Setting.get('invoice_legals'))
|
||||
txt.each_line do |line|
|
||||
text line, align: :right, leading: 4, inline_format: true
|
||||
end
|
||||
|
@ -4,8 +4,8 @@
|
||||
class SlotPolicy < ApplicationPolicy
|
||||
def update?
|
||||
# check that the update is allowed and the prevention delay has not expired
|
||||
delay = Setting.find_by(name: 'booking_move_delay').value.to_i
|
||||
enabled = (Setting.find_by(name: 'booking_move_enable').value == 'true')
|
||||
delay = Setting.get('booking_move_delay').to_i
|
||||
enabled = (Setting.get('booking_move_enable') == 'true')
|
||||
|
||||
# these condition does not apply to admins
|
||||
user.admin? || user.manager? ||
|
||||
|
@ -15,7 +15,7 @@ class AccountingExportService
|
||||
@date_format = '%d/%m/%Y'
|
||||
@label_max_length = 50
|
||||
@export_zeros = false
|
||||
@journal_code = Setting.find_by(name: 'accounting_journal_code')&.value || ''
|
||||
@journal_code = Setting.get('accounting_journal_code') || ''
|
||||
@date_format = date_format
|
||||
@columns = columns
|
||||
end
|
||||
|
@ -4,7 +4,7 @@
|
||||
class Availabilities::StatusService
|
||||
def initialize(current_user_role)
|
||||
@current_user_role = current_user_role
|
||||
@show_name = (@current_user_role == 'admin' || Setting.find_by(name: 'display_name_enable').value == 'true')
|
||||
@show_name = (@current_user_role == 'admin' || Setting.get('display_name_enable') == 'true')
|
||||
end
|
||||
|
||||
# check that the provided machine slot is reserved or not and modify it accordingly
|
||||
|
@ -48,7 +48,7 @@ class HealthService
|
||||
end
|
||||
|
||||
def self.stats
|
||||
enable = Setting.find_by(name: 'fab_analytics')&.value
|
||||
enable = Setting.get('fab_analytics')
|
||||
return false if enable == 'false'
|
||||
|
||||
require 'openssl'
|
||||
@ -56,7 +56,7 @@ class HealthService
|
||||
|
||||
row_stats.to_json.to_s
|
||||
|
||||
key = Setting.find_by(name: 'hub_public_key')&.value
|
||||
key = Setting.get('hub_public_key')
|
||||
return false unless key
|
||||
|
||||
public_key = OpenSSL::PKey::RSA.new(key)
|
||||
|
@ -4,7 +4,7 @@
|
||||
class InvoiceReferenceService
|
||||
class << self
|
||||
def generate_reference(invoice, date: DateTime.current, avoir: false)
|
||||
pattern = Setting.find_by(name: 'invoice_reference').value
|
||||
pattern = Setting.get('invoice_reference')
|
||||
|
||||
reference = replace_invoice_number_pattern(pattern, invoice)
|
||||
reference = replace_date_pattern(reference, date)
|
||||
@ -31,7 +31,7 @@ class InvoiceReferenceService
|
||||
end
|
||||
|
||||
def generate_order_number(invoice)
|
||||
pattern = Setting.find_by(name: 'invoice_order-nb').value
|
||||
pattern = Setting.get('invoice_order-nb')
|
||||
|
||||
# global invoice number (nn..nn)
|
||||
reference = pattern.gsub(/n+(?![^\[]*\])/) do |match|
|
||||
|
@ -7,7 +7,7 @@
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="">
|
||||
|
||||
<title><%=Setting.find_by(name: 'fablab_name').value%></title>
|
||||
<title><%=Setting.get('fablab_name')%></title>
|
||||
|
||||
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,400italic,600,600italic,700,800,700italic' rel='stylesheet' type='text/css'>
|
||||
<link href='https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300,700,300italic' rel='stylesheet' type='text/css'>
|
||||
|
@ -1,5 +1,5 @@
|
||||
<% fablab_name = Setting.find_by(name: 'fablab_name').value %>
|
||||
<% fablab_gender = Setting.find_by(name: 'name_genre').value %>
|
||||
<% fablab_name = Setting.get('fablab_name') %>
|
||||
<% fablab_gender = Setting.get('name_genre') %>
|
||||
<% primary_color = Stylesheet.primary %>
|
||||
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
|
@ -18,7 +18,7 @@
|
||||
url_path = File.join(root_url, 'sso-redirect')
|
||||
%>
|
||||
|
||||
<p><%= t(".body.the_platform") %> <%= Setting.find_by(name: 'fablab_name').value %> <%= t(".body.is_changing_its_auth_system_and_will_now_use") %> <%= active_provider.name %> <%= t(".body.instead_of") %> <%= AuthProvider.find_by(status: 'previous').name %>.</p>
|
||||
<p><%= t(".body.the_platform") %> <%= Setting.get('fablab_name') %> <%= t(".body.is_changing_its_auth_system_and_will_now_use") %> <%= active_provider.name %> <%= t(".body.instead_of") %> <%= AuthProvider.find_by(status: 'previous').name %>.</p>
|
||||
|
||||
<p><%= t('.body.consequence_of_the_modification') %></p>
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
<%= render 'notifications_mailer/shared/hello', recipient: @recipient %>
|
||||
|
||||
<%
|
||||
name = Setting.find_by(name: 'fablab_name').value
|
||||
gender = Setting.find_by(name: 'name_genre').value
|
||||
name = Setting.get('fablab_name')
|
||||
gender = Setting.get('name_genre')
|
||||
%>
|
||||
<p><%= _t('.body.role_changed_html',
|
||||
{
|
||||
|
@ -17,8 +17,8 @@
|
||||
|
||||
<p><%= _t('.body.intro',
|
||||
{
|
||||
GENDER: Setting.find_by(name: 'name_genre').value,
|
||||
FABLAB: Setting.find_by(name: 'fablab_name').value
|
||||
GENDER: Setting.get('name_genre'),
|
||||
FABLAB: Setting.get('fablab_name')
|
||||
})
|
||||
# messageFormat
|
||||
%> <%= link_to URI(root_url).host, root_url %>.
|
||||
|
@ -918,8 +918,8 @@ end
|
||||
unless Setting.find_by(name: 'link_name').try(:value)
|
||||
include ApplicationHelper # rubocop:disable Style/MixinUsage
|
||||
|
||||
name = Setting.find_by(name: 'fablab_name').value
|
||||
gender = Setting.find_by(name: 'name_genre').value
|
||||
name = Setting.get('fablab_name')
|
||||
gender = Setting.get('name_genre')
|
||||
setting = Setting.find_or_initialize_by(name: 'link_name')
|
||||
setting.value = _t('app.public.common.about_the_fablab', NAME: name, GENDER: gender)
|
||||
setting.save
|
||||
|
@ -112,11 +112,6 @@ This is useful if you have your own invoicing system and you want to prevent Fab
|
||||
|
||||
If set to 'true', the wallet will be disabled.
|
||||
This is useful if you won't use wallet system.
|
||||
<a name="PHONE_REQUIRED"></a>
|
||||
|
||||
PHONE_REQUIRED
|
||||
|
||||
If set to 'false' the phone number won't be required to register a new user on the software.
|
||||
<a name="BOOK_SLOT_AT_SAME_TIME"></a>
|
||||
|
||||
BOOK_SLOT_AT_SAME_TIME
|
||||
|
@ -3,8 +3,8 @@
|
||||
# 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}"
|
||||
uuid = Setting.get('uuid')
|
||||
origin = Setting.get('origin') || "#{Rails.application.secrets.default_protocol}://#{Rails.application.secrets.default_host}"
|
||||
{
|
||||
uuid: uuid,
|
||||
origin: origin,
|
||||
|
@ -10,7 +10,7 @@ class Version
|
||||
|
||||
# currently published
|
||||
def self.up_to_date?
|
||||
hub_version = Setting.find_by(name: 'hub_last_version')&.value
|
||||
hub_version = Setting.get('hub_last_version')
|
||||
return unless hub_version
|
||||
|
||||
json = JSON.parse(hub_version)
|
||||
|
@ -51,7 +51,7 @@ class Exports::AccountingExportTest < ActionDispatch::IntegrationTest
|
||||
|
||||
# test values
|
||||
# first line = client line
|
||||
journal_code = Setting.find_by(name: 'accounting_journal_code').value
|
||||
journal_code = Setting.get('accounting_journal_code')
|
||||
assert_equal journal_code, data[0][I18n.t('accounting_export.journal_code')], 'Wrong journal code'
|
||||
|
||||
first_invoice = Invoice.first
|
||||
@ -59,10 +59,10 @@ class Exports::AccountingExportTest < ActionDispatch::IntegrationTest
|
||||
assert_equal entry_date, DateTime.parse(data[0][I18n.t('accounting_export.date')]), 'Wrong date'
|
||||
|
||||
if first_invoice.paid_with_stripe?
|
||||
card_client_code = Setting.find_by(name: 'accounting_card_client_code').value
|
||||
card_client_code = Setting.get('accounting_card_client_code')
|
||||
assert_equal card_client_code, data[0][I18n.t('accounting_export.account_code')], 'Account code for card client is wrong'
|
||||
|
||||
card_client_label = Setting.find_by(name: 'accounting_card_client_label').value
|
||||
card_client_label = Setting.get('accounting_card_client_label')
|
||||
assert_equal card_client_label, data[0][I18n.t('accounting_export.account_label')], 'Account label for card client is wrong'
|
||||
else
|
||||
STDERR.puts "WARNING: unable to test accurately accounting export: invoice #{first_invoice.id} was not paid by card"
|
||||
@ -93,10 +93,10 @@ class Exports::AccountingExportTest < ActionDispatch::IntegrationTest
|
||||
assert_equal entry_date, DateTime.parse(data[1][I18n.t('accounting_export.date')]), 'Wrong date'
|
||||
|
||||
if first_invoice.subscription_invoice?
|
||||
subscription_code = Setting.find_by(name: 'accounting_subscription_code').value
|
||||
subscription_code = Setting.get('accounting_subscription_code')
|
||||
assert_equal subscription_code, data[1][I18n.t('accounting_export.account_code')], 'Account code for subscription is wrong'
|
||||
|
||||
subscription_label = Setting.find_by(name: 'accounting_subscription_label').value
|
||||
subscription_label = Setting.get('accounting_subscription_label')
|
||||
assert_equal subscription_label, data[1][I18n.t('accounting_export.account_label')], 'Account label for subscription is wrong'
|
||||
end
|
||||
|
||||
@ -122,10 +122,10 @@ class Exports::AccountingExportTest < ActionDispatch::IntegrationTest
|
||||
client_row[I18n.t('accounting_export.line_label')],
|
||||
'Line label does not contains the reference to the invoiced item'
|
||||
|
||||
machine_code = Setting.find_by(name: 'accounting_Machine_code').value
|
||||
machine_code = Setting.get('accounting_Machine_code')
|
||||
assert_equal machine_code, item_row[I18n.t('accounting_export.account_code')], 'Account code for machine reservation is wrong'
|
||||
|
||||
machine_label = Setting.find_by(name: 'accounting_Machine_label').value
|
||||
machine_label = Setting.get('accounting_Machine_label')
|
||||
assert_equal machine_label, item_row[I18n.t('accounting_export.account_label')], 'Account label for machine reservation is wrong'
|
||||
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user