Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds QR Code signature feature to default reports #500

Merged
merged 35 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4f52731
Merge pull request #464 from gems-uff/master
caiovelp May 22, 2024
e0a3f61
Merge pull request #485 from gems-uff/master
anderson-mj Aug 14, 2024
1b04dca
added pdf uploader with base64 support
Jun 5, 2024
5020c9a
added qr code generation on report configurations and qr code signatu…
Jun 5, 2024
e641070
added report record creation and report configuration on-screen for q…
Jun 19, 2024
2e33bcb
changes signature type to enum
anderson-mj Jul 17, 2024
7e15b60
add a few locales for new qr code signature footer
anderson-mj Jul 17, 2024
509ab82
add expiration configuration to reports
anderson-mj Aug 13, 2024
8bc3a82
add maintenance task for notifications and reports
anderson-mj Aug 13, 2024
5b5bc60
adds description and validation for report configuration expiration c…
anderson-mj Aug 26, 2024
e3884eb
validates expiration field for QR Code signatures only + fix transcri…
anderson-mj Aug 28, 2024
c9b00a1
fix a few tests related to reports
anderson-mj Sep 11, 2024
d76d40a
Merge branch 'assertion-pdf-validation' into qr-code-signature
anderson-mj Sep 11, 2024
2cc60b7
remove scaffold fixtures
anderson-mj Sep 11, 2024
67aa95b
fix report configurations record params
anderson-mj Sep 11, 2024
95126df
Remove duplicated tag
caiovelp May 22, 2024
21e3de9
Creates Documents tab
caiovelp May 22, 2024
4712de2
minor fixes
caiovelp Jun 5, 2024
0a7c026
permissões para secretaria
caiovelp Jul 17, 2024
a29845b
adds signed reports listing page
anderson-mj Oct 1, 2024
dc6a45c
let managers see reports but only admins can update it
anderson-mj Oct 1, 2024
3b73a8d
Merge pull request #475 from gems-uff/qr-code-signature
anderson-mj Oct 2, 2024
6e35da9
Merge remote-tracking branch 'origin/develop' into assertion-pdf-vali…
anderson-mj Oct 2, 2024
b66ba3a
change select value based on selected option
anderson-mj Oct 24, 2024
82be1b3
add identifier and file name to reports table
anderson-mj Nov 20, 2024
d326083
fix maintenance rake and add reports spec
anderson-mj Nov 20, 2024
4dcd6cb
pass down filename to store on report record
anderson-mj Nov 20, 2024
7fc64c8
reduce identifier to 10 chars
anderson-mj Nov 20, 2024
f18adec
add back default file name for reports
anderson-mj Nov 20, 2024
62244da
change qr code data url method and add authorize_resource to reports_…
anderson-mj Nov 21, 2024
f04a022
including modules needed to render notification attachments
anderson-mj Nov 21, 2024
6cdc4f2
Merge develop into assertion-pdf-validation
JoaoFelipe Dec 2, 2024
478cebe
fix foreign key types on reports table
anderson-mj Dec 3, 2024
1d58981
add relative url host to qr_code data
anderson-mj Dec 3, 2024
961ab31
fix report download by identifier helper
anderson-mj Dec 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ gem "prawn"
gem "prawn-table"
gem "prawn-rails"
gem "matrix", "~> 0.4.2"
gem "prawn-qrcode"

# Redcarpet for Readme MarkDown (or README.md) - Credits Page
gem "redcarpet"
Expand Down
11 changes: 10 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ GEM
childprocess (5.1.0)
logger (~> 1.5)
choice (0.2.0)
chunky_png (1.4.0)
cocoon (1.2.15)
coderay (1.1.3)
coffee-rails (5.0.0)
Expand Down Expand Up @@ -295,6 +296,9 @@ GEM
prawn (2.4.0)
pdf-core (~> 0.9.0)
ttfunk (~> 1.7)
prawn-qrcode (0.5.2)
prawn (>= 1)
rqrcode (>= 1.0.0)
prawn-rails (1.4.2)
actionview (>= 3.1.0)
prawn
Expand Down Expand Up @@ -365,6 +369,10 @@ GEM
railties (>= 5.2)
rexml (3.3.9)
rouge (4.2.0)
rqrcode (2.2.0)
chunky_png (~> 1.0)
rqrcode_core (~> 1.0)
rqrcode_core (1.2.0)
rspec-collection_matchers (1.2.1)
rspec-expectations (>= 2.99.0.beta1)
rspec-core (3.12.2)
Expand Down Expand Up @@ -533,6 +541,7 @@ DEPENDENCIES
nokogiri (>= 1.16.5)
paper_trail
prawn
prawn-qrcode
prawn-rails
prawn-table
pry
Expand Down Expand Up @@ -564,7 +573,7 @@ DEPENDENCIES
web-console

RUBY VERSION
ruby 3.2.2p53
ruby 3.2.5p208

BUNDLED WITH
2.4.19
6 changes: 4 additions & 2 deletions app/controllers/concerns/shared_pdf_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def render_course_classes_summary_pdf(course_class)
)
end

def render_enrollments_academic_transcript_pdf(enrollment)
def render_enrollments_academic_transcript_pdf(enrollment, filename = "transcript.pdf")
class_enrollments = enrollment.class_enrollments
.where(situation: ClassEnrollment::APPROVED)
.joins(:course_class)
Expand All @@ -47,14 +47,15 @@ def render_enrollments_academic_transcript_pdf(enrollment)
type: "application/pdf",
formats: [:pdf],
assigns: {
filename: filename,
enrollment: enrollment,
class_enrollments: class_enrollments,
accomplished_phases: accomplished_phases,
}
)
end

def render_enrollments_grades_report_pdf(enrollment)
def render_enrollments_grades_report_pdf(enrollment, filename = "grades_report.pdf")
class_enrollments = enrollment.class_enrollments
.where(situation: ClassEnrollment::APPROVED)
.joins(:course_class)
Expand All @@ -66,6 +67,7 @@ def render_enrollments_grades_report_pdf(enrollment)
type: "application/pdf",
formats: [:pdf],
assigns: {
filename: filename,
enrollment: enrollment,
class_enrollments: class_enrollments,
accomplished_phases: accomplished_phases,
Expand Down
10 changes: 6 additions & 4 deletions app/controllers/enrollments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,9 @@ def academic_transcript_pdf
format.pdf do
title = I18n.t("pdf_content.enrollment.academic_transcript.title")
student = enrollment.student.name
send_data render_enrollments_academic_transcript_pdf(enrollment),
filename: "#{title} - #{student}.pdf",
filename = "#{title} - #{student}.pdf"
send_data render_enrollments_academic_transcript_pdf(enrollment, filename),
filename: filename,
type: "application/pdf"
end
end
Expand All @@ -232,8 +233,9 @@ def grades_report_pdf
format.pdf do
title = I18n.t("pdf_content.enrollment.grades_report.title")
student = enrollment.student.name
send_data render_enrollments_grades_report_pdf(enrollment),
filename: "#{title} - #{student}.pdf",
filename = "#{title} - #{student}.pdf"
send_data render_enrollments_grades_report_pdf(enrollment, filename),
filename: filename,
type: "application/pdf"
end
end
Expand Down
20 changes: 12 additions & 8 deletions app/controllers/report_configurations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@ class ReportConfigurationsController < ApplicationController
active_scaffold :report_configuration do |config|
config.create.label = :create_report_configuration_label
columns = [
:name, :image, :scale, :x, :y, :order, :text, :signature_footer,
:preview, :use_at_report, :use_at_transcript, :use_at_grades_report,
:use_at_schedule,
:name, :image, :scale, :x, :y, :order, :text, :signature_type,
:preview, :use_at_report, :use_at_transcript,
:use_at_grades_report, :use_at_schedule, :expiration_in_months
]
config.create.columns = columns
config.update.columns = columns
columns.delete(:preview)
config.columns = columns
config.list.columns = [
:name, :order, :text, :signature_footer, :use_at_report,
:use_at_transcript, :use_at_grades_report, :use_at_schedule
:name, :order, :text, :signature_type,
:use_at_report, :use_at_transcript, :use_at_grades_report,
:use_at_schedule, :expiration_in_months
]
config.columns[:signature_type].form_ui = :select
config.columns[:signature_type].options = { options: ReportConfiguration.signature_types.keys.map(&:to_sym) }
config.columns[:expiration_in_months].description = I18n.t("active_scaffold.report_configurations.expiration_in_months_description")
config.list.sorting = { name: "ASC" }
config.actions << :duplicate
config.duplicate.link.label = "
Expand All @@ -41,7 +45,7 @@ def preview
record.assign_attributes(record_params.except(:image_cache, :remove_image))
# up = ImageUploader.new record, :image
# up.store(File.open(params[:record][:image]))
@pdf_config = record
@pdf_config = record.tap { |r| r.preview = true }
respond_to do |format|
format.pdf do
title = I18n.t("pdf_content.report_configurations.preview")
Expand All @@ -61,8 +65,8 @@ def logo
def record_params
params.required(:record).permit(
:name, :use_at_report, :use_at_transcript, :use_at_grades_report,
:use_at_schedule, :text, :image, :signature_footer, :order, :scale,
:x, :y
:use_at_schedule, :text, :image, :order, :scale,
:x, :y, :signature_type, :expiration_in_months
)
end
end
52 changes: 52 additions & 0 deletions app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# frozen_string_literal: true

class ReportsController < ApplicationController
before_action :set_report, only: [:download, :download_by_identifier]
before_action :check_downloadable, only: [:download, :download_by_identifier]
authorize_resource

skip_authorization_check only: :download_by_identifier
skip_authorize_resource only: :download_by_identifier
skip_before_action :authenticate_user!, only: :download_by_identifier

active_scaffold :report do |config|
config.list.columns = [:user, :file_name, :identifier, :created_at, :expires_at]
config.show.columns = [:user, :file_name, :identifier, :created_at, :expires_at]
config.update.columns = [:expires_at]
config.columns[:user].clear_link
config.actions.exclude :create, :delete
config.action_links.add "download",
label: "
<i title='#{I18n.t("active_scaffold.download_link")}'
class='fa fa-download'></i>
".html_safe,
page: true,
type: :member,
parameters: { format: :pdf },
method: :get,
html_options: { target: "_blank" },
ignore_method: :cant_download?
end

def download
redirect_to download_path(medium_hash: @report.carrierwave_file.medium_hash)
end

def download_by_identifier
send_data(@report.carrierwave_file.read, filename: @report.carrierwave_file.original_filename, disposition: :inline)
end

private
def set_report
@report = params[:id] ? Report.find(params[:id]) : Report.find_by_identifier(params[:identifier])
raise ActionController::RoutingError.new("Este documento não foi encontrado.") if @report.nil?
end

def check_downloadable
raise ActionController::RoutingError.new("Este documento expirou.") if cant_download?(@report)
end

def cant_download?(record)
record.carrierwave_file.blank?
end
end
2 changes: 1 addition & 1 deletion app/helpers/enrollments_pdf_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def transcript_table(pdf, options = {})

if table_data.size >= page_size
new_page = true
next_table_data = table_data.slice(page_size..-1)
next_table_data = table_data.slice(page_size + 1..-1)
table_data = table_data.slice(0..page_size)
page_size = 50
end
Expand Down
Loading
Loading