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? %>
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 @@You have been invited to submit a form
<% end %><%= @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 @@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