diff --git a/lib/Pear/LocalLoop/Controller/Admin.pm b/lib/Pear/LocalLoop/Controller/Admin.pm index 005707b..8030d59 100644 --- a/lib/Pear/LocalLoop/Controller/Admin.pm +++ b/lib/Pear/LocalLoop/Controller/Admin.pm @@ -5,10 +5,10 @@ sub under { my $c = shift; if ( $c->is_user_authenticated ) { - return 1 if defined $c->current_user->administrator; + return 1 if $c->current_user->is_admin; } $c->redirect_to('/'); - return undef; + return 0; } sub home { @@ -16,8 +16,8 @@ sub home { my $user_rs = $c->schema->resultset('User'); my $token_rs = $c->schema->resultset('AccountToken'); - my $pending_orgs_rs = $c->schema->resultset('PendingOrganisation'); - my $pending_transaction_rs = $c->schema->resultset('PendingTransaction'); + my $pending_orgs_rs = $c->schema->resultset('Organisation')->search({ pending => 1 }); + my $pending_transaction_rs = $pending_orgs_rs->entity->sales; $c->stash( user_count => $user_rs->count, tokens => { diff --git a/lib/Pear/LocalLoop/Schema/ResultSet/Entity.pm b/lib/Pear/LocalLoop/Schema/ResultSet/Entity.pm new file mode 100644 index 0000000..735b0db --- /dev/null +++ b/lib/Pear/LocalLoop/Schema/ResultSet/Entity.pm @@ -0,0 +1,10 @@ +package Pear::LocalLoop::Schema::ResultSet::Entity; + +use strict; +use warnings; + +use base 'DBIx::Class::ResultSet'; + +sub sales { shift->search_related('sales', @_) } + +1; diff --git a/lib/Pear/LocalLoop/Schema/ResultSet/Organisation.pm b/lib/Pear/LocalLoop/Schema/ResultSet/Organisation.pm new file mode 100644 index 0000000..10560b2 --- /dev/null +++ b/lib/Pear/LocalLoop/Schema/ResultSet/Organisation.pm @@ -0,0 +1,10 @@ +package Pear::LocalLoop::Schema::ResultSet::Organisation; + +use strict; +use warnings; + +use base 'DBIx::Class::ResultSet'; + +sub entity { shift->search_related('entity', @_) } + +1; diff --git a/t/admin/login.t b/t/admin/login.t index 1f7211a..abaea7e 100644 --- a/t/admin/login.t +++ b/t/admin/login.t @@ -1,27 +1,18 @@ use Mojo::Base -strict; +use FindBin qw/ $Bin /; + use Test::More; -use Mojo::JSON; use Test::Pear::LocalLoop; -my $framework = Test::Pear::LocalLoop->new; +my $framework = Test::Pear::LocalLoop->new( + etc_dir => "$Bin/../etc", +); +$framework->install_fixtures('users'); + my $t = $framework->framework; my $schema = $t->app->schema; -$schema->resultset('User')->create({ - email => 'admin@example.com', - password => 'abc123', - administrator => {}, -}); - -$schema->resultset('User')->create({ - email => 'user@example.com', - password => 'abc123', -}); - -is $schema->resultset('User')->count, 2, 'Users Created'; -is $schema->resultset('Administrator')->count, 1, 'Admin Created'; - my $location_is = sub { my ($t, $value, $desc) = @_; $desc ||= "Location: $value"; @@ -34,7 +25,7 @@ $t->get_ok('/admin') $t->ua->max_redirects(10); $t->post_ok('/admin', form => { - email => 'user@example.com', + email => 'test1@example.com', password => 'abc123', })->status_is(200);