From 42872ab1072937cd69a612032f6d57bfe950f639 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Mon, 15 Jun 2020 12:44:43 +0200 Subject: [PATCH] configure wallet from UI --- app/assets/javascripts/app.js | 3 --- app/assets/javascripts/router.js.erb | 6 ++++-- app/assets/templates/admin/members/edit.html.erb | 2 +- app/assets/templates/admin/settings/general.html | 10 ++++++++++ app/assets/templates/dashboard/nav.html.erb | 2 +- app/assets/templates/shared/header.html.erb | 2 +- app/controllers/api/wallet_controller.rb | 2 +- app/models/setting.rb | 3 ++- app/views/application/index.html.erb | 2 +- config/locales/app.admin.en.yml | 4 ++++ config/locales/app.admin.fr.yml | 4 ++++ config/secrets.yml | 4 ---- db/seeds.rb | 2 ++ doc/environment.md | 6 ------ env.example | 3 --- lib/tasks/fablab/setup.rake | 3 ++- setup/env.example | 2 -- setup/setup.sh | 6 ++---- test/fixtures/history_values.yml | 8 ++++++++ test/fixtures/settings.yml | 6 ++++++ 20 files changed, 49 insertions(+), 31 deletions(-) diff --git a/app/assets/javascripts/app.js b/app/assets/javascripts/app.js index 0c1f53813..cf0751f6f 100644 --- a/app/assets/javascripts/app.js +++ b/app/assets/javascripts/app.js @@ -81,9 +81,6 @@ angular.module('application', ['ngCookies', 'ngResource', 'ngSanitize', 'ui.rout $state.prevParams = fromParams; }); - // Global config: if true, wallet will be disabled - $rootScope.fablabWithoutWallet = Fablab.fablabWithoutWallet; - // Global function to allow the user to navigate to the previous screen (ie. $state). // If no previous $state were recorded, navigate to the home page $rootScope.backPrevLocation = function (event) { diff --git a/app/assets/javascripts/router.js.erb b/app/assets/javascripts/router.js.erb index 23b3a7d20..57b93692a 100644 --- a/app/assets/javascripts/router.js.erb +++ b/app/assets/javascripts/router.js.erb @@ -37,7 +37,7 @@ angular.module('application.router', ['ui.router']) logoFile: ['CustomAsset', function (CustomAsset) { return CustomAsset.get({ name: 'logo-file' }).$promise; }], logoBlackFile: ['CustomAsset', function (CustomAsset) { return CustomAsset.get({ name: 'logo-black-file' }).$promise; }], sharedTranslations: ['Translations', function (Translations) { return Translations.query(['app.shared', 'app.public.common']).$promise; }], - modulesPromise: ['Setting', function (Setting) { return Setting.query({ names: "['spaces_module', 'plans_module', 'invoicing_module']" }).$promise; }] + modulesPromise: ['Setting', function (Setting) { return Setting.query({ names: "['spaces_module', 'plans_module', 'invoicing_module', 'wallet_module']" }).$promise; }] }, onEnter: ['$rootScope', 'logoFile', 'logoBlackFile', 'modulesPromise', 'CSRF', function ($rootScope, logoFile, logoBlackFile, modulesPromise, CSRF) { // Retrieve Anti-CSRF tokens from cookies @@ -49,6 +49,7 @@ angular.module('application.router', ['ui.router']) spaces: (modulesPromise.spaces_module === 'true'), plans: (modulesPromise.plans_module === 'true'), invoicing: (modulesPromise.invoicing_module === 'true'), + wallet: (modulesPromise.wallet_module === 'true'), }; }] }) @@ -205,6 +206,7 @@ angular.module('application.router', ['ui.router']) }) .state('app.logged.dashboard.wallet', { url: '/wallet', + abstract: !Fablab.walletModule, views: { 'main@': { templateUrl: '<%= asset_path "dashboard/wallet.html" %>', @@ -1033,7 +1035,7 @@ angular.module('application.router', ['ui.router']) 'booking_move_enable', 'booking_move_delay', 'booking_cancel_enable', 'feature_tour_display', \ 'booking_cancel_delay', 'main_color', 'secondary_color', 'spaces_module', 'twitter_analytics', \ 'fablab_name', 'name_genre', 'reminder_enable', 'plans_module', 'confirmation_required', \ - 'reminder_delay', 'visibility_yearly', 'visibility_others', \ + 'reminder_delay', 'visibility_yearly', 'visibility_others', 'wallet_module', \ 'display_name_enable', 'machines_sort_by', 'fab_analytics', \ 'link_name', 'home_content', 'home_css', 'phone_required']` }).$promise; }], diff --git a/app/assets/templates/admin/members/edit.html.erb b/app/assets/templates/admin/members/edit.html.erb index 0c89c4de6..16eef7b58 100644 --- a/app/assets/templates/admin/members/edit.html.erb +++ b/app/assets/templates/admin/members/edit.html.erb @@ -229,7 +229,7 @@ - +
'"> diff --git a/app/assets/templates/admin/settings/general.html b/app/assets/templates/admin/settings/general.html index 8b25c22cd..2b9482555 100644 --- a/app/assets/templates/admin/settings/general.html +++ b/app/assets/templates/admin/settings/general.html @@ -475,5 +475,15 @@ yes-label="app.shared.buttons.yes" no-label="app.shared.buttons.no">
+
+

{{ 'app.admin.settings.general.wallet' }}

+

+ +
diff --git a/app/assets/templates/dashboard/nav.html.erb b/app/assets/templates/dashboard/nav.html.erb index 8114eb968..c4dcb6bb5 100644 --- a/app/assets/templates/dashboard/nav.html.erb +++ b/app/assets/templates/dashboard/nav.html.erb @@ -16,7 +16,7 @@
  • {{ 'app.public.common.my_trainings' }}
  • {{ 'app.public.common.my_events' }}
  • {{ 'app.public.common.my_invoices' }}
  • -
  • {{ 'app.public.common.my_wallet' }}
  • +
  • {{ 'app.public.common.my_wallet' }}
  • diff --git a/app/assets/templates/shared/header.html.erb b/app/assets/templates/shared/header.html.erb index fe65d87bc..3d48ecbc6 100644 --- a/app/assets/templates/shared/header.html.erb +++ b/app/assets/templates/shared/header.html.erb @@ -39,7 +39,7 @@
  • {{ 'app.public.common.my_trainings' }}
  • {{ 'app.public.common.my_events' }}
  • {{ 'app.public.common.my_invoices' }}
  • -
  • {{ 'app.public.common.my_wallet' }}
  • +
  • {{ 'app.public.common.my_wallet' }}
  • {{ 'app.public.common.help' }}
  • diff --git a/app/controllers/api/wallet_controller.rb b/app/controllers/api/wallet_controller.rb index 5842ece51..75e450e55 100644 --- a/app/controllers/api/wallet_controller.rb +++ b/app/controllers/api/wallet_controller.rb @@ -18,7 +18,7 @@ class API::WalletController < API::ApiController end def credit - return head 422 if Rails.application.secrets.fablab_without_wallet == 'true' + return head 422 unless Setting.get('wallet_module') @wallet = Wallet.find(credit_params[:id]) authorize @wallet diff --git a/app/models/setting.rb b/app/models/setting.rb index 44c7dee35..4a8e10c95 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -101,7 +101,8 @@ class Setting < ApplicationRecord stripe_secret_key stripe_currency invoice_prefix - confirmation_required] } + confirmation_required + wallet_module] } # WARNING: when adding a new key, you may also want to add it in app/policies/setting_policy.rb#public_whitelist def value diff --git a/app/views/application/index.html.erb b/app/views/application/index.html.erb index 0e0aa949a..b69219f14 100644 --- a/app/views/application/index.html.erb +++ b/app/views/application/index.html.erb @@ -25,7 +25,7 @@ Fablab.plansModule = ('<%= Setting.get('plans_module') %>' === 'true'); Fablab.spacesModule = ('<%= Setting.get('spaces_module') %>' === 'true'); - Fablab.fablabWithoutWallet = ('<%= Rails.application.secrets.fablab_without_wallet %>' === 'true'); + Fablab.walletModule = ('<%= Setting.get('wallet_module') %>' === 'true'); Fablab.defaultHost = "<%= Rails.application.secrets.default_host %>"; Fablab.trackingId = "<%= Setting.get('tracking_id') %>"; Fablab.superadminId = parseInt("<%= User.superadmin&.id %>", 10); diff --git a/config/locales/app.admin.en.yml b/config/locales/app.admin.en.yml index 86bb62be4..10ab2ebfd 100644 --- a/config/locales/app.admin.en.yml +++ b/config/locales/app.admin.en.yml @@ -1109,6 +1109,7 @@ en: account_confirmation: "Account confirmation" confirmation_required_info: "Optionally, you can force the users to confirm their email address before being able to access Fab-manager." confirmation_is_required: "Confirmation required" + wallet_module: "wallet module" general: general: "General" title: "Title" @@ -1142,6 +1143,9 @@ en: email: "Email" email_info: "The email address from which notifications will be sent. You can use a non-existing address (like noreply@...) or an existing address if you want to allow your members to reply to the notifications they receive." email_from: "Expeditor's address" + wallet: "Wallet" + wallet_info_html: "

    The virtual wallet allows you to allocate a sum of money to users. Then, can spend this money as they wish, in Fab-manager.

    Members cannot credit their wallet themselves, it's a privilege of managers and administrators.

    " + enable_wallet: "Enable wallet" privacy: title: "Privacy" privacy_policy: "Privacy policy" diff --git a/config/locales/app.admin.fr.yml b/config/locales/app.admin.fr.yml index 1dedc9aab..4356f0e0d 100644 --- a/config/locales/app.admin.fr.yml +++ b/config/locales/app.admin.fr.yml @@ -1109,6 +1109,7 @@ fr: account_confirmation: "Confirmation de compte" confirmation_required_info: "De manière optionnelle, vous pouvez forcer les utilisateurs à confirmer leur adresse électronique avant de pouvoir accéder à Fab-manager." confirmation_is_required: "Confirmation requise" + wallet_module: "module porte-monnaie" general: general: "Général" title: "Titre" @@ -1142,6 +1143,9 @@ fr: email: "Courriel" email_info: "L'adresse de courriel depuis laquelle les notifications seront envoyées. Vous pouvez utiliser une adresse qui n'existe pas (comme ne-pas-repondre@...) ou une adresse existante si vous voulez que vos membres puisse répondre aux notifications qu'ils reçoivent." email_from: "Adresse de l'expéditeur" + wallet: "Porte-monnaie" + wallet_info_html: "

    Le porte-monnaie virtuel vous permet d'allouer une certaine somme d'argent aux utilisateurs. Ils peuvent ensuite dépenser cet argent comment bon leur semble, dans Fab-manager.

    Les membres ne peuvent pas créditer leur porte-monnaie eux-même, c'est un privilège des gestionnaires et des administrateurs.

    " + enable_wallet: "Activer le porte-monnaie" privacy: title: "Confidentialité" privacy_policy: "Politique de confidentialité" diff --git a/config/secrets.yml b/config/secrets.yml index 4437131f9..5ee02c689 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -12,7 +12,6 @@ development: secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> - fablab_without_wallet: <%= ENV["FABLAB_WITHOUT_WALLET"] %> default_host: <%= ENV["DEFAULT_HOST"] %> default_protocol: <%= ENV["DEFAULT_PROTOCOL"] %> time_zone: <%= ENV["TIME_ZONE"] %> @@ -40,7 +39,6 @@ development: test: secret_key_base: 83daf5e7b80d990f037407bab78dff9904aaf3c195a50f84fa8695a22287e707dfbd9524b403b1dcf116ae1d8c06844c3d7ed942564e5b46be6ae3ead93a9d30 - fablab_without_wallet: false default_host: <%= ENV["DEFAULT_HOST"] %> default_protocol: <%= ENV["DEFAULT_PROTOCOL"] %> time_zone: Paris @@ -68,7 +66,6 @@ test: staging: secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> - fablab_without_wallet: <%= ENV["FABLAB_WITHOUT_WALLET"] %> default_host: <%= ENV["DEFAULT_HOST"] %> default_protocol: <%= ENV["DEFAULT_PROTOCOL"] %> delivery_method: <%= ENV['DELIVERY_METHOD'] %> @@ -107,7 +104,6 @@ staging: # instead read values from the environment. production: secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> - fablab_without_wallet: <%= ENV["FABLAB_WITHOUT_WALLET"] %> default_host: <%= ENV["DEFAULT_HOST"] %> default_protocol: <%= ENV["DEFAULT_PROTOCOL"] %> delivery_method: <%= ENV['DELIVERY_METHOD'] %> diff --git a/db/seeds.rb b/db/seeds.rb index 59dcc149b..1327978f3 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -886,6 +886,8 @@ Setting.set('invoice_prefix', 'FabManager_invoice') unless Setting.find_by(name: Setting.set('confirmation_required', false) unless Setting.find_by(name: 'confirmation_required').try(:value) +Setting.set('wallet_module', true) unless Setting.find_by(name: 'wallet_module').try(:value) + if StatisticCustomAggregation.count.zero? # available reservations hours for machines machine_hours = StatisticType.find_by(key: 'hour', statistic_index_id: 2) diff --git a/doc/environment.md b/doc/environment.md index 4e1843f0f..f178d9e31 100644 --- a/doc/environment.md +++ b/doc/environment.md @@ -51,12 +51,6 @@ When using docker-compose, you should provide the name of the service in your [d Used by the authentication system to generate random tokens, eg. for resetting passwords. Used by Rails to verify the integrity of signed cookies. You can generate such a random key by running `rails secret`. - - - FABLAB_WITHOUT_WALLET - -If set to 'true', the wallet will be disabled. -This is useful if you won't use wallet system. DELIVERY_METHOD diff --git a/env.example b/env.example index 16f58d5ff..f40b69b05 100644 --- a/env.example +++ b/env.example @@ -8,9 +8,6 @@ ELASTICSEARCH_HOST=fabmanager-elastic SECRET_KEY_BASE=83daf5e7b80d990f037407bab78dff9904aaf3c195a50f84fa8695a22287e707dfbd9524b403b1dcf116ae1d8c06844c3d7ed942564e5b46be6ae3ead93a9d30 -# FabLab optional modules= -FABLAB_WITHOUT_WALLET=false - # Configure carefully! DEFAULT_HOST=localhost:5000 DEFAULT_PROTOCOL=http diff --git a/lib/tasks/fablab/setup.rake b/lib/tasks/fablab/setup.rake index cebcbecae..d41f5cd64 100644 --- a/lib/tasks/fablab/setup.rake +++ b/lib/tasks/fablab/setup.rake @@ -131,7 +131,8 @@ namespace :fablab do %w[_ STRIPE_API_KEY stripe_secret_key], %w[_ STRIPE_CURRENCY stripe_currency], %w[_ INVOICE_PREFIX invoice_prefix FabManager_invoice], - %w[_ USER_CONFIRMATION_NEEDED_TO_SIGN_IN confirmation_required false] + %w[_ USER_CONFIRMATION_NEEDED_TO_SIGN_IN confirmation_required false], + %w[! FABLAB_WITHOUT_WALLET wallet_module false] ] mapping.each do |m| diff --git a/setup/env.example b/setup/env.example index 63b53b433..1bc8f13ef 100644 --- a/setup/env.example +++ b/setup/env.example @@ -4,8 +4,6 @@ ELASTICSEARCH_HOST=elasticsearch SECRET_KEY_BASE= -FABLAB_WITHOUT_WALLET=false - SLOT_DURATION=60 FEATURE_TOUR_DISPLAY=once diff --git a/setup/setup.sh b/setup/setup.sh index 2163d11de..8f98a6044 100755 --- a/setup/setup.sh +++ b/setup/setup.sh @@ -234,10 +234,8 @@ configure_env_file() local doc variables secret doc=$(\curl -sSL https://raw.githubusercontent.com/sleede/fab-manager/master/doc/environment.md) - variables=(FABLAB_WITHOUT_WALLET \ - DEFAULT_HOST DEFAULT_PROTOCOL DELIVERY_METHOD SMTP_ADDRESS SMTP_PORT SMTP_USER_NAME SMTP_PASSWORD SMTP_AUTHENTICATION \ - SMTP_ENABLE_STARTTLS_AUTO SMTP_OPENSSL_VERIFY_MODE SMTP_TLS \ - LOG_LEVEL MAX_IMAGE_SIZE MAX_CAO_SIZE MAX_IMPORT_SIZE DISK_SPACE_MB_ALERT \ + variables=(DEFAULT_HOST DEFAULT_PROTOCOL DELIVERY_METHOD SMTP_ADDRESS SMTP_PORT SMTP_USER_NAME SMTP_PASSWORD SMTP_AUTHENTICATION \ + SMTP_ENABLE_STARTTLS_AUTO SMTP_OPENSSL_VERIFY_MODE SMTP_TLS LOG_LEVEL MAX_IMAGE_SIZE MAX_CAO_SIZE MAX_IMPORT_SIZE DISK_SPACE_MB_ALERT \ SUPERADMIN_EMAIL APP_LOCALE RAILS_LOCALE MOMENT_LOCALE SUMMERNOTE_LOCALE ANGULAR_LOCALE FULLCALENDAR_LOCALE ELASTICSEARCH_LANGUAGE_ANALYZER TIME_ZONE \ WEEK_STARTING_DAY D3_DATE_FORMAT UIB_DATE_FORMAT EXCEL_DATE_FORMAT) for variable in "${variables[@]}"; do diff --git a/test/fixtures/history_values.yml b/test/fixtures/history_values.yml index b6f2bae4a..2a6e24fc6 100644 --- a/test/fixtures/history_values.yml +++ b/test/fixtures/history_values.yml @@ -677,3 +677,11 @@ history_value_71: name: false created_at: 2020-06-15 10:04:06.216541000 Z updated_at: 2020-06-15 10:04:06.216541000 Z + +history_value_72: + id: 72 + setting_id: 72 + value: 1 + name: true + created_at: 2020-06-15 10:04:06.216541000 Z + updated_at: 2020-06-15 10:04:06.216541000 Z diff --git a/test/fixtures/settings.yml b/test/fixtures/settings.yml index 0042c495c..d7d04bfe8 100644 --- a/test/fixtures/settings.yml +++ b/test/fixtures/settings.yml @@ -419,3 +419,9 @@ setting_71: created_at: 2020-06-15 10:04:06.216541000 Z updated_at: 2020-06-15 10:04:06.216541000 Z +setting_72: + id: 72 + name: wallet_module + created_at: 2020-06-15 10:04:06.216541000 Z + updated_at: 2020-06-15 10:04:06.216541000 Z +