Skip to content

Commit

Permalink
Merge branch 'master' into feature/DEMAD-364
Browse files Browse the repository at this point in the history
  • Loading branch information
vanessasotob committed Apr 18, 2022
2 parents 010ae5c + 2b3abb4 commit a2b3c49
Show file tree
Hide file tree
Showing 34 changed files with 772 additions and 44 deletions.
90 changes: 73 additions & 17 deletions app/controllers/admin/budget_investments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
:change_admitted, :proccess_correct, :change_correct, :send_correct, :process_inadmissible, :change_inadmissible, :send_inadmissible,
:inadmited_pdf,:correct_pdf, :grouped, :process_grouped, :process_desisted, :change_desist, :valuate, :valuating, :download_unfeasible,
:notification_unfeasible, :notification_model13, :unfeasible_model21, :unfeasible_model22, :unfeasible_model23,
:feasible_model31, :feasible_model32, :feasible_model33, :send_author_email, :supplementary_report, :add_supplementary_report
:feasible_model31, :feasible_model32, :feasible_model33, :send_author_email, :supplementary_report, :add_supplementary_report, :sign_download_unfeasible, :notification_unfeasible
]
before_action :load_data, only: [:edit, :update]
before_action :load_ballot, only: [:show, :index]
Expand Down Expand Up @@ -45,7 +45,12 @@ def edit
load_tags
end

def update
def update
if params.has_key?(:sign_download_unfeasible)
redirect_to download_unfeasible_admin_budget_budget_investment_path(@budget, @investment, format: :pdf, params: params) and return
elsif params.has_key?(:sign_notification_unfeasible)
redirect_to notification_unfeasible_admin_budget_budget_investment_path(@budget, @investment, format: :pdf, params: params) and return
end
@investment.terms_of_service = true
if !params[:budget_investment][:resolution_unfeasible_pdf].blank?
document_aux = @investment.budget_allegation_historics.first
Expand Down Expand Up @@ -594,28 +599,70 @@ def send_author_email
end
end

def download_unfeasible
respond_to do |format|
format.pdf do
render pdf: "Resolucion_de_inviabilidad",
layout: 'pdf.html',
page_size: 'A4',
encoding: "UTF-8"
def download_unfeasible
if params.has_key?(:sign_download_unfeasible)
document_aux = ::Budget::AllegationHistoric.new(budget_investment: @investment) if document_aux.blank?
name = "firma_electronica_#{Time.current.strftime("%Y-%m-%d %H:%M:%S")}.pdf"
respond_to do |format|
format.pdf do
render pdf: "Resolucion_de_inviabilidad",
layout: 'pdf.html',
save_to_file: Rails.root.join('public/system/documents/attachments', name),
page_size: 'A4',
encoding: "UTF-8"
end
end
doc = Document.create(title: "Resolución de inviabilidad", user: current_user, documentable: document_aux, attachment: File.new(Rails.root.join('public/system/documents/attachments', name)))
if document_aux.id.blank?
@investment.budget_allegation_historics = []
@investment.budget_allegation_historics << document_aux
end
esr = ElectronicSignRequest.create(document: doc, electronic_signer_configuration_id: params[:budget_investment][:electronic_signer_configuration_download])
response = PortafirmasApi.new.create_request(doc,esr)
flash[:alert] = "Se ha producido un error al mandar la petición" if response.blank? || !response.blank? && !response.success?
else
respond_to do |format|
format.pdf do
render pdf: "Resolucion_de_inviabilidad",
layout: 'pdf.html',
page_size: 'A4',
encoding: "UTF-8"
end
end
end

end

def notification_unfeasible
respond_to do |format|
format.pdf do
render pdf: "Notificacion_resolucion_de_inviabilidad",
layout: 'pdf.html',
page_size: 'A4',
encoding: "UTF-8"
if params.has_key?(:sign_notification_unfeasible)
document_aux = ::Budget::NotificationHistoric.new(budget_investment: @investment) if document_aux.blank?
name = "firma_electronica_#{Time.current.strftime("%Y-%m-%d %H:%M:%S")}.pdf"
respond_to do |format|
format.pdf do
render pdf: "Notificacion_resolucion_de_inviabilidad",
layout: 'pdf.html',
save_to_file: Rails.root.join('public/system/documents/attachments', name),
page_size: 'A4',
encoding: "UTF-8"
end
end
doc = Document.create(title: "Notificación de inviabilidad", user: current_user, documentable: document_aux, attachment: File.new(Rails.root.join('public/system/documents/attachments', name)))
if document_aux.id.blank?
@investment.budget_notification_historics = []
@investment.budget_notification_historics << document_aux
end
esr = ElectronicSignRequest.create(document: doc, electronic_signer_configuration_id: params[:budget_investment][:electronic_signer_configuration_notification])
response = PortafirmasApi.new.create_request(doc,esr)
flash[:alert] = "Se ha producido un error al mandar la petición" if response.blank? || !response.blank? && !response.success?
else
respond_to do |format|
format.pdf do
render pdf: "Notificacion_resolucion_de_inviabilidad",
layout: 'pdf.html',
page_size: 'A4',
encoding: "UTF-8"
end
end
end

end

def notification_model13
Expand Down Expand Up @@ -832,6 +879,15 @@ def load_budget

def load_investment
@investment = @budget.investments.find(params[:id])
historics = @investment.budget_valuation_historics
@budget_valuation_historics = []
historics.each do |h|
if h.documents.first.electronic_sign_request.nil?
@budget_valuation_historics << h
elsif h.documents.first.electronic_sign_request.signed == true
@budget_valuation_historics << h
end
end
end

def load_data
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
class Admin::ElectronicSignerConfigurationsController < Admin::BaseController

def index
if params[:sort_by] && params[:direction]
@electronic_signers = ElectronicSignerConfiguration.order_filter(params)
else
@electronic_signers = ElectronicSignerConfiguration.all
end
end

def new
@electronic_signer = ElectronicSignerConfiguration.new
end

def create
@electronic_signer = ElectronicSignerConfiguration.new(electronic_signer_params)
if @electronic_signer.save
notice = t("flash.actions.create.electronic_signer")
redirect_to admin_electronic_signer_configurations_path, notice: notice
else
render :new
end
end

def edit
@electronic_signer = ElectronicSignerConfiguration.find(params[:id])
end

def update
@electronic_signer = ElectronicSignerConfiguration.find(params[:id])
if @electronic_signer.update(electronic_signer_params)
notice = t("flash.actions.update.electronic_signer")
redirect_to admin_electronic_signer_configurations_path, notice: notice
else
render :edit
end
end

def destroy
@electronic_signer = ElectronicSignerConfiguration.find(params[:id])
if @electronic_signer.destroy
redirect_to admin_electronic_signer_configurations_path, notice: t("admin.electronic_signers.destroy.success_notice")
else
redirect_to admin_electronic_signer_configurations_path, alert: t("admin.electronic_signers.destroy.unable_notice")
end
end

def search
if params[:anything]
@electronic_signers = ElectronicSignerConfiguration.all.search_electronic_signer(params[:anything][:search_dni].split("=").last, params[:anything][:search_email].split("=").last).order(params[:sort])
respond_to :js
else
redirect_to admin_electronic_signer_configurations_path
end
end

private

def electronic_signer_params
params.require(:electronic_signer_configuration).permit(:full_name, :email, :dni, :zone)
end

end
91 changes: 91 additions & 0 deletions app/controllers/api/electronic_signs_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
class Api::ElectronicSignsController < ApplicationController
respond_to :json
skip_authorization_check
protect_from_forgery unless: -> { request.format.json? }
before_action :checktokenUser
before_action :authenticate_http_basic, except: [:download_signed_document]

def download_signed_document
begin
if @data_permit.to_s == "true" && !params[:request].blank?
if !params[:request][:documentList].blank? && !params[:request][:documentList][:document][0].blank?
identifier = params[:request][:documentList][:document][0][:identifier]
name = params[:request][:documentList][:document][0][:name]
end
if !identifier.blank? && !name.blank?
esr = ElectronicSignRequest.find(name)
if !esr.blank?
document = esr.document
response = PortafirmasApi.new.download_document(identifier, esr.hash_request)
if !response.blank?
xml = response.xml
decoded = xml[(xml.index("%PDF-1.4"))..(xml.index("%%EOF")+5)]

data = StringIO.new(decoded.strip)
data.class_eval do
attr_accessor :content_type, :original_filename
end

data.content_type = document.attachment.content_type
data.original_filename = document.attachment.original_filename
document.attachment = data

if document.save
esr.signed = true
esr.save
render json: "Documento con id #{document.id} actualizado con exito", status: 200, statusInfo: "OK"
else
error("Error al guardar el document con id #{document.id}. Errores: #{document.errors.full_messages}")
end
else
error("No se ha podido obtener la respuesta en la petición de descarga del documento")
end
else
error("No se ha podido obtener el objeto de petición de firma")
end
else
error("No se ha podido obtener el identificador y/o el nombre del documento")
end
else
Rails.logger.warn("No se han recibido los parámetros de autenticación o el parámetro request está en blanco")
error("No se han recibido los parámetros de autenticación o el parámetro request está en blanco.")
end
rescue => e
Rails.logger.error("Error al recibir el documento: #{e.to_s.force_encoding("UTF-8")}")
end
end

private

def error(error, message="", status = :error)
json_response({:error => {mensaje: "#{t("electronic_signs.errors.#{error}")}: #{message}", codigo: t("electronic_signs.cod_errors.#{error}")}}, status)
end

def success(message)
json_response(message)
end

def json_response(message, status = :ok)
begin
if status.to_s != "ok"
Rails.logger.error("#{status.to_s == "ok" ? "INFO-ELECTRONIC_SIGNS: " : "ERROR-ELECTRONIC_SIGNS: "}#{message}")
end
rescue
end
render json: message, status: status
end

def checktokenUser
if !params[:authentication].blank? && !params[:authentication][:userName].blank? && !params[:authentication][:password].blank?
if Rails.application.secrets.user_auth_pfirmin == params[:authentication][:userName] && Rails.application.secrets.password_auth_pfirmin == params[:authentication][:password]
@data_permit = true
else
@data_permit = false
error("Parámetros de autenticación erróneos")
end
else
error("No se han recibido los parámetros de autenticación")
end
end

end
60 changes: 48 additions & 12 deletions app/controllers/valuation/budget_investments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ class Valuation::BudgetInvestmentsController < Valuation::BaseController

feature_flag :budgets

before_action :restrict_access_to_assigned_items, only: [:show, :edit, :valuate,:generate_report, :sign_report]
before_action :restrict_access, only: [:edit, :valuate,:generate_report, :sign_report]
before_action :restrict_access_to_assigned_items, only: [:show, :edit, :valuate,:generate_report, :save_pdf, :sign_report]
before_action :restrict_access, only: [:edit, :valuate,:generate_report, :save_pdf, :sign_report]
before_action :load_budget
before_action :load_investment, only: [:show, :edit, :valuate, :generate_report, :sign_report]
before_action :load_investment, only: [:show, :edit, :valuate, :generate_report, :save_pdf, :sign_report]
before_action :load_data, only: [:edit, :update, :new, :create, :valuate]

has_orders %w{oldest}, only: [:show, :edit]
Expand Down Expand Up @@ -109,8 +109,8 @@ def valuate
@investment.update_attribute(:valuation_status_id, @investment.assign_status.present? ? @investment.assign_status.id : nil)
end
end
if params.has_key?(:download_pdf)
redirect_to generate_report_valuation_budget_budget_investment_path(@budget, @investment, format: :pdf)
if params.has_key?(:download_pdf) || params.has_key?(:electronic_signing)
redirect_to generate_report_valuation_budget_budget_investment_path(@budget, @investment, format: :pdf, params: params)
elsif params.has_key?(:download_allegation)
redirect_to download_unfeasible_admin_budget_budget_investment_path(@budget, @investment, format: :pdf)
else
Expand All @@ -136,14 +136,41 @@ def generate_report
@literal = "la"
@literal = "el" if @investment.competent_organism.name.include? "Organismo Autónomo"
@literal = "el" if @investment.competent_organism.name.include? "Instituto"
respond_to do |format|
format.pdf do
render pdf: "informe_tecnico",
layout: 'pdf.html',
page_size: 'A4',
encoding: "UTF-8"
document_aux = ::Budget::ValuationHistoric.new(budget_investment: @investment)
if @investment.valuation_status == ::Budget::Investment::Status.find_by(name: "Evaluación alegaciones")
title = "PDF alegaciones Firmado"
else
title = "PDF Firmado"
end
if params.has_key?(:electronic_signing)
name = "firma_electronica_#{Time.current.strftime("%Y-%m-%d %H:%M:%S")}.pdf"
respond_to do |format|
format.pdf do
render pdf: "informe_tecnico",
layout: 'pdf.html',
save_to_file: Rails.root.join('public/system/documents/attachments', name),
page_size: 'A4',
encoding: "UTF-8"
end
end
end
doc = Document.create(title: title, user: current_user, documentable: document_aux, attachment: File.new(Rails.root.join('public/system/documents/attachments', name)))
if document_aux.id.blank? && @investment.valuation_status != ::Budget::Investment::Status.find_by(name: "Evaluación alegaciones")
@investment.budget_valuation_historics = []
end
@investment.budget_valuation_historics << document_aux
esr = ElectronicSignRequest.create(document: doc, electronic_signer_configuration_id: params[:budget_investment][:electronic_signer_configuration_id])
response = PortafirmasApi.new.create_request(doc,esr)
flash[:alert] = "Se ha producido un error al mandar la petición" if response.blank? || !response.blank? && !response.success?
else
respond_to do |format|
format.pdf do
render pdf: "informe_tecnico",
layout: 'pdf.html',
page_size: 'A4',
encoding: "UTF-8"
end
end
end
end

private
Expand Down Expand Up @@ -176,6 +203,15 @@ def load_budget

def load_investment
@investment = @budget.investments.find params[:id]
historics = @investment.budget_valuation_historics
@budget_valuation_historics = []
historics.each do |h|
if h.documents.first.electronic_sign_request.nil?
@budget_valuation_historics << h
elsif h.documents.first.electronic_sign_request.signed == true
@budget_valuation_historics << h
end
end
end

def heading_filters
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/admin_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def menu_profiles?
end

def menu_settings?
["settings", "tags", "geozones", "images", "content_blocks", "permissions", "permission_activities"].include?(controller_name) &&
["settings", "tags", "geozones", "images", "content_blocks", "permissions", "permission_activities", "electronic_signer_configurations"].include?(controller_name) &&
controller.class.parent != Admin::Poll::Questions::Answers
end

Expand Down
1 change: 1 addition & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'base64'
module ApplicationHelper

def home_page?
Expand Down
Loading

0 comments on commit a2b3c49

Please sign in to comment.