From b9a87d93c713b05e89026d5a018f6bea71a81794 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 2 Mar 2023 13:41:16 +0100 Subject: [PATCH] Bug 33104: Encrypt password --- Koha/Acquisition/Bookseller.pm | 7 ++- Koha/Acquisition/Bookseller/Interface.pm | 33 ++++++++++++++ .../prog/en/modules/acqui/supplier.tt | 43 +++++++++++++------ 3 files changed, 70 insertions(+), 13 deletions(-) diff --git a/Koha/Acquisition/Bookseller.pm b/Koha/Acquisition/Bookseller.pm index 13f829e2af6..3aee699edbf 100644 --- a/Koha/Acquisition/Bookseller.pm +++ b/Koha/Acquisition/Bookseller.pm @@ -122,7 +122,12 @@ sub interfaces { sub { $self->interfaces->delete; for my $interface (@$interfaces) { - $self->_result->add_to_aqbookseller_interfaces($interface); + Koha::Acquisition::Bookseller::Interface->new( + { + %$interface, + vendor_id => $self->id, + } + )->store; } } ); diff --git a/Koha/Acquisition/Bookseller/Interface.pm b/Koha/Acquisition/Bookseller/Interface.pm index b038f539e4e..a7a232f4546 100644 --- a/Koha/Acquisition/Bookseller/Interface.pm +++ b/Koha/Acquisition/Bookseller/Interface.pm @@ -16,6 +16,7 @@ package Koha::Acquisition::Bookseller::Interface; # along with Koha; if not, see . use Modern::Perl; +use Koha::Encryption; use base qw( Koha::Object ); @@ -29,6 +30,38 @@ Koha::Acquisition::Bookseller::Interface - Koha Bookseller interface Object clas =cut +=head3 store + + $self->store; + +Specific store method to encrypt the password. + +=cut + +sub store { + my ($self) = @_; + + if ( $self->password ) { + $self->password(Koha::Encryption->new->encrypt_hex($self->password)); + } + + return $self->SUPER::store; +} + +=head3 plain_text_password + + my $plain_text_password = $self->plain_text_password; + +Decrypt the password and return its plain text form. + +=cut + +sub plain_text_password { + my ($self) = @_; + return Koha::Encryption->new->decrypt_hex($self->password) + if $self->password; +} + =head3 _type =cut diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt index 418f406a2a2..23fbed84ace 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt @@ -364,18 +364,28 @@

Interfaces

- [% FOR interface IN vendor.interfaces %] + [% FOR i IN vendor.interfaces %]
- [% interface.name | html %] + [% i.name | html %]
    -
  • -
  • Type: [% interface.type | html %]
  • -
  • URI: [% interface.uri | html %]
  • -
  • Login: [% interface.login | html %]
  • -
  • Password: [% interface.password | html %]
  • -
  • Account email: [% interface.account_email | html %]
  • -
  • Notes : [% interface.notes | html %]
  • - + [% IF i.type %] +
  • Type: [% i.type | html %]
  • + [% END %] + [% IF i.uri %] +
  • URI: [% i.uri | html %]
  • + [% END %] + [% IF i.login %] +
  • Login: [% i.login | html %]
  • + [% END %] + [% IF i.password %] +
  • Password: Show
  • + [% END %] + [% IF i.account_email %] +
  • Account email: [% i.account_email | html %]
  • + [% END %] + [% IF i.notes %] +
  • Notes : [% i.notes | html %]
  • + [% END %]
[% END %] @@ -520,9 +530,14 @@ } [% IF vendor %] - let interfaces = [% To.json(vendor.interfaces.unblessed) | $raw %]; + let interfaces = []; + [% FOR i_object IN vendor.interfaces %] + [% SET i = i_object.unblessed %] + [% SET i.password = i_object.plain_text_password %] + interfaces.push([% To.json(i) | $raw %]); + [% END %] [% ELSE %] - let interfaces = []; + let interfaces = []; [% END %] function serialize_interface_form(){ interfaces = []; @@ -627,6 +642,10 @@ $(this).next('.contact_claimissues_hidden').val($(this).is(':checked') ? '1' : '0'); }); + $('body').on('click', '.show_password', null, function(e){ + e.preventDefault(); + $(this).parent().replaceWith($(this).data('plain-text-password')); + }); refresh_aliases(); refresh_interfaces(); -- 2.25.1