From 176b200d32e99fb9133f291531a2d2323b34915d Mon Sep 17 00:00:00 2001 From: oleghasjanov Date: Fri, 20 Dec 2024 12:51:52 +0200 Subject: [PATCH] feat: Add expire_at field to Reserved Domains - Add expire_at field to Reserved Domains form and permit it in controller - Add expire_at column to Reserved Domains index table with status indicators - Add expire date search filter using custom ransacker to ignore time component - Update translations and labels - Change "edit_pw" to "edit" in views and translations --- .../admin/reserved_domains_controller.rb | 2 +- app/models/reserved_domain.rb | 4 ++++ .../admin/reserved_domains/_form.html.erb | 8 +++++++ app/views/admin/reserved_domains/edit.haml | 2 +- .../admin/reserved_domains/index.html.erb | 21 ++++++++++++++++++- config/locales/en.yml | 1 + 6 files changed, 35 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/reserved_domains_controller.rb b/app/controllers/admin/reserved_domains_controller.rb index 93188ecc46..8a36de01b1 100644 --- a/app/controllers/admin/reserved_domains_controller.rb +++ b/app/controllers/admin/reserved_domains_controller.rb @@ -73,7 +73,7 @@ def reserved_checked_elements end def reserved_domain_params - params.require(:reserved_domain).permit(:name, :password) + params.require(:reserved_domain).permit(:name, :password, :expire_at) end def set_domain diff --git a/app/models/reserved_domain.rb b/app/models/reserved_domain.rb index abde7cd2cb..ac71018e20 100644 --- a/app/models/reserved_domain.rb +++ b/app/models/reserved_domain.rb @@ -10,6 +10,10 @@ class ReservedDomain < ApplicationRecord alias_attribute :registration_code, :password + ransacker :expire_date do + Arel.sql('DATE(expire_at)') + end + self.ignored_columns = %w[legacy_id] MAX_DOMAIN_NAME_PER_REQUEST = 20 diff --git a/app/views/admin/reserved_domains/_form.html.erb b/app/views/admin/reserved_domains/_form.html.erb index 6dd266566d..53ac3fa46f 100644 --- a/app/views/admin/reserved_domains/_form.html.erb +++ b/app/views/admin/reserved_domains/_form.html.erb @@ -27,6 +27,14 @@ <%= t '.password_hint' %> +
+
+ <%= f.label :expire_at %> +
+
+ <%= f.text_field :expire_at, class: 'form-control js-datepicker', value: f.object.expire_at.present? ? l(f.object.expire_at, format: :short) : nil %> +
+
diff --git a/app/views/admin/reserved_domains/edit.haml b/app/views/admin/reserved_domains/edit.haml index 51d77f0cc8..c90e41fa82 100644 --- a/app/views/admin/reserved_domains/edit.haml +++ b/app/views/admin/reserved_domains/edit.haml @@ -1,3 +1,3 @@ -= render 'shared/title', name: t(:edit_pw) += render 'shared/title', name: t(:edit) = render 'form' diff --git a/app/views/admin/reserved_domains/index.html.erb b/app/views/admin/reserved_domains/index.html.erb index 109dbad9a1..250ea89e24 100644 --- a/app/views/admin/reserved_domains/index.html.erb +++ b/app/views/admin/reserved_domains/index.html.erb @@ -25,6 +25,15 @@ <%= f.search_field :created_at_lteq, value: params[:q][:created_at_lteq], class: 'form-control js-datepicker', placeholder: t(:created_at_until) %> +
+
+ <%= f.label t(:expired_at) %> + <%= f.search_field :expire_date_eq, + value: params[:q][:expire_date_eq], + class: 'form-control js-datepicker', + placeholder: t(:expired_at) %> +
+
@@ -76,6 +85,9 @@ <%= sort_link(@q, 'updated_at', t(:updated_at)) %> + + <%= sort_link(@q, 'expire_at', t(:expire_at)) %> + <%= t(:actions) %> @@ -100,7 +112,14 @@ <%= l(x.updated_at, format: :short) %> - <%= link_to(t(:edit_pw), edit_admin_reserved_domain_path(id: x.id), class: 'btn btn-primary btn-xs') %> + <% if x.expire_at.present? %> + <%= l(x.expire_at, format: :short) %> + <% else %> + <%= t(:not_set) %> + <% end %> + + + <%= link_to(t(:edit), edit_admin_reserved_domain_path(id: x.id), class: 'btn btn-primary btn-xs') %> <%= link_to(t(:delete), delete_admin_reserved_domain_path(id: x.id), data: { confirm: t(:are_you_sure) }, class: 'btn btn-danger btn-xs') %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 44c2e94cf7..afadacc3aa 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -650,6 +650,7 @@ en: id: ID created_at_from: 'Created at from' created_at_until: 'Created at until' + expired_at: 'Expired at' is_registrant: 'Is registrant' force_delete_set_on_domain: 'Force delete set on domain %{domain_name}. Outzone date: %{outzone_date}. Purge date: %{purge_date}' force_delete_auto_email: 'Force delete set on domain %{domain_name}. Outzone date: %{outzone_date}. Purge date: %{purge_date}. Invalid email: %{email}'