From 6d7d8ae87c6578804091f1efa9db830864dd1896 Mon Sep 17 00:00:00 2001 From: Pete Matsyburka Date: Sat, 30 Dec 2023 00:37:03 +0200 Subject: [PATCH] rename deleted_at to archived_at --- app/controllers/api/submissions_controller.rb | 6 +++--- ...template_folders_autocomplete_controller.rb | 4 ++-- app/controllers/api/templates_controller.rb | 4 ++-- app/controllers/start_form_controller.rb | 2 +- app/controllers/submissions_controller.rb | 2 +- app/controllers/submit_form_controller.rb | 4 ++-- .../templates_archived_controller.rb | 2 +- ...emplates_archived_submissions_controller.rb | 2 +- app/controllers/templates_controller.rb | 4 ++-- .../templates_restore_controller.rb | 2 +- app/controllers/users_controller.rb | 4 ++-- app/models/submission.rb | 8 ++------ app/models/template.rb | 6 +++--- app/models/template_folder.rb | 18 +++++++++--------- app/models/user.rb | 6 +++--- app/views/dashboard/index.html.erb | 2 +- app/views/start_form/show.html.erb | 6 +++--- app/views/templates/_submission.html.erb | 4 ++-- app/views/templates/_template.html.erb | 12 ++++++------ app/views/templates/_title.html.erb | 10 +++++----- app/views/templates/show.html.erb | 6 +++--- ...9220819_rename_deleted_at_to_archived_at.rb | 10 ++++++++++ db/schema.rb | 10 +++++----- lib/accounts.rb | 2 +- 24 files changed, 71 insertions(+), 65 deletions(-) create mode 100644 db/migrate/20231229220819_rename_deleted_at_to_archived_at.rb diff --git a/app/controllers/api/submissions_controller.rb b/app/controllers/api/submissions_controller.rb index 7c160baa..085d8e93 100644 --- a/app/controllers/api/submissions_controller.rb +++ b/app/controllers/api/submissions_controller.rb @@ -78,7 +78,7 @@ module Api end def destroy - @submission.update!(deleted_at: Time.current) + @submission.update!(archived_at: Time.current) render json: @submission.as_json(only: %i[id], methods: %i[archived_at]) end @@ -118,8 +118,8 @@ module Api def serialize_params { - only: %i[id source submitters_order created_at updated_at], - methods: %i[audit_log_url archived_at], + only: %i[id source submitters_order created_at updated_at archived_at], + methods: %i[audit_log_url], include: { submitters: { only: %i[id slug uuid name email phone completed_at opened_at sent_at diff --git a/app/controllers/api/template_folders_autocomplete_controller.rb b/app/controllers/api/template_folders_autocomplete_controller.rb index 19365e76..39d1a27e 100644 --- a/app/controllers/api/template_folders_autocomplete_controller.rb +++ b/app/controllers/api/template_folders_autocomplete_controller.rb @@ -7,10 +7,10 @@ module Api LIMIT = 100 def index - template_folders = @template_folders.joins(:templates).where(templates: { deleted_at: nil }).distinct + template_folders = @template_folders.joins(:templates).where(templates: { archived_at: nil }).distinct template_folders = TemplateFolders.search(template_folders, params[:q]).limit(LIMIT) - render json: template_folders.as_json(only: %i[name deleted_at]) + render json: template_folders.as_json(only: %i[name archived_at]) end end end diff --git a/app/controllers/api/templates_controller.rb b/app/controllers/api/templates_controller.rb index 2b6b1d59..5c9d6561 100644 --- a/app/controllers/api/templates_controller.rb +++ b/app/controllers/api/templates_controller.rb @@ -38,9 +38,9 @@ module Api end def destroy - @template.update!(deleted_at: Time.current) + @template.update!(archived_at: Time.current) - render json: @template.as_json(only: %i[id deleted_at]) + render json: @template.as_json(only: %i[id archived_at]) end private diff --git a/app/controllers/start_form_controller.rb b/app/controllers/start_form_controller.rb index 0586d7da..bad00328 100644 --- a/app/controllers/start_form_controller.rb +++ b/app/controllers/start_form_controller.rb @@ -13,7 +13,7 @@ class StartFormController < ApplicationController end def update - @submitter = Submitter.where(submission: @template.submissions.where(deleted_at: nil)) + @submitter = Submitter.where(submission: @template.submissions.where(archived_at: nil)) .order(id: :desc) .then { |rel| params[:resubmit].present? ? rel.where(completed_at: nil) : rel } .find_or_initialize_by(**submitter_params.compact_blank) diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb index dda8a829..9c6d6026 100644 --- a/app/controllers/submissions_controller.rb +++ b/app/controllers/submissions_controller.rb @@ -63,7 +63,7 @@ class SubmissionsController < ApplicationController end def destroy - @submission.update!(deleted_at: Time.current) + @submission.update!(archived_at: Time.current) redirect_back(fallback_location: template_path(@submission.template), notice: 'Submission has been archived') end diff --git a/app/controllers/submit_form_controller.rb b/app/controllers/submit_form_controller.rb index 63134478..a9ae111b 100644 --- a/app/controllers/submit_form_controller.rb +++ b/app/controllers/submit_form_controller.rb @@ -32,7 +32,7 @@ class SubmitFormController < ApplicationController cookies[:submitter_sid] = @submitter.signed_id - render @submitter.submission.template.deleted_at? ? :archived : :show + render @submitter.submission.template.archived_at? ? :archived : :show end def update @@ -42,7 +42,7 @@ class SubmitFormController < ApplicationController return render json: { error: 'Form has been completed already.' }, status: :unprocessable_entity end - if submitter.template.deleted_at? || submitter.submission.deleted_at? + if submitter.template.archived_at? || submitter.submission.archived_at? Rollbar.info("Archived template: #{submitter.template.id}") if defined?(Rollbar) return render json: { error: 'Form has been archived.' }, status: :unprocessable_entity diff --git a/app/controllers/templates_archived_controller.rb b/app/controllers/templates_archived_controller.rb index 82f286d0..1d2efe34 100644 --- a/app/controllers/templates_archived_controller.rb +++ b/app/controllers/templates_archived_controller.rb @@ -4,7 +4,7 @@ class TemplatesArchivedController < ApplicationController load_and_authorize_resource :template, parent: false def index - @templates = @templates.where.not(deleted_at: nil).preload(:author, :folder).order(id: :desc) + @templates = @templates.where.not(archived_at: nil).preload(:author, :folder).order(id: :desc) @templates = Templates.search(@templates, params[:q]) @pagy, @templates = pagy(@templates, items: 12) diff --git a/app/controllers/templates_archived_submissions_controller.rb b/app/controllers/templates_archived_submissions_controller.rb index 6d5f82b7..85d551a4 100644 --- a/app/controllers/templates_archived_submissions_controller.rb +++ b/app/controllers/templates_archived_submissions_controller.rb @@ -5,7 +5,7 @@ class TemplatesArchivedSubmissionsController < ApplicationController load_and_authorize_resource :submission, through: :template, parent: false def index - @submissions = @submissions.where.not(deleted_at: nil) + @submissions = @submissions.where.not(archived_at: nil) @submissions = Submissions.search(@submissions, params[:q]) @pagy, @submissions = pagy(@submissions.preload(:submitters).order(id: :desc)) diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index 9650c809..05cb2bac 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -7,7 +7,7 @@ class TemplatesController < ApplicationController def show submissions = @template.submissions - submissions = submissions.active if @template.deleted_at.blank? + submissions = submissions.active if @template.archived_at.blank? submissions = Submissions.search(submissions, params[:q]) @base_submissions = submissions @@ -70,7 +70,7 @@ class TemplatesController < ApplicationController 'Template has been removed.' else - @template.update!(deleted_at: Time.current) + @template.update!(archived_at: Time.current) 'Template has been archived.' end diff --git a/app/controllers/templates_restore_controller.rb b/app/controllers/templates_restore_controller.rb index 954743ce..2d1f80cf 100644 --- a/app/controllers/templates_restore_controller.rb +++ b/app/controllers/templates_restore_controller.rb @@ -4,7 +4,7 @@ class TemplatesRestoreController < ApplicationController load_and_authorize_resource :template def create - @template.update!(deleted_at: nil) + @template.update!(archived_at: nil) redirect_to template_path(@template), notice: 'Template has been unarchived' end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index c84efe0c..387686a6 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -42,7 +42,7 @@ class UsersController < ApplicationController return redirect_to settings_users_path, notice: 'Unable to remove user' end - @user.update!(deleted_at: Time.current) + @user.update!(archived_at: Time.current) redirect_to settings_users_path, notice: 'User has been removed' end @@ -52,7 +52,7 @@ class UsersController < ApplicationController def build_user @user = current_account.users.find_by(email: user_params[:email])&.tap do |user| user.assign_attributes(user_params) - user.deleted_at = nil + user.archived_at = nil end @user ||= current_account.users.new(user_params) diff --git a/app/models/submission.rb b/app/models/submission.rb index 9cdbf6c2..fe8a78aa 100644 --- a/app/models/submission.rb +++ b/app/models/submission.rb @@ -5,7 +5,7 @@ # Table name: submissions # # id :bigint not null, primary key -# deleted_at :datetime +# archived_at :datetime # preferences :text not null # slug :string not null # source :text not null @@ -55,7 +55,7 @@ class Submission < ApplicationRecord ->(e) { where(uuid: (e.template_schema.presence || e.template.schema).pluck('attachment_uuid')) }, through: :template, source: :documents_attachments - scope :active, -> { where(deleted_at: nil) } + scope :active, -> { where(archived_at: nil) } scope :pending, -> { joins(:submitters).where(submitters: { completed_at: nil }).distinct } scope :completed, -> { where.not(id: pending.select(:submission_id)) } @@ -71,10 +71,6 @@ class Submission < ApplicationRecord preserved: 'preserved' }, scope: false, prefix: true - def archived_at - deleted_at - end - def audit_trail_url return if audit_trail.blank? diff --git a/app/models/template.rb b/app/models/template.rb index 03197202..78262887 100644 --- a/app/models/template.rb +++ b/app/models/template.rb @@ -6,7 +6,7 @@ # # id :bigint not null, primary key # application_key :string -# deleted_at :datetime +# archived_at :datetime # fields :text not null # name :string not null # schema :text not null @@ -58,8 +58,8 @@ class Template < ApplicationRecord has_many :submissions, dependent: :destroy - scope :active, -> { where(deleted_at: nil) } - scope :archived, -> { where.not(deleted_at: nil) } + scope :active, -> { where(archived_at: nil) } + scope :archived, -> { where.not(archived_at: nil) } private diff --git a/app/models/template_folder.rb b/app/models/template_folder.rb index c01fe30c..ea9401f6 100644 --- a/app/models/template_folder.rb +++ b/app/models/template_folder.rb @@ -4,13 +4,13 @@ # # Table name: template_folders # -# id :bigint not null, primary key -# deleted_at :datetime -# name :string not null -# created_at :datetime not null -# updated_at :datetime not null -# account_id :bigint not null -# author_id :bigint not null +# id :bigint not null, primary key +# archived_at :datetime +# name :string not null +# created_at :datetime not null +# updated_at :datetime not null +# account_id :bigint not null +# author_id :bigint not null # # Indexes # @@ -29,10 +29,10 @@ class TemplateFolder < ApplicationRecord belongs_to :account has_many :templates, dependent: :destroy, foreign_key: :folder_id, inverse_of: :folder - has_many :active_templates, -> { where(deleted_at: nil) }, + has_many :active_templates, -> { where(archived_at: nil) }, class_name: 'Template', dependent: :destroy, foreign_key: :folder_id, inverse_of: :folder - scope :active, -> { where(deleted_at: nil) } + scope :active, -> { where(archived_at: nil) } def default? name == DEFAULT_NAME diff --git a/app/models/user.rb b/app/models/user.rb index 40d7b884..b164e64f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -5,10 +5,10 @@ # Table name: users # # id :bigint not null, primary key +# archived_at :datetime # consumed_timestep :integer # current_sign_in_at :datetime # current_sign_in_ip :string -# deleted_at :datetime # email :string not null # encrypted_password :string not null # failed_attempts :integer default(0), not null @@ -62,7 +62,7 @@ class User < ApplicationRecord attribute :role, :string, default: ADMIN_ROLE attribute :uuid, :string, default: -> { SecureRandom.uuid } - scope :active, -> { where(deleted_at: nil) } + scope :active, -> { where(archived_at: nil) } scope :admins, -> { where(role: ADMIN_ROLE) } def access_token @@ -70,7 +70,7 @@ class User < ApplicationRecord end def active_for_authentication? - !deleted_at? + !archived_at? end def remember_me diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index 86f400b1..5dfbe091 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -16,7 +16,7 @@ <% view_archived_html = capture do %> - <% if current_account.templates.where.not(deleted_at: nil).exists? %> + <% if current_account.templates.where.not(archived_at: nil).exists? %>
View Archived
diff --git a/app/views/start_form/show.html.erb b/app/views/start_form/show.html.erb index 8bdbf226..a9a505cb 100644 --- a/app/views/start_form/show.html.erb +++ b/app/views/start_form/show.html.erb @@ -3,7 +3,7 @@
<%= render 'banner' %> - <% unless @template.deleted_at? %> + <% unless @template.archived_at? %>

You have been invited to submit a form

<% end %>
@@ -14,7 +14,7 @@

<%= @template.name %>

- <% if @template.deleted_at? %> + <% if @template.archived_at? %>

Form has been deleted by <%= @template.account.name %>.

<% else %>

Invited by <%= @template.account.name %>

@@ -23,7 +23,7 @@
- <% unless @template.deleted_at? %> + <% unless @template.archived_at? %> <%= form_for @submitter, url: start_form_path(@template.slug), data: { turbo_frame: :_top }, method: :put, html: { class: 'space-y-4', onsubmit: 'event.submitter.disabled = true' } do |f| %>
<%= f.label :email, class: 'label' %> diff --git a/app/views/templates/_submission.html.erb b/app/views/templates/_submission.html.erb index 6a7cf93e..2b696f08 100644 --- a/app/views/templates/_submission.html.erb +++ b/app/views/templates/_submission.html.erb @@ -49,7 +49,7 @@ <% end %> <% end %> View - <% if !submission.deleted_at? && can?(:destroy, submission) %> + <% if !submission.archived_at? && can?(:destroy, submission) %> <%= button_to button_title(title: nil, disabled_with: 'Remov', icon: svg_icon('trash', class: 'w-6 h-6')), submission_path(submission), class: 'btn btn-outline btn-sm', form: { class: 'flex' }, title: 'Delete', method: :delete, data: { turbo_confirm: 'Are you sure?' }, onclick: 'event.stopPropagation()' %> <% end %>
@@ -134,7 +134,7 @@ <% end %> View - <% unless submission.deleted_at? %> + <% unless submission.archived_at? %> <%= button_to button_title(title: nil, disabled_with: 'Remov', icon: svg_icon('trash', class: 'w-6 h-6')), submission_path(submission), class: 'btn btn-outline btn-sm', form: { class: 'flex' }, title: 'Delete', method: :delete, data: { turbo_confirm: 'Are you sure?' }, onclick: 'event.stopPropagation()' %> <% end %> diff --git a/app/views/templates/_template.html.erb b/app/views/templates/_template.html.erb index 9a149d05..67905060 100644 --- a/app/views/templates/_template.html.erb +++ b/app/views/templates/_template.html.erb @@ -13,7 +13,7 @@ <%= svg_icon('calendar', class: 'w-4 h-4') %> <%= l(template.created_at.in_time_zone(current_account.timezone), format: :short, locale: current_account.locale) %> - <% if template.deleted_at? %> + <% if template.archived_at? %> <%= svg_icon('folder', class: 'w-4 h-4 flex-shrink-0') %> <%= template.folder.name %> @@ -24,14 +24,14 @@ <% view_archived_html = capture do %> - <% if @template.submissions.where.not(deleted_at: nil).exists? && !@template.deleted_at? %> + <% if @template.submissions.where.not(archived_at: nil).exists? && !@template.archived_at? %>
View Archived
@@ -74,7 +74,7 @@

There are no Submissions

- <% if @template.deleted_at.blank? && params[:q].blank? %> + <% if @template.archived_at.blank? && params[:q].blank? %>

Send an invitation to fill and complete the form

<% if can?(:create, Submission) %> diff --git a/db/migrate/20231229220819_rename_deleted_at_to_archived_at.rb b/db/migrate/20231229220819_rename_deleted_at_to_archived_at.rb new file mode 100644 index 00000000..29017397 --- /dev/null +++ b/db/migrate/20231229220819_rename_deleted_at_to_archived_at.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class RenameDeletedAtToArchivedAt < ActiveRecord::Migration[7.1] + def change + rename_column :templates, :deleted_at, :archived_at + rename_column :submissions, :deleted_at, :archived_at + rename_column :users, :deleted_at, :archived_at + rename_column :template_folders, :deleted_at, :archived_at + end +end diff --git a/db/schema.rb b/db/schema.rb index c518087d..0eac8bf9 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[7.0].define(version: 2023_11_22_212612) do +ActiveRecord::Schema[7.1].define(version: 2023_12_29_220819) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -130,7 +130,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_11_22_212612) do create_table "submissions", force: :cascade do |t| t.bigint "template_id", null: false t.bigint "created_by_user_id" - t.datetime "deleted_at" + t.datetime "archived_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.text "template_fields" @@ -171,7 +171,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_11_22_212612) do t.string "name", null: false t.bigint "author_id", null: false t.bigint "account_id", null: false - t.datetime "deleted_at" + t.datetime "archived_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["account_id"], name: "index_template_folders_on_account_id" @@ -186,7 +186,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_11_22_212612) do t.text "submitters", null: false t.bigint "author_id", null: false t.bigint "account_id", null: false - t.datetime "deleted_at" + t.datetime "archived_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.text "source", null: false @@ -226,7 +226,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_11_22_212612) do t.integer "failed_attempts", default: 0, null: false t.string "unlock_token" t.datetime "locked_at" - t.datetime "deleted_at" + t.datetime "archived_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.text "uuid", null: false diff --git a/lib/accounts.rb b/lib/accounts.rb index 0f6cac94..fd7e9684 100644 --- a/lib/accounts.rb +++ b/lib/accounts.rb @@ -19,7 +19,7 @@ module Accounts new_template.account = new_account new_template.slug = SecureRandom.base58(14) - new_template.deleted_at = nil + new_template.archived_at = nil new_template.save! Templates::CloneAttachments.call(template: new_template, original_template: template)