-
Notifications
You must be signed in to change notification settings - Fork 560
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
link to submission preview page in completed emails
- Loading branch information
Showing
12 changed files
with
114 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
class SubmissionsPreviewController < ApplicationController | ||
skip_before_action :authenticate_user! | ||
skip_authorization_check | ||
|
||
PRELOAD_ALL_PAGES_AMOUNT = 200 | ||
|
||
def show | ||
@submission = Submission.find_by!(slug: params[:slug]) | ||
|
||
ActiveRecord::Associations::Preloader.new( | ||
records: [@submission], | ||
associations: [:template, { template_schema_documents: :blob }] | ||
).call | ||
|
||
total_pages = | ||
@submission.template_schema_documents.sum { |e| e.metadata.dig('pdf', 'number_of_pages').to_i } | ||
|
||
if total_pages < PRELOAD_ALL_PAGES_AMOUNT | ||
ActiveRecord::Associations::Preloader.new( | ||
records: @submission.template_schema_documents, | ||
associations: [:blob, { preview_images_attachments: :blob }] | ||
).call | ||
end | ||
|
||
render 'submissions/show', layout: 'plain' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddSlugToSubmissions < ActiveRecord::Migration[7.0] | ||
class MigrationSubmission < ApplicationRecord | ||
self.table_name = 'submissions' | ||
end | ||
|
||
def up | ||
add_column :submissions, :slug, :string | ||
|
||
MigrationSubmission.where(slug: nil).find_each do |submission| | ||
submission.update_columns(slug: SecureRandom.base58(14)) | ||
end | ||
|
||
change_column_null :submissions, :slug, false | ||
|
||
add_index :submissions, :slug, unique: true | ||
end | ||
|
||
def down | ||
remove_column :submissions, :slug | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module TimeUtils | ||
module_function | ||
|
||
def timezone_abbr(timezone, time = Time.current) | ||
tz_info = TZInfo::Timezone.get( | ||
ActiveSupport::TimeZone::MAPPING[timezone] || timezone || 'UTC' | ||
) | ||
|
||
tz_info.abbreviation(time) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe 'Submission Preview' do | ||
let(:account) { create(:account) } | ||
let(:user) { create(:user, account:) } | ||
let(:template) { create(:template, account:, author: user) } | ||
|
||
context 'when not submitted' do | ||
let(:submission) { create(:submission, template:, created_by_user: user) } | ||
let(:submitters) { template.submitters.map { |s| create(:submitter, submission:, uuid: s['uuid']) } } | ||
|
||
before do | ||
visit submissions_preview_path(slug: submission.slug) | ||
end | ||
|
||
it 'completes the form' do | ||
expect(page).to have_content('Not completed') | ||
end | ||
end | ||
end |