forked from consuldemocracy/consuldemocracy
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/DEMAD-364
- Loading branch information
Showing
34 changed files
with
772 additions
and
44 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
63 changes: 63 additions & 0 deletions
63
app/controllers/admin/electronic_signer_configurations_controller.rb
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,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 |
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,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 |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
require 'base64' | ||
module ApplicationHelper | ||
|
||
def home_page? | ||
|
Oops, something went wrong.