From 8530a6f6550dfa62b33675a379c17f57c4a3aba0 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Wed, 20 Mar 2019 16:49:38 +0100 Subject: [PATCH] superadmin + fixed free space notification --- app/assets/javascripts/controllers/admin/members.js.erb | 2 +- app/models/user.rb | 6 ++++++ .../_notify_admin_free_disk_space.json.jbuilder | 2 +- app/views/application/index.html.erb | 1 + .../notify_admin_free_disk_space.html.erb | 2 +- app/workers/free_disk_space_worker.rb | 2 +- config/application.yml.default | 1 + config/locales/en.yml | 2 +- config/locales/es.yml | 2 +- config/locales/fr.yml | 2 +- config/locales/pt.yml | 2 +- config/secrets.yml | 4 ++++ doc/environment.md | 5 +++++ docker/env.example | 2 ++ 14 files changed, 27 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/controllers/admin/members.js.erb b/app/assets/javascripts/controllers/admin/members.js.erb index 3b4d5fd1a..c8c49ed49 100644 --- a/app/assets/javascripts/controllers/admin/members.js.erb +++ b/app/assets/javascripts/controllers/admin/members.js.erb @@ -150,7 +150,7 @@ Application.Controllers.controller('AdminMembersController', ['$scope', '$sce', }; // admins list - $scope.admins = adminsPromise.admins; + $scope.admins = adminsPromise.admins.filter(function(m) { return m.id != Fablab.superadminId; }); // Admins ordering/sorting. Default: not sorted $scope.orderAdmin = null; diff --git a/app/models/user.rb b/app/models/user.rb index 0cda62a55..74d700f1f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -93,6 +93,12 @@ class User < ActiveRecord::Base User.with_role(:admin) end + def self.superadmin + return unless Rails.application.secrets.superadmin_email.present? + + User.find_by(email: Rails.application.secrets.superadmin_email) + end + def training_machine?(machine) return true if admin? diff --git a/app/views/api/notifications/_notify_admin_free_disk_space.json.jbuilder b/app/views/api/notifications/_notify_admin_free_disk_space.json.jbuilder index f729e4d01..bf275289d 100644 --- a/app/views/api/notifications/_notify_admin_free_disk_space.json.jbuilder +++ b/app/views/api/notifications/_notify_admin_free_disk_space.json.jbuilder @@ -1,3 +1,3 @@ json.title notification.notification_type -json.description t('warning_disk_space_under_threshold', THRESHOLD: notification.meta_data.threshold) +json.description t('.warning_free_disk_space', AVAILABLE: number_with_delimiter(notification.meta_data['mb_available'])) json.url notification_url(notification, format: :json) diff --git a/app/views/application/index.html.erb b/app/views/application/index.html.erb index 84703a1ca..006d32d36 100644 --- a/app/views/application/index.html.erb +++ b/app/views/application/index.html.erb @@ -28,6 +28,7 @@ Fablab.disqusShortname = "<%= Rails.application.secrets.disqus_shortname %>"; Fablab.defaultHost = "<%= Rails.application.secrets.default_host %>"; Fablab.gaId = "<%= Rails.application.secrets.google_analytics_id %>"; + Fablab.superadminId = parseInt("<%= User.superadmin&.id %>", 10); // i18n stuff Fablab.locale = "<%= Rails.application.secrets.app_locale %>"; diff --git a/app/views/notifications_mailer/notify_admin_free_disk_space.html.erb b/app/views/notifications_mailer/notify_admin_free_disk_space.html.erb index 5543e94f6..ee977d2d7 100644 --- a/app/views/notifications_mailer/notify_admin_free_disk_space.html.erb +++ b/app/views/notifications_mailer/notify_admin_free_disk_space.html.erb @@ -1,4 +1,4 @@ <%= render 'notifications_mailer/shared/hello', recipient: @recipient %> -

<%= t('.body', THRESHOLD: @notification.get_meta_data(:threshold), AVAILABLE: @notification.get_meta_data(:mb_available)) %>

+

<%= t('.body', THRESHOLD: number_with_delimiter(@notification.get_meta_data(:threshold)), AVAILABLE: number_with_delimiter(@notification.get_meta_data(:mb_available))) %>

diff --git a/app/workers/free_disk_space_worker.rb b/app/workers/free_disk_space_worker.rb index 6066e67ed..f5d798365 100644 --- a/app/workers/free_disk_space_worker.rb +++ b/app/workers/free_disk_space_worker.rb @@ -13,7 +13,7 @@ class FreeDiskSpaceWorker return if mb_available > Rails.application.secrets.disk_space_mb_alert NotificationCenter.call type: 'notify_admin_free_disk_space', - receiver: User.admins, + receiver: User.superadmin || User.admins, attached_object: Role.first, meta_data: { mb_available: mb_available, diff --git a/config/application.yml.default b/config/application.yml.default index db4ba61c1..cce865aa7 100644 --- a/config/application.yml.default +++ b/config/application.yml.default @@ -62,6 +62,7 @@ OPENLAB_BASE_URI: 'https://openprojects.fab-manager.com' LOG_LEVEL: 'debug' DISK_SPACE_MB_ALERT: '100' +SUPERADMIN_EMAIL: 'admin@sleede.com' ALLOWED_EXTENSIONS: pdf ai eps cad math svg stl dxf dwg obj step iges igs 3dm 3dmf doc docx png ino scad fcad skp sldprt sldasm slddrw slddrt tex latex ps ALLOWED_MIME_TYPES: application/pdf application/postscript application/illustrator image/x-eps image/svg+xml application/sla application/dxf application/acad application/dwg application/octet-stream application/step application/iges model/iges x-world/x-3dmf application/vnd.openxmlformats-officedocument.wordprocessingml.document image/png text/x-arduino text/plain application/scad application/vnd.sketchup.skp application/x-koan application/vnd-koan koan/x-skm application/vnd.koan application/x-tex application/x-latex diff --git a/config/locales/en.yml b/config/locales/en.yml index 5b9e3390a..0690a80e2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -310,7 +310,7 @@ en: enjoy_a_discount_of_PERCENT_with_code_CODE: "Enjoy a discount of %{PERCENT}% with code %{CODE}" enjoy_a_discount_of_AMOUNT_with_code_CODE: "Enjoy a discount of %{AMOUNT} with code %{CODE}" notify_admin_free_disk_space: - warning_disk_space_under_threshold: "Warning: the server's available disk space is now %{AVAILABLE} MiB" + warning_free_disk_space: "Warning: the server's available disk space is now %{AVAILABLE} MiB" notify_admin_close_period_reminder: warning_last_closed_period_over_1_year: "Please remind to periodically close your accounting periods. Last closed period ended at %{LAST_END}" warning_no_closed_periods: "Please remind to periodically close your accounting periods. You have to close periods from %{FIRST_DATE}" diff --git a/config/locales/es.yml b/config/locales/es.yml index 0e0dcbe36..7b63df33d 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -310,7 +310,7 @@ es: enjoy_a_discount_of_PERCENT_with_code_CODE: "Disfruta de un descuento de %{PERCENT}% con el código %{CODE}" enjoy_a_discount_of_AMOUNT_with_code_CODE: "Disfruta de un descuento de %{AMOUNT} con el código %{CODE}" notify_admin_free_disk_space: - warning_disk_space_under_threshold: "Warning: the server's available disk space is now %{AVAILABLE} MiB" # missing translation + warning_free_disk_space: "Warning: the server's available disk space is now %{AVAILABLE} MiB" # missing translation notify_admin_close_period_reminder: warning_last_closed_period_over_1_year: "Please remind to periodically close your accounting periods. Last closed period ended at %{LAST_END}" # missing translation warning_no_closed_periods: "Please remind to periodically close your accounting periods. You have to close periods from %{FIRST_DATE}" # missing translation diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 497704060..aedcbcee7 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -310,7 +310,7 @@ fr: enjoy_a_discount_of_PERCENT_with_code_CODE: "Bénéficiez d'une remise de %{PERCENT} % avec le code %{CODE}" enjoy_a_discount_of_AMOUNT_with_code_CODE: "Bénéficiez d'une remise de %{AMOUNT} avec le code %{CODE}" notify_admin_free_disk_space: - warning_disk_space_under_threshold: "Attention: l'espace disque disponible sur le serveur est désormais de %{AVAILABLE} MiO" + warning_free_disk_space: "Attention: l'espace disque disponible sur le serveur est désormais de %{AVAILABLE} MiO" notify_admin_close_period_reminder: warning_last_closed_period_over_1_year: "Pensez à clôturer régulièrement vos périodes comptables. Les comptes sont actuellement clôturés jusqu'au %{LAST_END}" warning_no_closed_periods: "Pensez à clôturer régulièrement vos périodes comptables. Vous devez clôturer des périodes depuis le %{FIRST_DATE}" diff --git a/config/locales/pt.yml b/config/locales/pt.yml index cffb4270e..00ef49273 100755 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -310,7 +310,7 @@ pt: enjoy_a_discount_of_PERCENT_with_code_CODE: "Desfrute de um desconto de %{PERCENT}% com o código %{CODE}" enjoy_a_discount_of_AMOUNT_with_code_CODE: "Desfrute de um desconto de %{AMOUNT} com o código %{CODE}" notify_admin_free_disk_space: - warning_disk_space_under_threshold: "Warning: the server's available disk space is now %{AVAILABLE} MiB" # missing translation + warning_free_disk_space: "Warning: the server's available disk space is now %{AVAILABLE} MiB" # missing translation notify_admin_close_period_reminder: warning_last_closed_period_over_1_year: "Please remind to periodically close your accounting periods. Last closed period ended at %{LAST_END}" # missing translation warning_no_closed_periods: "Please remind to periodically close your accounting periods. You have to close periods from %{FIRST_DATE}" # missing translation diff --git a/config/secrets.yml b/config/secrets.yml index 189401adf..105cf9671 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -43,6 +43,7 @@ development: elaticsearch_host: <%= ENV["ELASTICSEARCH_HOST"] %> max_image_size: <%= ENV["MAX_IMAGE_SIZE"] %> disk_space_mb_alert: <%= ENV["DISK_SPACE_MB_ALERT"] %> + superadmin_email: <%= ENV["SUPERADMIN_EMAIL"] %> test: secret_key_base: 83daf5e7b80d990f037407bab78dff9904aaf3c195a50f84fa8695a22287e707dfbd9524b403b1dcf116ae1d8c06844c3d7ed942564e5b46be6ae3ead93a9d30 @@ -77,6 +78,7 @@ test: elaticsearch_host: <%= ENV["ELASTICSEARCH_HOST"] %> max_image_size: <%= ENV["MAX_IMAGE_SIZE"] %> disk_space_mb_alert: <%= ENV["DISK_SPACE_MB_ALERT"] %> + superadmin_email: <%= ENV["SUPERADMIN_EMAIL"] %> staging: secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> @@ -119,6 +121,7 @@ staging: elaticsearch_host: <%= ENV["ELASTICSEARCH_HOST"] %> max_image_size: <%= ENV["MAX_IMAGE_SIZE"] %> disk_space_mb_alert: <%= ENV["DISK_SPACE_MB_ALERT"] %> + superadmin_email: <%= ENV["SUPERADMIN_EMAIL"] %> # Do not keep production secrets in the repository, # instead read values from the environment. @@ -164,3 +167,4 @@ production: elaticsearch_host: <%= ENV["ELASTICSEARCH_HOST"] %> max_image_size: <%= ENV["MAX_IMAGE_SIZE"] %> disk_space_mb_alert: <%= ENV["DISK_SPACE_MB_ALERT"] %> + superadmin_email: <%= ENV["SUPERADMIN_EMAIL"] %> diff --git a/doc/environment.md b/doc/environment.md index 8733a8c6a..937e01bcd 100644 --- a/doc/environment.md +++ b/doc/environment.md @@ -152,6 +152,11 @@ The check will run every weeks and if the threshold is exceeded, an alert will b Credentials for the first admin user created when seeding the project. (not present in application.yml because they are only used once when running the database seed with the command `rake db:seed`) + SUPERADMIN_EMAIL + +Optional email of the administrator account in charge of the system administration. +If specified, it will be hidden from the administrators list and he will exclusively receive the notifications related to the system administration. +If not specified, every admins will receive system administration notifications. ## Internationalization settings diff --git a/docker/env.example b/docker/env.example index 51ed48325..f2f5e9a6c 100644 --- a/docker/env.example +++ b/docker/env.example @@ -61,6 +61,8 @@ NAVINUM_API_LOGIN= NAVINUM_API_PASSWORD= LOG_LEVEL=debug +DISK_SPACE_MB_ALERT='100' +SUPERADMIN_EMAIL='admin@sleede.com' ALLOWED_EXTENSIONS=pdf ai eps cad math svg stl dxf dwg obj step iges igs 3dm 3dmf doc docx png ino scad fcad skp sldprt sldasm slddrw slddrt tex latex ps