Bugzilla – Attachment 60949 Details for
Bug 18230
Generate Koha::Patron::Modification verification_token in ->new
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18230: Generate verification_token in Koha::Patron::Modification->new
Bug-18230-Generate-verificationtoken-in-KohaPatron.patch (text/plain), 2.62 KB, created by
Lari Taskula
on 2017-03-09 13:45:24 UTC
(
hide
)
Description:
Bug 18230: Generate verification_token in Koha::Patron::Modification->new
Filename:
MIME Type:
Creator:
Lari Taskula
Created:
2017-03-09 13:45:24 UTC
Size:
2.62 KB
patch
obsolete
>From b6d09fa0a2cee194121d434a68f9f88ce70d576d Mon Sep 17 00:00:00 2001 >From: Lari Taskula <lari.taskula@jns.fi> >Date: Wed, 8 Mar 2017 17:59:37 +0200 >Subject: [PATCH] Bug 18230: Generate verification_token in > Koha::Patron::Modification->new > >To test: >1. prove t/db_dependent/Koha/Patron/Modifications.t >--- > Koha/Patron/Modification.pm | 24 ++++++++++++++++++++++++ > t/db_dependent/Koha/Patron/Modifications.t | 14 +++++++++++++- > 2 files changed, 37 insertions(+), 1 deletion(-) > >diff --git a/Koha/Patron/Modification.pm b/Koha/Patron/Modification.pm >index 696f7e8..36a81cf 100644 >--- a/Koha/Patron/Modification.pm >+++ b/Koha/Patron/Modification.pm >@@ -27,6 +27,7 @@ use Koha::Patron::Modifications; > # TODO: Remove once Koha::Patron::Attribute(s) is implemented > use C4::Members::Attributes qw( SetBorrowerAttributes ); > >+use Digest::MD5 qw( md5_hex ); > use JSON; > use Try::Tiny; > >@@ -40,6 +41,29 @@ Koha::Patron::Modification - Class represents a request to modify or create a pa > > =cut > >+=head2 new >+ >+=cut >+ >+sub new { >+ my $class = shift; >+ my ($attributes) = @_; >+ >+ # Generate a verification_token unless provided >+ if ( ref $attributes && !$attributes->{verification_token} ) { >+ my $verification_token = md5_hex( time().{}.rand().{}.$$ ); >+ while ( Koha::Patron::Modifications->search( { >+ verification_token => $verification_token >+ } )->count() >+ ) { >+ $verification_token = md5_hex( time().{}.rand().{}.$$ ); >+ } >+ $attributes->{verification_token} = $verification_token; >+ } >+ >+ return $class->SUPER::new(@_); >+} >+ > =head2 store > > =cut >diff --git a/t/db_dependent/Koha/Patron/Modifications.t b/t/db_dependent/Koha/Patron/Modifications.t >index 0755858..ed2590d 100755 >--- a/t/db_dependent/Koha/Patron/Modifications.t >+++ b/t/db_dependent/Koha/Patron/Modifications.t >@@ -40,7 +40,7 @@ my $builder = t::lib::TestBuilder->new; > > subtest 'new() tests' => sub { > >- plan tests => 3; >+ plan tests => 4; > > $schema->storage->txn_begin; > >@@ -77,6 +77,18 @@ subtest 'new() tests' => sub { > 'Exception carries the right message' > ); > >+ # Create new pending modification, let verification_token be generated >+ # automatically >+ Koha::Patron::Modification->new( >+ { >+ surname => 'Koha-Suomi', >+ firstname => 'Suha-Koomi', >+ } >+ )->store(); >+ $borrower = Koha::Patron::Modifications->find( >+ { surname => 'Koha-Suomi' } ); >+ ok(length($borrower->verification_token) > 0, 'Verification token generated.'); >+ > $schema->storage->txn_rollback; > }; > >-- >1.9.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 18230
: 60949