rename deleted_at to archived_at

pull/217/head
Pete Matsyburka 2 years ago
parent cfb1bdcd52
commit 6d7d8ae87c

@ -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

@ -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

@ -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

@ -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)

@ -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

@ -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

@ -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)

@ -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))

@ -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

@ -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

@ -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)

@ -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?

@ -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

@ -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

@ -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

@ -16,7 +16,7 @@
</div>
</div>
<% 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? %>
<div>
<a href="<%= templates_archived_index_path %>" class="link text-sm">View Archived</a>
</div>

@ -3,7 +3,7 @@
<div class="space-y-6">
<div class="text-center w-full space-y-6">
<%= render 'banner' %>
<% unless @template.deleted_at? %>
<% unless @template.archived_at? %>
<p class="text-xl font-semibold text-center">You have been invited to submit a form</p>
<% end %>
</div>
@ -14,7 +14,7 @@
</div>
<div>
<p class="text-lg font-bold mb-1"><%= @template.name %></p>
<% if @template.deleted_at? %>
<% if @template.archived_at? %>
<p class="text-sm">Form has been deleted by <span class="font-semibold"><%= @template.account.name %></span>.</p>
<% else %>
<p class="text-sm">Invited by <span class="font-semibold"><%= @template.account.name %></span></p>
@ -23,7 +23,7 @@
</div>
</div>
</div>
<% 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| %>
<div class="form-control !mt-0">
<%= f.label :email, class: 'label' %>

@ -49,7 +49,7 @@
<% end %>
<% end %>
<span class="btn btn-outline btn-sm w-20 md:w-24">View</span>
<% 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 %>
</div>
@ -134,7 +134,7 @@
</form>
<% end %>
<span class="btn btn-outline btn-sm w-20 md:w-24">View</span>
<% 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 %>
</div>

@ -13,7 +13,7 @@
<%= svg_icon('calendar', class: 'w-4 h-4') %>
<span><%= l(template.created_at.in_time_zone(current_account.timezone), format: :short, locale: current_account.locale) %></span>
</span>
<% if template.deleted_at? %>
<% if template.archived_at? %>
<span class="flex items-center space-x-1 w-1/2">
<%= svg_icon('folder', class: 'w-4 h-4 flex-shrink-0') %>
<span class="truncate"><%= template.folder.name %></span>
@ -24,14 +24,14 @@
</a>
<div class="absolute top-0 bottom-0 w-0 flex items-center hidden md:group-hover:flex" style="right: 37px">
<div class="space-y-1">
<% if can?(:update, template) && !template.deleted_at? %>
<% if can?(:update, template) && !template.archived_at? %>
<span class="tooltip tooltip-left" data-tip="Move">
<a href="<%= edit_template_folder_path(template.id) %>" data-turbo-frame="modal" class="btn btn-xs hover:btn-outline bg-base-200 btn-circle">
<%= svg_icon('folder_share', class: 'w-4 h-4') %>
</a>
</span>
<% end %>
<% if template.deleted_at? && can?(:update, template) %>
<% if template.archived_at? && can?(:update, template) %>
<span class="tooltip tooltip-left" data-tip="Restore">
<%= button_to template_restore_index_path(template), class: 'btn btn-xs hover:btn-outline bg-base-200 btn-circle' do %>
<%= svg_icon('rotate', class: 'w-4 h-4 enabled') %>
@ -53,9 +53,9 @@
</span>
<% end %>
<% if can?(:destroy, template) %>
<span class="tooltip tooltip-left" data-tip="<%= template.deleted_at? ? 'Delete' : 'Archive' %>">
<%= button_to template_path(template), data: { turbo_confirm: template.deleted_at? ? 'Template deletion is irreversible and will permanently remove all associated signed documents with it. Are you sure?' : 'Are you sure?' }, params: { permanently: template.deleted_at? }.compact_blank, method: :delete, class: 'btn btn-xs hover:btn-outline bg-base-200 btn-circle', aria_label: 'Restore' do %>
<%= svg_icon(template.deleted_at? ? 'trash' : 'archive', class: 'w-4 h-4 enabled') %>
<span class="tooltip tooltip-left" data-tip="<%= template.archived_at? ? 'Delete' : 'Archive' %>">
<%= button_to template_path(template), data: { turbo_confirm: template.archived_at? ? 'Template deletion is irreversible and will permanently remove all associated signed documents with it. Are you sure?' : 'Are you sure?' }, params: { permanently: template.archived_at? }.compact_blank, method: :delete, class: 'btn btn-xs hover:btn-outline bg-base-200 btn-circle', aria_label: 'Restore' do %>
<%= svg_icon(template.archived_at? ? 'trash' : 'archive', class: 'w-4 h-4 enabled') %>
<%= svg_icon('loader', class: 'w-4 h-4 animate-spin disabled') %>
<% end %>
</span>

@ -2,7 +2,7 @@
<div>
<h1 class="text-4xl font-semibold mr-4" style="overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;">
<%= template.name %>
<% if template.deleted_at? %>
<% if template.archived_at? %>
<span class="badge badge-outline badge-lg align-middle">Archived</span>
<% end %>
</h1>
@ -23,10 +23,10 @@
</div>
</div>
<div class="flex md:justify-between space-x-2 flex-none pt-1">
<% if !template.deleted_at? %>
<% if !template.archived_at? %>
<%= render 'shared/clipboard_copy', text: start_form_url(slug: @template.slug), class: 'btn btn-sm btn-neutral text-white', icon_class: 'w-6 h-6 text-white', copy_title: 'Copy Link', copied_title: 'Copied', copy_title_md: 'Link', copied_title_md: 'Copied' %>
<% end %>
<% if !template.deleted_at? && can?(:destroy, template) %>
<% if !template.archived_at? && can?(:destroy, template) %>
<%= button_to button_title(title: 'Archive', disabled_with: 'Archiving', title_class: 'hidden md:inline', icon: svg_icon('archive', class: 'w-6 h-6')), template_path(template), class: 'btn btn-outline btn-sm', method: :delete, data: { turbo_confirm: 'Are you sure?' } %>
<% end %>
<% if can?(:create, template) %>
@ -35,7 +35,7 @@
<span class="hidden md:inline">Clone</span>
<% end %>
<% end %>
<% if !template.deleted_at? && can?(:update, template) %>
<% if !template.archived_at? && can?(:update, template) %>
<%= link_to edit_template_path(template), class: 'btn btn-outline btn-sm' do %>
<span class="flex items-center justify-center space-x-2">
<%= svg_icon('pencil', class: 'w-6 h-6') %>
@ -43,7 +43,7 @@
</span>
<% end %>
<% end %>
<% if template.deleted_at? && can?(:create, template) %>
<% if template.archived_at? && can?(:create, template) %>
<%= button_to button_title(title: 'Restore', disabled_with: 'Restoring', icon: svg_icon('rotate', class: 'w-6 h-6')), template_restore_index_path(template), class: 'btn btn-outline btn-sm' %>
<% end %>
</div>

@ -11,7 +11,7 @@
<%= svg_icon('download', class: 'w-6 h-6 stroke-2') %>
<span>Export</span>
<% end %>
<% if !@template.deleted_at? && can?(:create, Submission) %>
<% if !@template.archived_at? && can?(:create, Submission) %>
<%= link_to new_template_submission_path(@template), class: 'white-button !border', data: { turbo_frame: 'modal' } do %>
<%= svg_icon('plus', class: 'w-6 h-6 stroke-2') %>
<span>Add <span class="hidden md:inline">Recipients</span></span>
@ -56,7 +56,7 @@
<%= render partial: 'submission', collection: @submissions %>
</div>
<% 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? %>
<div>
<a href="<%= template_archived_index_path(@template) %>" class="link text-sm">View Archived</a>
</div>
@ -74,7 +74,7 @@
<div class="card-body text-center py-16">
<div class="max-w-lg mx-auto">
<p class="text-3xl font-bold text-base-content mb-4">There are no Submissions</p>
<% if @template.deleted_at.blank? && params[:q].blank? %>
<% if @template.archived_at.blank? && params[:q].blank? %>
<p>Send an invitation to fill and complete the form</p>
<div class="space-y-2 flex flex-col">
<% if can?(:create, Submission) %>

@ -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

@ -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

@ -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)

Loading…
Cancel
Save