From 26aed7a1b5a12cce0f01fbd5d74ae3e20b875552 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Wed, 17 Aug 2016 12:49:52 +0200 Subject: [PATCH] ability for the admin to set custom settings for the reservation reminders + fix settings customization confirmation message --- CHANGELOG.md | 2 + .../controllers/admin/settings.coffee | 10 ++++- app/assets/javascripts/router.coffee.erb | 4 +- .../admin/settings/reservations.html | 39 ++++++++++++++++- app/controllers/api/settings_controller.rb | 2 +- app/models/setting.rb | 4 +- config/initializers/elasticsearch.rb | 2 +- config/locales/app.admin.en.yml | 25 ++++++++++- config/locales/app.admin.fr.yml | 23 ++++++++++ config/secrets.yml | 4 ++ db/seeds.rb | 12 ++++++ test/integration/settings_test.rb | 43 +++++++++++++++++++ 12 files changed, 163 insertions(+), 7 deletions(-) create mode 100644 test/integration/settings_test.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f7cb7cee..3364d3e5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,8 @@ - Excel exports are now asynchronously generated and cached on the server for future identical requests - Users have the ability to create an organizational profile when creating an account - Organization informations will be used in invoices generation, if present +- Admins can create and enable/disable coupons. They can also notify an user about details of a coupon +- Users and admins can apply coupons's discounts to their shopping cart - Fix a bug: project drafts are shown on public profiles - Fix a bug: event category disappear when editing the event - [TODO DEPLOY] `rake fablab:es_add_event_filters` diff --git a/app/assets/javascripts/controllers/admin/settings.coffee b/app/assets/javascripts/controllers/admin/settings.coffee index f46a279d6..481ffda51 100644 --- a/app/assets/javascripts/controllers/admin/settings.coffee +++ b/app/assets/javascripts/controllers/admin/settings.coffee @@ -74,6 +74,14 @@ Application.Controllers.controller "SettingsController", ["$scope", 'Setting', ' $scope.cancelDelay = name: 'booking_cancel_delay' value: parseInt(settingsPromise.booking_cancel_delay) + + $scope.enableReminder = + name: 'reminder_enable' + value: (settingsPromise.reminder_enable == 'true') + + $scope.reminderDelay = + name: 'reminder_delay' + value: parseInt(settingsPromise.reminder_delay) @@ -108,7 +116,7 @@ Application.Controllers.controller "SettingsController", ["$scope", 'Setting', ' value = setting.value Setting.update { name: setting.name }, { value: value }, (data)-> - growl.success(_t('customization_of_SETTING_successfully_saved', {SETTING:setting.name})) + growl.success(_t('customization_of_SETTING_successfully_saved', {SETTING:_t(setting.name)})) , (error)-> console.log(error) diff --git a/app/assets/javascripts/router.coffee.erb b/app/assets/javascripts/router.coffee.erb index fcbc5a232..f71e4dc02 100644 --- a/app/assets/javascripts/router.coffee.erb +++ b/app/assets/javascripts/router.coffee.erb @@ -1029,7 +1029,9 @@ angular.module('application.router', ['ui.router']). 'main_color', 'secondary_color', 'fablab_name', - 'name_genre' + 'name_genre', + 'reminder_enable', + 'reminder_delay' ]").$promise ] cguFile: ['CustomAsset', (CustomAsset) -> diff --git a/app/assets/templates/admin/settings/reservations.html b/app/assets/templates/admin/settings/reservations.html index 1c94fdc91..962bbc757 100644 --- a/app/assets/templates/admin/settings/reservations.html +++ b/app/assets/templates/admin/settings/reservations.html @@ -67,7 +67,7 @@
- +
@@ -81,4 +81,41 @@
+
+ +
+
+ {{ 'reservations_reminders' }} +
+
+
+

{{ 'notification_sending_before_the_reservation_occurs' }}

+
+ + + +
+
+
+
+ +
+
+
+ +
+ +
+
+ +
+
+
\ No newline at end of file diff --git a/app/controllers/api/settings_controller.rb b/app/controllers/api/settings_controller.rb index 3cac77033..bab41054b 100644 --- a/app/controllers/api/settings_controller.rb +++ b/app/controllers/api/settings_controller.rb @@ -7,7 +7,7 @@ class API::SettingsController < API::ApiController def update authorize Setting - @setting = Setting.find_by(name: params[:name]) + @setting = Setting.find_or_initialize_by(name: params[:name]) if @setting.update(setting_params) render status: :ok else diff --git a/app/models/setting.rb b/app/models/setting.rb index e156b0a66..126afc350 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -29,7 +29,9 @@ class Setting < ActiveRecord::Base main_color secondary_color fablab_name - name_genre) + name_genre + reminder_enable + reminder_delay ) } after_update :update_stylesheet if :value_changed? diff --git a/config/initializers/elasticsearch.rb b/config/initializers/elasticsearch.rb index 16fdd2ce3..5f8f7d446 100644 --- a/config/initializers/elasticsearch.rb +++ b/config/initializers/elasticsearch.rb @@ -1,3 +1,3 @@ -client = Elasticsearch::Client.new host: "http://#{ENV["ELASTICSEARCH_HOST"]}:9200", log: true +client = Elasticsearch::Client.new host: "http://#{Rails.application.secrets.elaticsearch_host}:9200", log: true Elasticsearch::Model.client = client Elasticsearch::Persistence.client = client diff --git a/config/locales/app.admin.en.yml b/config/locales/app.admin.en.yml index 272550d4c..1288c5591 100644 --- a/config/locales/app.admin.en.yml +++ b/config/locales/app.admin.en.yml @@ -513,8 +513,31 @@ en: disabled: "Disabled" ability_for_the_users_to_cancel_their_reservations: "Ability for the users to cancel their reservations" reservations_cancelling: "Reservations cancelling" - customization_of_SETTING_successfully_saved: "Customization of {{SETTING}} successfully saved." # angular interpolation + reservations_reminders: "Reservations reminders" + notification_sending_before_the_reservation_occurs: "Notification sending before the reservation occurs" + customization_of_SETTING_successfully_saved: "Customization of the {{SETTING}} successfully saved." # angular interpolation file_successfully_updated: "File successfully updated." + name_genre: "title concordance" + machine_explications_alert: "explanation message on the machine reservation page" + training_explications_alert: "explanation message on the training reservation page" + training_information_message: "information message on the machine reservation page" + subscription_explications_alert: "explanation message on the subscription page" + event_reduced_amount_alert: "information message concerning the reduced prices of an event" + main_color: "main colour" + secondary_color: "secondary colour" + home_blogpost: "homepage's brief" + twitter_name: "Twitter feed name" + about_title: "\"About\" page title" + about_body: "\"About\" page content" + about_contacts: "\"About\" page contacts" + booking_window_start: "opening time" + booking_window_end: "closing time" + booking_move_enable: "reservation moving enabling" + booking_move_delay: "preventive delay of moving" + booking_cancel_enable: "reservation canceling enabling" + booking_cancel_delay: "preventive delay of canceling" + reminder_enable: "reservation reminding enabling" + reminder_delay: "delay before sending the reminder" open_api_clients: add_new_client: "Create new API client" diff --git a/config/locales/app.admin.fr.yml b/config/locales/app.admin.fr.yml index 7b06f631e..33807ed4e 100644 --- a/config/locales/app.admin.fr.yml +++ b/config/locales/app.admin.fr.yml @@ -513,8 +513,31 @@ fr: disabled: "Désactivé" ability_for_the_users_to_cancel_their_reservations: "Possibilité pour l'utilisateur d'annuler ses réservations" reservations_cancelling: "Annulation des réservations" + reservations_reminders: "Rappel des réservations" + notification_sending_before_the_reservation_occurs: "Envoi de notification avant l'avènement de la réservation" customization_of_SETTING_successfully_saved: "La personnalisation de {{SETTING}} a bien été enregistrée." # angular interpolation file_successfully_updated: "Le fichier a bien été mis à jour." + name_genre: "l'accord du nom" + machine_explications_alert: "l'explication sur la page de réservation d'une machine" + training_explications_alert: "l'explication sur la page de réservation d'une formation" + training_information_message: "l'information sur la page de réservation d'une formation" + subscription_explications_alert: "l'explication sur la page de souscription à un abonnement" + event_reduced_amount_alert: "l'information relative aux tarifs réduits d'un évènement" + main_color: "la couleur principale" + secondary_color: "la couleur secondaire" + home_blogpost: "la brève de la page d'accueil" + twitter_name: "nom du flux Twitter" + about_title: "titre de la page \"À propos\"" + about_body: "corps de la page \"À propos\"" + about_contacts: "contacts sur la page \"À propos\"" + booking_window_start: "l'heure d'ouverture" + booking_window_end: "l'heure de fermeture" + booking_move_enable: "l'activation du déplacement de réservation" + booking_move_delay: "délai préventif de déplacement" + booking_cancel_enable: "l'activation de l'annulation de réservation" + booking_cancel_delay: "délai préventif d'annulation" + reminder_enable: "l'activation du rappel de réservation" + reminder_delay: "délai avant envoi de la notification de rappel" open_api_clients: add_new_client: "Créer un compte client" diff --git a/config/secrets.yml b/config/secrets.yml index c3b551ca7..9a835c283 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -36,6 +36,7 @@ development: navinum_api_password: <%= ENV["NAVINUM_API_PASSWORD"] %> log_level: <%= ENV["LOG_LEVEL"] %> facebook_app_id: <%= ENV["FACEBOOK_APP_ID"] %> + elaticsearch_host: <%= ENV["ELASTICSEARCH_HOST"] %> test: secret_key_base: 83daf5e7b80d990f037407bab78dff9904aaf3c195a50f84fa8695a22287e707dfbd9524b403b1dcf116ae1d8c06844c3d7ed942564e5b46be6ae3ead93a9d30 @@ -63,6 +64,7 @@ test: navinum_api_password: log_level: <%= ENV["LOG_LEVEL"] %> facebook_app_id: <%= ENV["FACEBOOK_APP_ID"] %> + elaticsearch_host: localhost staging: secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> @@ -97,6 +99,7 @@ staging: navinum_api_password: <%= ENV["NAVINUM_API_PASSWORD"] %> log_level: <%= ENV["LOG_LEVEL"] %> facebook_app_id: <%= ENV["FACEBOOK_APP_ID"] %> + elaticsearch_host: <%= ENV["ELASTICSEARCH_HOST"] %> # Do not keep production secrets in the repository, # instead read values from the environment. @@ -134,3 +137,4 @@ production: navinum_api_password: <%= ENV["NAVINUM_API_PASSWORD"] %> log_level: <%= ENV["LOG_LEVEL"] %> facebook_app_id: <%= ENV["FACEBOOK_APP_ID"] %> + elaticsearch_host: <%= ENV["ELASTICSEARCH_HOST"] %> diff --git a/db/seeds.rb b/db/seeds.rb index ac8baaabc..7c05d41e1 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -392,3 +392,15 @@ unless DatabaseProvider.count > 0 provider.save end end + +unless Setting.find_by(name: 'reminder_enable').try(:value) + setting = Setting.find_or_initialize_by(name: 'reminder_enable') + setting.value = 'true' + setting.save +end + +unless Setting.find_by(name: 'reminder_delay').try(:value) + setting = Setting.find_or_initialize_by(name: 'reminder_delay') + setting.value = '24' + setting.save +end \ No newline at end of file diff --git a/test/integration/settings_test.rb b/test/integration/settings_test.rb new file mode 100644 index 000000000..ae7aec4ff --- /dev/null +++ b/test/integration/settings_test.rb @@ -0,0 +1,43 @@ +class SettingsTest < ActionDispatch::IntegrationTest + + # Called before every test method runs. Can be used + # to set up fixture information. + def setup + @admin = User.find_by(username: 'admin') + login_as(@admin, scope: :user) + end + + # Called after every test method runs. Can be used to tear + # down fixture information. + + def teardown + # Do nothing + end + + test 'update setting value' do + put '/api/settings/fablab_name', + { + setting: { + value: 'Test Fablab' + } + } + assert_equal 200, response.status + assert_equal Mime::JSON, response.content_type + resp = json_response(response.body) + assert_equal 'fablab_name', resp[:setting][:name] + assert_equal 'Test Fablab', resp[:setting][:value] + end + + + test 'update setting with wrong name' do + put '/api/settings/does_not_exists', + { + setting: { + value: 'ERROR EXPECTED' + } + } + assert_equal 422, response.status + assert_match /Name is not included in the list/, response.body + end + +end