From 18cccf97902c3d017c4e19b6c7ff25913fdc61bd Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Wed, 29 Aug 2018 16:31:13 +0200 Subject: [PATCH 01/10] [MIG] Added checks#mode as an enum (auto, manual) --- app/models/check.rb | 3 ++- db/migrate/20180829134404_add_mode_to_checks.rb | 5 +++++ db/schema.rb | 3 ++- test/factories/checks.rb | 3 ++- 4 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20180829134404_add_mode_to_checks.rb diff --git a/app/models/check.rb b/app/models/check.rb index 5aa1b2e..65a6fea 100644 --- a/app/models/check.rb +++ b/app/models/check.rb @@ -1,6 +1,5 @@ # Copyright (C) 2018 Colin Darie , 2018 Jeremy Lecour , 2018 Evolix # License: GNU AGPL-3+ (see full text in LICENSE file) - # == Schema Information # # Table name: checks @@ -16,6 +15,7 @@ # kind :integer not null # last_run_at :datetime # last_success_at :datetime +# mode :integer default("auto"), not null # vendor :string(255) # created_at :datetime not null # updated_at :datetime not null @@ -39,6 +39,7 @@ class Check < ApplicationRecord reject_if: lambda { |at| at["recipient"].blank? && at["interval"].blank? } enum kind: [:domain, :ssl] + enum mode: [:auto, :manual] self.skip_time_zone_conversion_for_attributes = [ :domain_created_at, diff --git a/db/migrate/20180829134404_add_mode_to_checks.rb b/db/migrate/20180829134404_add_mode_to_checks.rb new file mode 100644 index 0000000..1f96d6b --- /dev/null +++ b/db/migrate/20180829134404_add_mode_to_checks.rb @@ -0,0 +1,5 @@ +class AddModeToChecks < ActiveRecord::Migration[5.2] + def change + add_column :checks, :mode, :integer, default: 0, null: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 024d864..b1c4fe7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_08_01_072038) do +ActiveRecord::Schema.define(version: 2018_08_29_134404) do create_table "check_logs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| t.bigint "check_id" @@ -39,6 +39,7 @@ ActiveRecord::Schema.define(version: 2018_08_01_072038) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "consecutive_failures", default: 0, null: false + t.integer "mode", default: 0, null: false t.index ["user_id"], name: "index_checks_on_user_id" end diff --git a/test/factories/checks.rb b/test/factories/checks.rb index a0a7ff3..313a723 100644 --- a/test/factories/checks.rb +++ b/test/factories/checks.rb @@ -1,6 +1,5 @@ # Copyright (C) 2018 Colin Darie , 2018 Evolix # License: GNU AGPL-3+ (see full text in LICENSE file) - # == Schema Information # # Table name: checks @@ -16,6 +15,7 @@ # kind :integer not null # last_run_at :datetime # last_success_at :datetime +# mode :integer default("auto"), not null # vendor :string(255) # created_at :datetime not null # updated_at :datetime not null @@ -44,6 +44,7 @@ FactoryBot.define do last_run_at nil last_success_at nil consecutive_failures 0 + mode :auto trait :domain do kind :domain From abaa800c977f05bedfa7273b999fed7743088d03 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Wed, 29 Aug 2018 16:32:52 +0200 Subject: [PATCH 02/10] Check#supported? for a domain (whois) --- app/models/check.rb | 14 ++++++++++++++ test/models/check_test.rb | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/app/models/check.rb b/app/models/check.rb index 65a6fea..c66e9b7 100644 --- a/app/models/check.rb +++ b/app/models/check.rb @@ -85,6 +85,20 @@ class Check < ApplicationRecord save! end + def supported? + return true unless domain? + return true if domain.blank? + + begin + Whois::Parser.for(domain) + true + rescue Whois::UnsupportedDomainError + false + rescue StandardError + false + end + end + private def domain_created_at_past diff --git a/test/models/check_test.rb b/test/models/check_test.rb index f2074cb..1b29102 100644 --- a/test/models/check_test.rb +++ b/test/models/check_test.rb @@ -71,4 +71,24 @@ class CheckTest < ActiveSupport::TestCase check = build(:check, last_success_at: (10.1 * 24).hours.ago) assert_equal 10, check.days_from_last_success end + + test "supported? for domain" do + check = build(:check, :domain, domain: "domain.fr") + assert check.supported? + + check = build(:check, :domain, domain: "domain.cn") + refute check.supported? + + # an empty domain name is still considered as supported + check = build(:check, :domain, domain: "") + assert check.supported? + end + + test "supported? for SSL" do + check = build(:check, :ssl) + assert check.supported? + + check = build(:check, :ssl, domain: "domain.cn") + assert check.supported? + end end From ef1229d90084e59ab3f3ba9a93c94561d751aecb Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Wed, 29 Aug 2018 16:33:36 +0200 Subject: [PATCH 03/10] Check: set mode manual/auto before saving --- app/models/check.rb | 6 ++++++ test/models/check_test.rb | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/app/models/check.rb b/app/models/check.rb index c66e9b7..d4dc37f 100644 --- a/app/models/check.rb +++ b/app/models/check.rb @@ -55,6 +55,7 @@ class Check < ApplicationRecord validates :vendor, length: { maximum: 255 } before_save :reset_consecutive_failures + before_save :set_mode after_update :reset_notifications after_save :enqueue_sync @@ -128,4 +129,9 @@ class Check < ApplicationRecord self.consecutive_failures = 0 end + + def set_mode + return unless domain_changed? + self.mode = supported? ? :auto : :manual + end end diff --git a/test/models/check_test.rb b/test/models/check_test.rb index 1b29102..072a1fd 100644 --- a/test/models/check_test.rb +++ b/test/models/check_test.rb @@ -91,4 +91,14 @@ class CheckTest < ActiveSupport::TestCase check = build(:check, :ssl, domain: "domain.cn") assert check.supported? end + + test "set mode before saving" do + check = build(:check, domain: "domain.fr") + check.save! + assert check.auto? + + check.domain = "domain.xyz" + check.save! + assert check.mode? + end end From 09be8a38c20d664eb733966ceaa0efd86fd250f7 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Wed, 29 Aug 2018 16:42:00 +0200 Subject: [PATCH 04/10] Manual expiray date support for unsupported domain Validation is made when leaving the input field with an ajax call on the /checks/support.json path. JSON response include the normalized domain name (more TODO) and the supported status. UI is updated with Javascript accordingly to this response. Closes #62 --- app/controllers/checks_controller.rb | 9 +++- app/frontend/components/check_validation.js | 57 +++++++++++++++++++++ app/frontend/packs/application.js | 4 ++ app/models/check.rb | 1 + app/policies/check_policy.rb | 4 ++ app/views/checks/_form.html.erb | 25 ++++++++- app/views/checks/supports.json.jbuilder | 7 +++ config/locales/en.yml | 14 +++-- config/locales/fr.yml | 15 ++++-- config/routes.rb | 36 +++++++------ lib/tasks/auto_annotate_models.rake | 2 +- test/system/checks_test.rb | 20 ++++++++ 12 files changed, 165 insertions(+), 29 deletions(-) create mode 100644 app/frontend/components/check_validation.js create mode 100644 app/views/checks/supports.json.jbuilder diff --git a/app/controllers/checks_controller.rb b/app/controllers/checks_controller.rb index 0029c81..40a16c7 100644 --- a/app/controllers/checks_controller.rb +++ b/app/controllers/checks_controller.rb @@ -3,7 +3,7 @@ class ChecksController < ApplicationController before_action :authenticate_user! - before_action :set_check, except: [:index, :new, :create] + before_action :set_check, except: [:index, :new, :create, :supports] after_action :verify_authorized, except: :index after_action :verify_policy_scoped, only: :index @@ -65,6 +65,11 @@ class ChecksController < ApplicationController redirect_to checks_path end + def supports + @check = Check.new(new_check_params) + authorize @check + end + private def set_check @@ -81,7 +86,7 @@ class ChecksController < ApplicationController end def check_params(*others) - params.require(:check).permit(:domain, :domain_created_at, :comment, :vendor, *others, + params.require(:check).permit(:domain, :domain_expires_at, :comment, :vendor, *others, notifications_attributes: [:id, :channel, :recipient, :interval]) end diff --git a/app/frontend/components/check_validation.js b/app/frontend/components/check_validation.js new file mode 100644 index 0000000..96d4b0e --- /dev/null +++ b/app/frontend/components/check_validation.js @@ -0,0 +1,57 @@ +// Copyright (C) 2018 Colin Darie , 2018 Evolix +// License: GNU AGPL-3+ (see full text in LICENSE file) + +function checkValidationInitialize() { + const element = document.getElementById("check_domain"); + + if (element && element.dataset.kind == "domain") { + addEventSupportListener(element); + } +} + +function addEventSupportListener(element) { + element.addEventListener("blur", event => { + const request = $.ajax("/checks/supports.json", { + method: "post", + dataType: "json", + data: { + check: { + domain: event.target.value, + kind: element.dataset.kind, + } + } + }) + + request.done(response => { + const { supported } = response.check; + + toggleUnsupportedContainers(supported); + setFocus(supported); + + // set normalized domain + element.value = response.check.domain; + }); + }); +} + +function toggleUnsupportedContainers(supported) { + const containerClass = supported ? "d-none" : "d-block"; + + document.getElementById("check_domain_expires_at_container").className = containerClass; + + const domainHint = document.getElementById("check_domain_unsupported_container"); + domainHint.classList.remove("d-none"); + domainHint.classList.remove("d-block"); + domainHint.classList.add(containerClass); +} + + +function setFocus(supported) { + if (supported) { + return; + } + + document.getElementById("check_domain_expires_at").focus(); +} + +export default checkValidationInitialize; diff --git a/app/frontend/packs/application.js b/app/frontend/packs/application.js index 65d2c5b..f232272 100644 --- a/app/frontend/packs/application.js +++ b/app/frontend/packs/application.js @@ -20,9 +20,13 @@ import 'bootstrap/js/dist/tooltip'; import '../scss'; +import checkValidationInitialize from '../components/check_validation'; + Rails.start() Turbolinks.start() document.addEventListener("turbolinks:load", () => { $('[data-toggle="tooltip"]').tooltip(); + + checkValidationInitialize(); }); diff --git a/app/models/check.rb b/app/models/check.rb index d4dc37f..12954b4 100644 --- a/app/models/check.rb +++ b/app/models/check.rb @@ -51,6 +51,7 @@ class Check < ApplicationRecord validates :domain, presence: true validate :domain_created_at_past validate :domain_updated_at_past + validates :domain_expires_at, presence: true, unless: :supported? validates :comment, length: { maximum: 255 } validates :vendor, length: { maximum: 255 } diff --git a/app/policies/check_policy.rb b/app/policies/check_policy.rb index 111c940..0964e21 100644 --- a/app/policies/check_policy.rb +++ b/app/policies/check_policy.rb @@ -20,6 +20,10 @@ class CheckPolicy < ApplicationPolicy owner? end + def supports? + new? + end + private def owner? diff --git a/app/views/checks/_form.html.erb b/app/views/checks/_form.html.erb index cffce68..138b09d 100644 --- a/app/views/checks/_form.html.erb +++ b/app/views/checks/_form.html.erb @@ -3,13 +3,34 @@ <%= simple_form_for(check) do |f| %> <%= f.input :domain, autofocus: true, - input_html: { autocapitalize: :none, autocorrect: :off }, - label: t(".#{check.kind || "generic" }.domain") %> + input_html: { autocapitalize: :none, autocorrect: :off, data: { kind: check.kind } }, + label: t(".#{check.kind || "generic" }.domain"), + hint: t(".#{check.kind || "generic" }.unsupported"), + hint_html: { + id: "check_domain_unsupported_container", + class: "#{check.supported? && 'd-none'}", + } + %> <% if check.new_record? %> <%= f.input :kind, as: check.kind.present? ? :hidden : :radio_buttons, collection: Check.kinds.keys %> <% end %> +
"> + <%= f.input :domain_expires_at, + required: true, + input_html: { + type: :string, + value: check.domain_expires_at&.to_date, + # min: Date.yesterday, + # max: 10.years.from_now.end_of_year.to_date + }, + as: :string, + placeholder: t(".domain_expires_at_placeholder"), + hint: t(".domain_expires_at_hint") + %> +
+ <%= f.input :comment %> <%= f.input :vendor %> diff --git a/app/views/checks/supports.json.jbuilder b/app/views/checks/supports.json.jbuilder new file mode 100644 index 0000000..12c4621 --- /dev/null +++ b/app/views/checks/supports.json.jbuilder @@ -0,0 +1,7 @@ +# Copyright (C) 2018 Colin Darie , 2018 Evolix +# License: GNU AGPL-3+ (see full text in LICENSE file) + +json.check do + json.supported @check.supported? + json.domain normalize_domain(@check.domain) +end diff --git a/config/locales/en.yml b/config/locales/en.yml index 451d3f3..423d7a3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -72,17 +72,17 @@ en: sign_in: "Log in" sign_out: "Log out" profile: "Profile" - home_header: + home_header: welcome: "Chexpire" intro: "Never forget to renew a domain name or SSL certificate." - beta_banner: + beta_banner: beta_info: "Chexpire is in \"beta\" release: only few TLD (.com/.net/.org/.fr) are verified for domain name checks and TLS 1.2 is not supported for SSL checks." issue_link: "Please report issues." pages: - + home: - why: "Why Chexpire?" + why: "Why Chexpire?" description: "Chexpire is a Free Software (AGPLv3 license) to manage the expiration of domain names and SSL certificates. It is primarily an ergonomic web interface that allows you easily to add new domain names/SSL certificates to monitor, and custom/unlimited notifications to be notified before expiration." centralization: "Centralize all your expiry dates" centralization-details: "Do you have domain names at different registrars? many Let's Encrypt SSL certificates with automatic renewal? You will enjoy everything centralized in a web interface: adding a domain name/SSL certificate in two clicks, sorted list, search bar etc." @@ -119,6 +119,12 @@ en: domain: Domain domain: domain: Domain name + unsupported: | + This top-level domain isn't currently automatically supported. + You'll have to fill and maintain yourself the expiry date. + domain_expires_at_hint: | + Fill the expiry date in YYYY-MM-DD format. + domain_expires_at_placeholder: YYYY-MM-DD. ssl: domain: Hostname notifications_hint: | diff --git a/config/locales/fr.yml b/config/locales/fr.yml index ffefa3c..56befae 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -11,6 +11,7 @@ fr: kind: Type domain_created_at: "Date de création" domain_updated_at: "Date de modification" + domain_expires_at: "Date d'expiration" notification: interval: Délai recipient: Destinataire @@ -104,17 +105,17 @@ fr: sign_in: "Connexion" sign_out: "Déconnexion" profile: "Profil" - home_header: + home_header: welcome: "Chexpire" intro: "vous n'oublierez plus jamais de renouveler un nom de domaine ou un certificat SSL." - beta_banner: + beta_banner: beta_info: "Chexpire est en version \"beta\" : seuls certains TLD (.com/.net/.org/.fr) sont vérifiés pour les noms de domaine et TLS 1.2 n'est pas supporté pour les vérifications SSL." issue_link: "Merci de nous reporter bugs et suggestions." pages: - + home: - why: "Pourquoi Chexpire ?" + why: "Pourquoi Chexpire ?" description: "Chexpire est un Logiciel Libre (licence AGPLv3) permettant de gérer l'expiration de noms de domaine et de certificats SSL. C'est avant tout une interface web ergonomique permettant d'ajouter simplement de nouveaux noms de domaine/certificats SSL à surveiller, et des notifications sur mesure et illimitées pour être averti·e avant expiration." centralization: "Centralisez toutes vos dates d'expiration" centralization-details: "Vous avez des noms de domaine chez différents registrars ? de nombreux certificats SSL Let's Encrypt en renouvellement automatique ? Vous allez apprécier de tout centraliser simplement dans une interface web : ajout d'un nom de domaine/certificat SSL en deux clics, liste récapitulative triée, barre de recherche etc." @@ -151,6 +152,12 @@ fr: domain: Domaine domain: domain: Nom de domaine + unsupported: | + Cette extension n'est pas supportée automatiquement actuellement. + Vous devrez saisir et maintenir vous-même sa date d'expiration. + domain_expires_at_hint: | + Renseignez la date d'expiration au format AAAA-MM-JJ. + domain_expires_at_placeholder: AAAA-MM-JJ ssl: domain: Nom d'hôte notifications_hint: | diff --git a/config/routes.rb b/config/routes.rb index dcbf4af..6dc56fd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,10 +1,29 @@ # Copyright (C) 2018 Colin Darie , 2018 Evolix # License: GNU AGPL-3+ (see full text in LICENSE file) +# In order to update the route map below, +# run `bundle exec annotate -r` after modifying this file +Rails.application.routes.draw do + # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html + + resources :checks, except: [:show] do + resources :notifications, only: [:destroy] + collection do + post :supports, format: :json + end + end + + devise_for :users + root to: "pages#home" + + mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development? +end + # == Route Map # # Prefix Verb URI Pattern Controller#Action # check_notification DELETE /checks/:check_id/notifications/:id(.:format) notifications#destroy +# supports_checks POST /checks/supports(.:format) checks#supports # checks GET /checks(.:format) checks#index # POST /checks(.:format) checks#create # new_check GET /checks/new(.:format) checks#new @@ -37,25 +56,10 @@ # rails_disk_service GET /rails/active_storage/disk/:encoded_key/*filename(.:format) active_storage/disk#show # update_rails_disk_service PUT /rails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update # rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create -# +# # Routes for LetterOpenerWeb::Engine: # clear_letters DELETE /clear(.:format) letter_opener_web/letters#clear # delete_letter DELETE /:id(.:format) letter_opener_web/letters#destroy # letters GET / letter_opener_web/letters#index # letter GET /:id(/:style)(.:format) letter_opener_web/letters#show # GET /:id/attachments/:file(.:format) letter_opener_web/letters#attachment - -# In order to update the route map above, -# run `bundle exec annotate -r` after modifying this file -Rails.application.routes.draw do - # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html - - resources :checks, except: [:show] do - resources :notifications, only: [:destroy] - end - - devise_for :users - root to: "pages#home" - - mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development? -end diff --git a/lib/tasks/auto_annotate_models.rake b/lib/tasks/auto_annotate_models.rake index b221470..3210fd2 100644 --- a/lib/tasks/auto_annotate_models.rake +++ b/lib/tasks/auto_annotate_models.rake @@ -8,7 +8,7 @@ if Rails.env.development? # same name. Annotate.set_defaults( 'routes' => 'before', - 'position_in_routes' => 'before', + 'position_in_routes' => 'after', 'position_in_class' => 'before', 'position_in_test' => 'before', 'position_in_fixture' => 'before', diff --git a/test/system/checks_test.rb b/test/system/checks_test.rb index ed513f5..d3b5556 100644 --- a/test/system/checks_test.rb +++ b/test/system/checks_test.rb @@ -25,6 +25,26 @@ class ChecksTest < ApplicationSystemTestCase fill_and_valid_new_check end + test "create a manual domain check" do + visit new_check_path(kind: :domain) + + domain = "unsupported.wxyz" + fill_in("check[domain]", with: domain) + + page.find("body").click # simulate blur + fill_in("check[domain_expires_at]", with: "2022-04-05") + + click_button + + assert_equal checks_path, page.current_path + + assert page.has_css?(".alert-success") + assert page.has_content?(domain) + + check = Check.last + assert_equal Date.new(2022, 4, 5), check.domain_expires_at + end + test "create a predefined ssl check" do visit new_check_path(kind: :ssl) From c540b0d612f6e4500fc74024a345573609414e55 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Wed, 29 Aug 2018 16:44:36 +0200 Subject: [PATCH 05/10] More explicit placeholder color Temporary workaround for #81 --- app/frontend/scss/_variables.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/frontend/scss/_variables.scss b/app/frontend/scss/_variables.scss index 3b55aa8..954eccf 100644 --- a/app/frontend/scss/_variables.scss +++ b/app/frontend/scss/_variables.scss @@ -1,7 +1,7 @@ // Copyright (C) 2018 Colin Darie , 2018 Evolix // License: GNU AGPL-3+ (see full text in LICENSE file) -$input-placeholder-color: #013d3a; +$input-placeholder-color: #b9bbbb; $enable-rounded: false; $theme-colors: ( "primary": #118b83, //light-green From 279f384e56a1f8abcdaaa430ab7c5d83813a9c62 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Wed, 29 Aug 2018 17:02:22 +0200 Subject: [PATCH 06/10] Test: remove obsolete (and stupid) assertion --- test/jobs/whois_sync_job_test.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/jobs/whois_sync_job_test.rb b/test/jobs/whois_sync_job_test.rb index 9276e6d..fbbdcb7 100644 --- a/test/jobs/whois_sync_job_test.rb +++ b/test/jobs/whois_sync_job_test.rb @@ -24,7 +24,6 @@ class WhoisSyncJobTest < ActiveJob::TestCase test "ignore invalid response (domain.fr)" do check = create(:check, :nil_dates, domain: "domain.fr") - original_updated_at = check.updated_at mock_system_command("whois", "domain.fr", stdout: "not a response") do WhoisSyncJob.perform_now(check.id) @@ -34,7 +33,6 @@ class WhoisSyncJobTest < ActiveJob::TestCase assert_just_now check.last_run_at assert_nil check.last_success_at - assert_equal original_updated_at, check.updated_at assert check.active? assert_equal 1, check.consecutive_failures end From 3cbf0e2656f26956519894c400a11f9e434f7a51 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Wed, 29 Aug 2018 17:17:58 +0200 Subject: [PATCH 07/10] Enforce input of type date, enhancing UX for browser compatible. Note: the submitted date format is iso8601 YYYY-MM-DD (as we expect), even if the displayed date by the browser depends of the user's browser locale. Theses browsers then safely ignore input placeholder. This is why we can't display the expected date format elsewhere in the interface: these users will see another format as the one we expect, and we don't want to mislead them. The date format is only displayed as a placeholder, for browser non-compatible with input of type date. --- app/views/checks/_form.html.erb | 9 ++++----- config/locales/en.yml | 2 -- config/locales/fr.yml | 2 -- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/app/views/checks/_form.html.erb b/app/views/checks/_form.html.erb index 138b09d..378dce9 100644 --- a/app/views/checks/_form.html.erb +++ b/app/views/checks/_form.html.erb @@ -20,14 +20,13 @@ <%= f.input :domain_expires_at, required: true, input_html: { - type: :string, + type: :date, value: check.domain_expires_at&.to_date, - # min: Date.yesterday, - # max: 10.years.from_now.end_of_year.to_date + min: Date.yesterday, + max: 10.years.from_now.end_of_year.to_date }, as: :string, - placeholder: t(".domain_expires_at_placeholder"), - hint: t(".domain_expires_at_hint") + placeholder: t(".domain_expires_at_placeholder") %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 423d7a3..58c4495 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -122,8 +122,6 @@ en: unsupported: | This top-level domain isn't currently automatically supported. You'll have to fill and maintain yourself the expiry date. - domain_expires_at_hint: | - Fill the expiry date in YYYY-MM-DD format. domain_expires_at_placeholder: YYYY-MM-DD. ssl: domain: Hostname diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 56befae..e48ca32 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -155,8 +155,6 @@ fr: unsupported: | Cette extension n'est pas supportée automatiquement actuellement. Vous devrez saisir et maintenir vous-même sa date d'expiration. - domain_expires_at_hint: | - Renseignez la date d'expiration au format AAAA-MM-JJ. domain_expires_at_placeholder: AAAA-MM-JJ ssl: domain: Nom d'hôte From 6ccddc6afc988aed175453ba1352d3e4554aa930 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Wed, 29 Aug 2018 17:42:27 +0200 Subject: [PATCH 08/10] Upgrade Task for setting manual mode for domain non supported --- lib/tasks/one_shot.rake | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 lib/tasks/one_shot.rake diff --git a/lib/tasks/one_shot.rake b/lib/tasks/one_shot.rake new file mode 100644 index 0000000..19d088e --- /dev/null +++ b/lib/tasks/one_shot.rake @@ -0,0 +1,14 @@ +namespace :one_shot do + desc "Set manual mode for unsupported checks" + task reset_checks_modes: :environment do + Check.domain.find_each do |check| + check.mode = if check.supported? + :auto + else + :manual + end + + check.save(validate: false) + end + end +end From 7a7ef4407b6c1a4e1e898effc4c6829772daf909 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Wed, 29 Aug 2018 17:46:04 +0200 Subject: [PATCH 09/10] CheckProcessor: restrict scope to "auto" checks --- app/services/check_processor.rb | 1 + test/services/check_processor_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/app/services/check_processor.rb b/app/services/check_processor.rb index 37226b5..2cc626b 100644 --- a/app/services/check_processor.rb +++ b/app/services/check_processor.rb @@ -54,6 +54,7 @@ module CheckProcessor def base_scope Check .active + .auto .where("last_run_at IS NULL OR last_run_at < DATE_SUB(NOW(), INTERVAL 12 HOUR)") end diff --git a/test/services/check_processor_test.rb b/test/services/check_processor_test.rb index 876f8d5..b85191c 100644 --- a/test/services/check_processor_test.rb +++ b/test/services/check_processor_test.rb @@ -108,6 +108,16 @@ class CheckProcessorTest < ActiveSupport::TestCase assert_not_includes checks, c2 end + test "resolvers does not include manual checks" do + c1 = create(:check, :expires_next_week) + c2 = create(:check, :expires_next_week, domain: "fff.wxyz") + + checks = @processor.resolve_expire_short_term + + assert_includes checks, c1 + assert_not_includes checks, c2 + end + test "#sync_dates respects the interval configuration between sends" do create_list(:check, 3, :expires_next_week) From 5d1fa13fba4a7b0d822e3b74002070e324607faa Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Wed, 29 Aug 2018 17:47:04 +0200 Subject: [PATCH 10/10] Do not automatically mark as inactive checks for domain not found This renders explicit the failures after X fails, and notify the user. --- app/jobs/whois_sync_job.rb | 3 --- test/jobs/whois_sync_job_test.rb | 3 +-- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/app/jobs/whois_sync_job.rb b/app/jobs/whois_sync_job.rb index c0e1d17..1532245 100644 --- a/app/jobs/whois_sync_job.rb +++ b/app/jobs/whois_sync_job.rb @@ -20,9 +20,6 @@ class WhoisSyncJob < ApplicationJob return unless response.valid? update_from_response(response) - rescue Whois::DomainNotFoundError - check.active = false - check.save! end def update_from_response(response) diff --git a/test/jobs/whois_sync_job_test.rb b/test/jobs/whois_sync_job_test.rb index fbbdcb7..67464f5 100644 --- a/test/jobs/whois_sync_job_test.rb +++ b/test/jobs/whois_sync_job_test.rb @@ -60,7 +60,7 @@ class WhoisSyncJobTest < ActiveJob::TestCase assert_equal 1, check.consecutive_failures end - test "disable check when whois responds domain not found" do + test "increment consecutive failures when whois responds domain not found" do domain = "willneverexist.fr" check = create(:check, :nil_dates, domain: domain) @@ -70,7 +70,6 @@ class WhoisSyncJobTest < ActiveJob::TestCase check.reload - refute check.active? assert_just_now check.last_run_at assert_nil check.last_success_at assert_equal 1, check.consecutive_failures