From 7b571bcfa7d62337575c90d13594812e18950b11 Mon Sep 17 00:00:00 2001 From: Anderson Meireles Date: Tue, 14 Jan 2025 19:02:11 -0300 Subject: [PATCH] removing watermark when signature is qr code and changing ability to prevent academic_transcript generation if not dismissed with degree --- app/controllers/enrollments_controller.rb | 5 +++++ app/helpers/pdf_helper.rb | 2 +- app/models/ability.rb | 6 ++++++ ...ic_transcript_signature_override_links.html.erb | 14 +++++++++++--- ...grades_report_signature_override_links.html.erb | 14 ++++++++------ .../enrollments/academic_transcript_pdf.pdf.prawn | 2 +- app/views/enrollments/grades_report_pdf.pdf.prawn | 2 +- 7 files changed, 33 insertions(+), 12 deletions(-) diff --git a/app/controllers/enrollments_controller.rb b/app/controllers/enrollments_controller.rb index cbba7774..fe7980c1 100644 --- a/app/controllers/enrollments_controller.rb +++ b/app/controllers/enrollments_controller.rb @@ -224,6 +224,11 @@ def override_signature_grades_report_pdf def academic_transcript_pdf(signature_type = nil) enrollment = Enrollment.find(params[:id]) + + if cannot? :academic_transcript_pdf, enrollment + raise CanCan::AccessDenied.new + end + respond_to do |format| format.pdf do title = I18n.t("pdf_content.enrollment.academic_transcript.title") diff --git a/app/helpers/pdf_helper.rb b/app/helpers/pdf_helper.rb index 61896ab0..3c9b7a0c 100644 --- a/app/helpers/pdf_helper.rb +++ b/app/helpers/pdf_helper.rb @@ -341,7 +341,7 @@ def new_document(name, title, options = {}, &block) datetime_footer(pdf) end end - if options[:watermark] + if options[:watermark] && pdf_config.signature_type != "qr_code" pdf.create_stamp("watermark") do pdf.rotate(60, origin: [0, 0]) do pdf.fill_color "993333" diff --git a/app/models/ability.rb b/app/models/ability.rb index 6cc965b2..15bbe972 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -126,6 +126,7 @@ def initialize_students(user, roles) can :manage, Ability::STUDENT_MODELS can :update_all_fields, Student can :read_all_fields, Student + can :override_report_signature_type, Enrollment can :generate_report_without_watermark, Enrollment can :invite, User end @@ -137,6 +138,11 @@ def initialize_students(user, roles) if roles[Role::ROLE_SUPORTE] can [:read, :update, :update_only_photo], (Student) end + + # Keep this at the end or :read STUDENT_MODELS will override it + cannot :academic_transcript_pdf, Enrollment do |enrollment| + enrollment.dismissal&.dismissal_reason&.thesis_judgement != DismissalReason::APPROVED + end unless roles[:manager] end def initialize_professors(user, roles) diff --git a/app/views/enrollments/_show_academic_transcript_signature_override_links.html.erb b/app/views/enrollments/_show_academic_transcript_signature_override_links.html.erb index 82ba1285..75c2a7d5 100644 --- a/app/views/enrollments/_show_academic_transcript_signature_override_links.html.erb +++ b/app/views/enrollments/_show_academic_transcript_signature_override_links.html.erb @@ -1,5 +1,13 @@
- <%= link_to 'Sem Assinatura', override_signature_transcript_pdf_enrollment_path(id: @record.id, signature_type: :no_signature), target: "_blank" %> - <%= link_to 'Assinatura Manual', override_signature_transcript_pdf_enrollment_path(id: @record.id, signature_type: :manual), target: "_blank" %> - <%= link_to 'Assinatura por QR Code', override_signature_transcript_pdf_enrollment_path(id: @record.id, signature_type: :qr_code), target: "_blank" %> + <% if can?(:academic_transcript_pdf, @record) %> + <% if can?(:override_report_signature_type, @record) %> + <%= link_to_if can?(:academic_transcript_pdf, @record), 'Sem Assinatura', override_signature_transcript_pdf_enrollment_path(id: @record.id, signature_type: :no_signature), target: "_blank" %> + <%= link_to 'Assinatura Manual', override_signature_transcript_pdf_enrollment_path(id: @record.id, signature_type: :manual), target: "_blank" %> + <%= link_to 'Assinatura por QR Code', override_signature_transcript_pdf_enrollment_path(id: @record.id, signature_type: :qr_code), target: "_blank" %> + <% else %> + <%= link_to 'Gerar', academic_transcript_pdf_enrollment_path(id: @record.id, format: :pdf), target: "_blank" %> + <% end %> + <% else %> + - + <% end %>
diff --git a/app/views/enrollments/_show_grades_report_signature_override_links.html.erb b/app/views/enrollments/_show_grades_report_signature_override_links.html.erb index de761741..7ff35878 100644 --- a/app/views/enrollments/_show_grades_report_signature_override_links.html.erb +++ b/app/views/enrollments/_show_grades_report_signature_override_links.html.erb @@ -1,7 +1,9 @@ -
-
- <%= link_to 'Sem Assinatura', override_signature_grades_report_pdf_enrollment_path(id: @record.id, signature_type: :no_signature, transcript: true), target: "_blank" %> - <%= link_to 'Assinatura Manual', override_signature_grades_report_pdf_enrollment_path(id: @record.id, signature_type: :manual, transcript: true), target: "_blank" %> - <%= link_to 'Assinatura por QR Code', override_signature_grades_report_pdf_enrollment_path(id: @record.id, signature_type: :qr_code, transcript: true), target: "_blank" %> -
+
+ <% if can?(:override_report_signature_type, @record) %> + <%= link_to 'Sem Assinatura', override_signature_grades_report_pdf_enrollment_path(id: @record.id, signature_type: :no_signature, transcript: true), target: "_blank" %> + <%= link_to 'Assinatura Manual', override_signature_grades_report_pdf_enrollment_path(id: @record.id, signature_type: :manual, transcript: true), target: "_blank" %> + <%= link_to 'Assinatura por QR Code', override_signature_grades_report_pdf_enrollment_path(id: @record.id, signature_type: :qr_code, transcript: true), target: "_blank" %> + <% else %> + <%= link_to 'Gerar', grades_report_pdf_enrollment_path(id: @record.id, format: :pdf), target: "_blank" %> + <% end %>
\ No newline at end of file diff --git a/app/views/enrollments/academic_transcript_pdf.pdf.prawn b/app/views/enrollments/academic_transcript_pdf.pdf.prawn index 028a820b..e5468748 100644 --- a/app/views/enrollments/academic_transcript_pdf.pdf.prawn +++ b/app/views/enrollments/academic_transcript_pdf.pdf.prawn @@ -12,7 +12,7 @@ new_document( :generate_report_without_watermark, @enrollment ), pdf_type: :transcript, - signature_override: @signature_override + signature_override: can?(:override_report_type, @enrollment) ? @signature_type : nil ) do |pdf| enrollment_student_header(pdf, enrollment: @enrollment) diff --git a/app/views/enrollments/grades_report_pdf.pdf.prawn b/app/views/enrollments/grades_report_pdf.pdf.prawn index 894056af..74f9b9e4 100644 --- a/app/views/enrollments/grades_report_pdf.pdf.prawn +++ b/app/views/enrollments/grades_report_pdf.pdf.prawn @@ -12,7 +12,7 @@ new_document( ) ), pdf_type: :grades_report, - signature_override: @signature_override + signature_override: can?(:generate_report_without_qrcode, @enrollment) ? @signature_override : nil ) do |pdf| enrollment_student_header(pdf, enrollment: @enrollment)