From 6f01bf26617dea7b194dac5767a0111b12941826 Mon Sep 17 00:00:00 2001 From: Finn Date: Wed, 23 Aug 2017 16:47:29 +0100 Subject: [PATCH 1/6] Fixed validation removing redundant code --- lib/Pear/LocalLoop/Controller/Api/Register.pm | 1 - lib/Pear/LocalLoop/Controller/Api/User.pm | 1 - t/api/register.t | 175 +++++++++--------- 3 files changed, 87 insertions(+), 90 deletions(-) diff --git a/lib/Pear/LocalLoop/Controller/Api/Register.pm b/lib/Pear/LocalLoop/Controller/Api/Register.pm index ee760ee..da6805a 100644 --- a/lib/Pear/LocalLoop/Controller/Api/Register.pm +++ b/lib/Pear/LocalLoop/Controller/Api/Register.pm @@ -102,7 +102,6 @@ sub post_register{ } elsif ($usertype eq 'organisation') { - my $fullAddress = $validation->param('fulladdress'); $c->schema->txn_do( sub { $c->schema->resultset('AccountToken')->find({ diff --git a/lib/Pear/LocalLoop/Controller/Api/User.pm b/lib/Pear/LocalLoop/Controller/Api/User.pm index ef9ec89..cb2396f 100644 --- a/lib/Pear/LocalLoop/Controller/Api/User.pm +++ b/lib/Pear/LocalLoop/Controller/Api/User.pm @@ -148,7 +148,6 @@ sub post_account_update { } elsif ( defined $user->organisation_id ) { - my $fullAddress = $validation->param('fulladdress'); $c->schema->txn_do( sub { $user->organisation->update({ diff --git a/t/api/register.t b/t/api/register.t index 40020ac..a1a20ec 100644 --- a/t/api/register.t +++ b/t/api/register.t @@ -92,12 +92,12 @@ $t->post_ok('/api/register' => json => $testJson) #Blank name $testJson = { 'usertype' => 'customer', - 'token' => 'a', - 'display_name' => 'test name', - 'full_name' => '', - 'email' => 'a@b.com', - 'postcode' => 'LA1 1AA', - 'password' => 'Meh', + 'token' => 'a', + 'display_name' => 'test name', + 'full_name' => '', + 'email' => 'a@b.com', + 'postcode' => 'LA1 1AA', + 'password' => 'Meh', 'year_of_birth' => 2005 }; $t->post_ok('/api/register' => json => $testJson) @@ -108,12 +108,12 @@ $t->post_ok('/api/register' => json => $testJson) #Blank name $testJson = { 'usertype' => 'customer', - 'token' => 'a', - 'display_name' => '', - 'full_name' => 'test name', - 'email' => 'a@b.com', - 'postcode' => 'LA1 1AA', - 'password' => 'Meh', + 'token' => 'a', + 'display_name' => '', + 'full_name' => 'test name', + 'email' => 'a@b.com', + 'postcode' => 'LA1 1AA', + 'password' => 'Meh', 'year_of_birth' => 2005 }; $t->post_ok('/api/register' => json => $testJson) @@ -125,13 +125,13 @@ $t->post_ok('/api/register' => json => $testJson) #Valid customer $testJson = { - 'usertype' => 'customer', - 'token' => 'a', - 'full_name' => 'test name', - 'display_name' => 'test name', - 'email' => 'a@b.com', - 'postcode' => 'LA1 1AA', - 'password' => 'Meh', + 'usertype' => 'customer', + 'token' => 'a', + 'full_name' => 'test name', + 'display_name' => 'test name', + 'email' => 'a@b.com', + 'postcode' => 'LA1 1AA', + 'password' => 'Meh', 'year_of_birth' => 2005 }; $t->post_ok('/api/register' => json => $testJson) @@ -140,35 +140,35 @@ $t->post_ok('/api/register' => json => $testJson) #Valid customer2 $testJson = { - 'usertype' => 'customer', - 'token' => 'b', - 'full_name' => 'test name', - 'display_name' => 'test name', - 'email' => 'b@c.com', - 'postcode' => 'LA1 1AA', - 'password' => 'Meh', + 'usertype' => 'customer', + 'token' => 'b', + 'full_name' => 'test name', + 'display_name' => 'test name', + 'email' => 'b@c.com', + 'postcode' => 'LA1 1AA', + 'password' => 'Meh', 'year_of_birth' => 2005 }; $t->post_ok('/api/register' => json => $testJson) ->or($dump_error) - ->status_is(200) + ->status_is(200) ->or($dump_error) ->json_is('/success', Mojo::JSON->true) ->or($dump_error); #Valid customer3 $testJson = { - 'usertype' => 'customer', - 'token' => 'c', - 'full_name' => 'test name', - 'display_name' => 'test name', - 'email' => 'c@d.com', - 'postcode' => 'LA1 1AA', - 'password' => 'Meh', + 'usertype' => 'customer', + 'token' => 'c', + 'full_name' => 'test name', + 'display_name' => 'test name', + 'email' => 'c@d.com', + 'postcode' => 'LA1 1AA', + 'password' => 'Meh', 'year_of_birth' => 2005 }; $t->post_ok('/api/register' => json => $testJson) - ->status_is(200) + ->status_is(200) ->json_is('/success', Mojo::JSON->true); #email missing JSON @@ -186,53 +186,53 @@ $t->post_ok('/api/register' => json => $testJson) ->json_is('/success', Mojo::JSON->false) ->content_like(qr/no email sent/i); -#invalid email 1 +#invalid email 1 $testJson = { 'usertype' => 'customer', - 'token' => 'd', - 'full_name' => 'test name', - 'display_name' => 'test name', - 'email' => 'dfsd@.com', - 'postcode' => 'LA1 1AA', - 'password' => 'Meh', + 'token' => 'd', + 'full_name' => 'test name', + 'display_name' => 'test name', + 'email' => 'dfsd@.com', + 'postcode' => 'LA1 1AA', + 'password' => 'Meh', 'year_of_birth' => 2006 }; $t->post_ok('/api/register' => json => $testJson) - ->status_is(400) + ->status_is(400) ->json_is('/success', Mojo::JSON->false) ->content_like(qr/email/i) ->content_like(qr/invalid/i); #invalid email 2 $testJson = { - 'usertype' => 'customer', - 'token' => 'd', - 'full_name' => 'test name', - 'display_name' => 'test name', - 'email' => 'dfsd@com', - 'postcode' => 'LA1 1AA', - 'password' => 'Meh', + 'usertype' => 'customer', + 'token' => 'd', + 'full_name' => 'test name', + 'display_name' => 'test name', + 'email' => 'dfsd@com', + 'postcode' => 'LA1 1AA', + 'password' => 'Meh', 'year_of_birth' => 2006 }; $t->post_ok('/api/register' => json => $testJson) - ->status_is(400) + ->status_is(400) ->json_is('/success', Mojo::JSON->false) ->content_like(qr/email/i) ->content_like(qr/invalid/i); #Email exists $testJson = { - 'usertype' => 'customer', - 'token' => 'd', - 'full_name' => 'test name', - 'display_name' => 'test name', - 'email' => 'a@b.com', - 'postcode' => 'LA1 1AA', - 'password' => 'Meh', + 'usertype' => 'customer', + 'token' => 'd', + 'full_name' => 'test name', + 'display_name' => 'test name', + 'email' => 'a@b.com', + 'postcode' => 'LA1 1AA', + 'password' => 'Meh', 'year_of_birth' => 2006 }; $t->post_ok('/api/register' => json => $testJson) - ->status_is(403) + ->status_is(403) ->json_is('/success', Mojo::JSON->false) ->content_like(qr/email/i) ->content_like(qr/exists/i); @@ -288,16 +288,15 @@ $t->post_ok('/api/register' => json => $testJson) #Invalid user type $testJson = { - 'usertype' => 'organisation1', - 'token' => 'f', - 'name' => 'test name', - 'email' => 'org@org.com', - 'postcode' => 'LA1 1AA', - 'password' => 'Meh', - 'fulladdress' => 'mary lane testing....' + 'usertype' => 'organisation1', + 'token' => 'f', + 'name' => 'test name', + 'email' => 'org@org.com', + 'postcode' => 'LA1 1AA', + 'password' => 'Meh', }; $t->post_ok('/api/register' => json => $testJson) - ->status_is(400) + ->status_is(400) ->json_is('/success', Mojo::JSON->false) ->content_like(qr/usertype/i) ->content_like(qr/invalid/i); @@ -320,29 +319,29 @@ $t->post_ok('/api/register' => json => $testJson) #Age is invalid $testJson = { - 'usertype' => 'customer', - 'token' => 'f', - 'full_name' => 'test name', - 'display_name' => 'test name', - 'email' => 'test@example.com', - 'postcode' => 'LA1 1AA', - 'password' => 'Meh', + 'usertype' => 'customer', + 'token' => 'f', + 'full_name' => 'test name', + 'display_name' => 'test name', + 'email' => 'test@example.com', + 'postcode' => 'LA1 1AA', + 'password' => 'Meh', 'year_of_birth' => 'invalid' }; $t->post_ok('/api/register' => json => $testJson) - ->status_is(400) + ->status_is(400) ->json_is('/success', Mojo::JSON->false) ->content_like(qr/year_of_birth/i) ->content_like(qr/invalid/i); #full address missing JSON $testJson = { - 'usertype' => 'organisation', - 'token' => 'f', - 'name' => 'test org', - 'email' => 'org@org.com', - 'postcode' => 'LA1 1AA', - 'password' => 'Meh', + 'usertype' => 'organisation', + 'token' => 'f', + 'name' => 'test org', + 'email' => 'org@org.com', + 'postcode' => 'LA1 1AA', + 'password' => 'Meh', }; $t->post_ok('/api/register' => json => $testJson) ->status_is(400) @@ -353,17 +352,17 @@ $t->post_ok('/api/register' => json => $testJson) #Organisation valid $testJson = { - 'usertype' => 'organisation', - 'token' => 'f', - 'name' => 'org name', - 'email' => 'org@org.com', - 'postcode' => 'LA1 1AA', - 'password' => 'Meh', + 'usertype' => 'organisation', + 'token' => 'f', + 'name' => 'org name', + 'email' => 'org@org.com', + 'postcode' => 'LA1 1AA', + 'password' => 'Meh', 'street_name' => 'mary lane testing....', 'town' => 'Lancaster', }; $t->post_ok('/api/register' => json => $testJson) - ->status_is(200) + ->status_is(200) ->json_is('/success', Mojo::JSON->true); is $t->app->schema->resultset('User')->count, 4, 'Correct user count'; From 4c7836c9f6f7ca4ab3c56071b45c1f9c51dd63eb Mon Sep 17 00:00:00 2001 From: Finn Date: Wed, 23 Aug 2017 16:50:04 +0100 Subject: [PATCH 2/6] Initial server code added for updating user account --- lib/Pear/LocalLoop.pm | 1 + lib/Pear/LocalLoop/Controller/Admin/Users.pm | 67 ++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/lib/Pear/LocalLoop.pm b/lib/Pear/LocalLoop.pm index 4813064..c41371d 100644 --- a/lib/Pear/LocalLoop.pm +++ b/lib/Pear/LocalLoop.pm @@ -169,6 +169,7 @@ sub startup { $admin_routes->get('/users/:id')->to('admin-users#read'); $admin_routes->post('/users/:id')->to('admin-users#update'); $admin_routes->post('/users/:id/delete')->to('admin-users#delete'); + $admin_routes->post('/users/:id/edit')->to('admin-users#edit'); $admin_routes->get('/organisations')->to('admin-organisations#list'); $admin_routes->get('/organisations/add')->to('admin-organisations#add_org'); diff --git a/lib/Pear/LocalLoop/Controller/Admin/Users.pm b/lib/Pear/LocalLoop/Controller/Admin/Users.pm index 2fbdd17..296a0cf 100644 --- a/lib/Pear/LocalLoop/Controller/Admin/Users.pm +++ b/lib/Pear/LocalLoop/Controller/Admin/Users.pm @@ -27,6 +27,73 @@ sub read { } } +sub edit { + my $c = shift; + + my $id = $c->param('id'); + + if ( my $user = $c->result_set->find($id) ) { + $c->stash( user => $user ); + } else { + $c->flash( error => 'No User found' ); + $c->redirect_to( '/admin/users/' . $id ); + } + + my $validation = $c->validation; + + $validation->required('email')->not_in_resultset( 'email', $user->id ); + $validation->required('postcode')->postcode; + $validation->optional('new_password'); + + if ( defined $user->customer_id ) { + $validation->required('display_name'); + $validation->required('full_name'); + } elsif ( defined $user->organisation_id ) { + $validation->required('name'); + $validation->required('street_name'); + $validation->required('town'); + } + + if ( $validation->has_error ) { + $c->flash( error => 'The validation has failed' ); + $c->app->log->warn(Dumper $validation); + return $c->redirect_to( '/admin/users/' . $id ); + } + + if ( defined $user->customer_id ){ + + $c->schema->txn_do( sub { + $user->customer->update({ + full_name => $validation->param('full_name'), + display_name => $validation->param('display_name'), + postcode => $validation->param('postcode'), + }); + $user->update({ + email => $validation->param('email'), + ( defined $validation->param('new_password') ? ( password => $validation->param('new_password') ) : () ), + }); + }); + + } + elsif ( defined $user->organisation_id ) { + + $c->schema->txn_do( sub { + $user->organisation->update({ + name => $validation->param('name'), + street_name => $validation->param('street_name'), + town => $validation->param('town'), + postcode => $validation->param('postcode'), + }); + $user->update({ + email => $validation->param('email'), + ( defined $validation->param('new_password') ? ( password => $validation->param('new_password') ) : () ), + }); + }); + } + + $c->redirect_to( '/admin/users/' . $id ); +} + sub update { my $c = shift; $c->redirect_to( '/admin/users' ); From 9865130666757adc4b70b4fc2b11c88f9e9c43a2 Mon Sep 17 00:00:00 2001 From: Finn Date: Wed, 23 Aug 2017 18:42:19 +0100 Subject: [PATCH 3/6] Added user account stuff test and some fixes --- lib/Pear/LocalLoop/Controller/Admin/Users.pm | 78 +++++++++------ t/admin/user.t | 99 ++++++++++++++++++++ 2 files changed, 149 insertions(+), 28 deletions(-) create mode 100644 t/admin/user.t diff --git a/lib/Pear/LocalLoop/Controller/Admin/Users.pm b/lib/Pear/LocalLoop/Controller/Admin/Users.pm index 296a0cf..d48e259 100644 --- a/lib/Pear/LocalLoop/Controller/Admin/Users.pm +++ b/lib/Pear/LocalLoop/Controller/Admin/Users.pm @@ -1,6 +1,8 @@ package Pear::LocalLoop::Controller::Admin::Users; use Mojo::Base 'Mojolicious::Controller'; +use Data::Dumper; + has result_set => sub { my $c = shift; return $c->schema->resultset('User'); @@ -32,16 +34,19 @@ sub edit { my $id = $c->param('id'); - if ( my $user = $c->result_set->find($id) ) { - $c->stash( user => $user ); - } else { + my $user; + + unless ( $user = $c->result_set->find($id) ) { $c->flash( error => 'No User found' ); - $c->redirect_to( '/admin/users/' . $id ); + return $c->redirect_to( '/admin/users/' . $id ); } my $validation = $c->validation; - $validation->required('email')->not_in_resultset( 'email', $user->id ); + my $not_myself_user_rs = $c->result_set->search({ + id => { "!=" => $user->id }, + }); + $validation->required('email')->email->not_in_resultset( 'email', $not_myself_user_rs ); $validation->required('postcode')->postcode; $validation->optional('new_password'); @@ -62,34 +67,51 @@ sub edit { if ( defined $user->customer_id ){ - $c->schema->txn_do( sub { - $user->customer->update({ - full_name => $validation->param('full_name'), - display_name => $validation->param('display_name'), - postcode => $validation->param('postcode'), + try { + $c->schema->txn_do( sub { + $user->customer->update({ + full_name => $validation->param('full_name'), + display_name => $validation->param('display_name'), + postcode => $validation->param('postcode'), + }); + $user->update({ + email => $validation->param('email'), + ( defined $validation->param('new_password') ? ( password => $validation->param('new_password') ) : () ), + }); }); - $user->update({ - email => $validation->param('email'), - ( defined $validation->param('new_password') ? ( password => $validation->param('new_password') ) : () ), - }); - }); - + } finally { + if ( @_ ) { + $c->flash( error => 'Something went wrong Updating the User' ); + $c->app->log->warn(Dumper @_); + } else { + $c->flash( success => 'Updated User' ); + }; + } } elsif ( defined $user->organisation_id ) { - $c->schema->txn_do( sub { - $user->organisation->update({ - name => $validation->param('name'), - street_name => $validation->param('street_name'), - town => $validation->param('town'), - postcode => $validation->param('postcode'), + try { + $c->schema->txn_do( sub { + $user->organisation->update({ + name => $validation->param('name'), + street_name => $validation->param('street_name'), + town => $validation->param('town'), + postcode => $validation->param('postcode'), + }); + $user->update({ + email => $validation->param('email'), + ( defined $validation->param('new_password') ? ( password => $validation->param('new_password') ) : () ), + }); }); - $user->update({ - email => $validation->param('email'), - ( defined $validation->param('new_password') ? ( password => $validation->param('new_password') ) : () ), - }); - }); - } + } finally { + if ( @_ ) { + $c->flash( error => 'Something went wrong Updating the User' ); + $c->app->log->warn(Dumper @_); + } else { + $c->flash( success => 'Updated User' ); + } + } + }; $c->redirect_to( '/admin/users/' . $id ); } diff --git a/t/admin/user.t b/t/admin/user.t new file mode 100644 index 0000000..86386e0 --- /dev/null +++ b/t/admin/user.t @@ -0,0 +1,99 @@ +use Mojo::Base -strict; + +use Test::More; +use Mojo::JSON; +use Test::Pear::LocalLoop; + +my $framework = Test::Pear::LocalLoop->new; +my $t = $framework->framework; +my $schema = $t->app->schema; + +my $user = $schema->resultset('User')->create({ + email => 'admin@example.com', + password => 'abc123', + administrator => {}, +}); + +is $schema->resultset('Administrator')->count, 1, 'Admin Created'; + +my $user1 = { + token => 'a', + full_name => 'Test User1', + display_name => 'Test User1', + email => 'test1@example.com', + postcode => 'LA1 1AA', + password => 'abc123', + year_of_birth => 2006, +}; + +my $org = { + token => 'e', + email => 'test50@example.com', + name => '7th Heaven', + street_name => 'Slums, Sector 7', + town => 'Midgar', + postcode => 'WC1E 6AD', + password => 'abc123', +}; + +$schema->resultset('AccountToken')->create({ name => $_->{token} }) + for ( $user1, $org ); + +$framework->register_customer($user1); + +$framework->register_organisation($org); + +#login to admin +$t->ua->max_redirects(10); +$t->post_ok('/admin', form => { + email => 'admin@example.com', + password => 'abc123', +})->status_is(200); + +#Read customer user +$t->get_ok('/admin/users/1/') + ->status_is(200); + +#Read organisation user +$t->get_ok('/admin/users/2/') + ->status_is(200); + +#Valid organisation user update +$t->post_ok('/admin/users/1/edit', form => { + email => 'test51@example.com', + new_password => 'abc123', + name => '7th Heaven', + street_name => 'Slums, Sector 7', + town => 'Midgar', + postcode => 'WC1E 6AD', +})->status_is(200)->content_like(qr/Updated User/); + +#Failed validation on organisation user from wrong email +$t->post_ok('/admin/users/1/edit', form => { + email => 'test55@example.com', + new_password => 'abc123', + name => '7th Heaven', + street_name => 'Slums, Sector 7', + town => 'Midgar', + postcode => 'WC1E 6AD', +})->content_like(qr/The validation has failed/); + +#Failed validation on organisation user from no postcode +$t->post_ok('/admin/users/1/edit', form => { + email => 'test50@example.com', + new_password => 'abc123', + name => '7th Heaven', + street_name => 'Slums, Sector 7', + town => 'Midgar', +})->content_like(qr/The validation has failed/); + +#Failed validation on organisation user from no street name +$t->post_ok('/admin/users/1/edit', form => { + email => 'test50@example.com', + new_password => 'abc123', + name => '7th Heaven', + town => 'Midgar', + postcode => 'WC1E 6AD', +})->content_like(qr/The validation has failed/); + +done_testing(); From db45f710c327186ab62ad5a40344dca20bc9b911 Mon Sep 17 00:00:00 2001 From: Finn Date: Thu, 24 Aug 2017 12:37:53 +0100 Subject: [PATCH 4/6] Code fixed, now functioning account edit --- lib/Pear/LocalLoop/Controller/Admin/Users.pm | 21 +++-- templates/admin/users/read.html.ep | 85 ++++++++++++++++---- 2 files changed, 85 insertions(+), 21 deletions(-) diff --git a/lib/Pear/LocalLoop/Controller/Admin/Users.pm b/lib/Pear/LocalLoop/Controller/Admin/Users.pm index d48e259..2fbc110 100644 --- a/lib/Pear/LocalLoop/Controller/Admin/Users.pm +++ b/lib/Pear/LocalLoop/Controller/Admin/Users.pm @@ -1,17 +1,28 @@ package Pear::LocalLoop::Controller::Admin::Users; use Mojo::Base 'Mojolicious::Controller'; +use Try::Tiny; use Data::Dumper; -has result_set => sub { +has user_result_set => sub { my $c = shift; return $c->schema->resultset('User'); }; +has customer_result_set => sub { + my $c = shift; + return $c->schema->resultset('Customer'); +}; + +has organisation_result_set => sub { + my $c = shift; + return $c->schema->resultset('Organisation'); +}; + sub index { my $c = shift; - my $user_rs = $c->result_set; + my $user_rs = $c->user_result_set; $user_rs->result_class('DBIx::Class::ResultClass::HashRefInflator'); $c->stash( users => [ $user_rs->all ] ); } @@ -21,7 +32,7 @@ sub read { my $id = $c->param('id'); - if ( my $user = $c->result_set->find($id) ) { + if ( my $user = $c->user_result_set->find($id) ) { $c->stash( user => $user ); } else { $c->flash( error => 'No User found' ); @@ -36,14 +47,14 @@ sub edit { my $user; - unless ( $user = $c->result_set->find($id) ) { + unless ( $user = $c->user_result_set->find($id) ) { $c->flash( error => 'No User found' ); return $c->redirect_to( '/admin/users/' . $id ); } my $validation = $c->validation; - my $not_myself_user_rs = $c->result_set->search({ + my $not_myself_user_rs = $c->user_result_set->search({ id => { "!=" => $user->id }, }); $validation->required('email')->email->not_in_resultset( 'email', $not_myself_user_rs ); diff --git a/templates/admin/users/read.html.ep b/templates/admin/users/read.html.ep index eaca969..9cf6740 100644 --- a/templates/admin/users/read.html.ep +++ b/templates/admin/users/read.html.ep @@ -11,20 +11,73 @@ Success! <%= $success %> % } -
-
- - -
-
- - -
-
- - -
-
- -
+ +

+ User Details +

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ % if ( my $customer_rs = $user->customer ) { +

+ Customer Details +

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ % } elsif ( my $org_rs = $user->organisation ) { +

+ Organisation Details +

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ % } else { +

+ User is not a customer or an organisation +

+ % } + +
+ +
From 7c25ecccfdce93a88595d50f1f3fa891a7c850e5 Mon Sep 17 00:00:00 2001 From: Finn Date: Thu, 24 Aug 2017 12:48:32 +0100 Subject: [PATCH 5/6] Entry field and test fixed --- t/admin/user.t | 52 ++++++++++++++++++++---------- templates/admin/users/read.html.ep | 2 +- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/t/admin/user.t b/t/admin/user.t index 86386e0..a531600 100644 --- a/t/admin/user.t +++ b/t/admin/user.t @@ -51,15 +51,43 @@ $t->post_ok('/admin', form => { })->status_is(200); #Read customer user -$t->get_ok('/admin/users/1/') - ->status_is(200); - -#Read organisation user $t->get_ok('/admin/users/2/') ->status_is(200); +#Read organisation user +$t->get_ok('/admin/users/3/') + ->status_is(200); + +#Valid customer user update +$t->post_ok('/admin/users/2/edit', form => { + email => 'test12@example.com', + new_password => 'abc123', + full_name => 'Test User1', + display_name => 'Test User1', + town => 'Midgar', + postcode => 'WC1E 6AD', +})->status_is(200)->content_like(qr/Updated User/); + +#Failed validation on customer user from no postcode +$t->post_ok('/admin/users/2/edit', form => { + email => 'test12@example.com', + new_password => 'abc123', + full_name => 'Test User1', + display_name => 'Test User1', + town => 'Midgar', +})->content_like(qr/The validation has failed/); + +#Failed validation on customer user from no display name +$t->post_ok('/admin/users/2/edit', form => { + email => 'test12@example.com', + new_password => 'abc123', + full_name => 'Test User1', + town => 'Midgar', + postcode => 'WC1E 6AD', +})->content_like(qr/The validation has failed/); + #Valid organisation user update -$t->post_ok('/admin/users/1/edit', form => { +$t->post_ok('/admin/users/3/edit', form => { email => 'test51@example.com', new_password => 'abc123', name => '7th Heaven', @@ -68,18 +96,8 @@ $t->post_ok('/admin/users/1/edit', form => { postcode => 'WC1E 6AD', })->status_is(200)->content_like(qr/Updated User/); -#Failed validation on organisation user from wrong email -$t->post_ok('/admin/users/1/edit', form => { - email => 'test55@example.com', - new_password => 'abc123', - name => '7th Heaven', - street_name => 'Slums, Sector 7', - town => 'Midgar', - postcode => 'WC1E 6AD', -})->content_like(qr/The validation has failed/); - #Failed validation on organisation user from no postcode -$t->post_ok('/admin/users/1/edit', form => { +$t->post_ok('/admin/users/3/edit', form => { email => 'test50@example.com', new_password => 'abc123', name => '7th Heaven', @@ -88,7 +106,7 @@ $t->post_ok('/admin/users/1/edit', form => { })->content_like(qr/The validation has failed/); #Failed validation on organisation user from no street name -$t->post_ok('/admin/users/1/edit', form => { +$t->post_ok('/admin/users/3/edit', form => { email => 'test50@example.com', new_password => 'abc123', name => '7th Heaven', diff --git a/templates/admin/users/read.html.ep b/templates/admin/users/read.html.ep index 9cf6740..c0463c3 100644 --- a/templates/admin/users/read.html.ep +++ b/templates/admin/users/read.html.ep @@ -49,7 +49,7 @@
- +
% } elsif ( my $org_rs = $user->organisation ) {

From b5feae5f068d6b4057f16b393d83c32c8d5cddd4 Mon Sep 17 00:00:00 2001 From: Finn Date: Thu, 24 Aug 2017 13:01:11 +0100 Subject: [PATCH 6/6] Disabled some entries and attempted autocomplete removal --- templates/admin/users/read.html.ep | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/templates/admin/users/read.html.ep b/templates/admin/users/read.html.ep index c0463c3..202efed 100644 --- a/templates/admin/users/read.html.ep +++ b/templates/admin/users/read.html.ep @@ -11,25 +11,26 @@ Success! <%= $success %> % } -
+

User Details

- +
- +
- +
- + +

Leave blank unless you want to change their password

% if ( my $customer_rs = $user->customer ) {