Implement role and controller filter for widgets.

agranig/1_0_subfix
Andreas Granig 12 years ago
parent 9067242a0f
commit 065d8aafd3

@ -21,6 +21,7 @@ use Catalyst qw/
ConfigLoader
Static::Simple
Authentication
Authorization::Roles
Session
Session::Store::FastMmap
Session::State::Cookie

@ -5,6 +5,7 @@ use namespace::autoclean;
BEGIN { extends 'Catalyst::Controller'; }
use NGCP::Panel::Widget;
use Data::Dumper;
=head1 NAME
@ -25,15 +26,18 @@ Dashboard index
=cut
sub index :Path :Args(0) {
my ( $self, $c ) = @_;
my ($self, $c) = @_;
print ">>>>>>>>>> user:\n";
print Dumper $c->user;
print ">>>>>>>>>> end user\n";
my $widget_templates = [];
my $finder = NGCP::Panel::Widget->new;
foreach($finder->list_plugins) {
my $widget = NGCP::Panel::Widget->new;
$widget->load_plugin($_);
$widget->handle($c);
push @{ $widget_templates }, $widget->template;
foreach($finder->instantiate_plugins($c)) {
$_->handle($c);
push @{ $widget_templates }, $_->template;
}
$c->stash(widgets => $widget_templates);

@ -2,14 +2,31 @@ package NGCP::Panel::Widget;
use Moose;
with 'MooseX::Object::Pluggable';
use Data::Dumper;
sub handle {
my ($self, $c) = @_;
return;
}
sub list_plugins {
my ($self) = @_;
return map { $_ = s/^.*:://r } $self->_plugin_locator->plugins;
sub filter {
my ($self, $c) = @_;
return;
}
sub instantiate_plugins {
my ($self, $c) = @_;
my @plugins = map { s/^.*:://; $_; } $self->_plugin_locator->plugins;
my @instances = ();
foreach(@plugins) {
my $inst = NGCP::Panel::Widget->new;
$inst->load_plugin($_);
if($inst->filter($c)) {
push @instances, $inst;
}
}
return @instances;
}
no Moose;

@ -8,11 +8,21 @@ has 'template' => (
);
around handle => sub {
my ($self, $c) = @_;
my ($foo, $self, $c) = @_;
print "++++ BillingOverview::handle\n";
return;
};
around filter => sub {
my ($foo, $self, $c) = @_;
return $self if(
$c->check_user_roles(qw/administrator/) &&
ref $c->controller eq 'NGCP::Panel::Controller::Dashboard'
);
return;
};
1;
# vim: set tabstop=4 expandtab:

@ -8,11 +8,21 @@ has 'template' => (
);
around handle => sub {
my ($self, $c) = @_;
my ($foo, $self, $c) = @_;
print "++++ PeeringOverview::handle\n";
return;
};
around filter => sub {
my ($foo, $self, $c) = @_;
return $self if(
$c->check_user_roles(qw/administrator/) &&
ref $c->controller eq 'NGCP::Panel::Controller::Dashboard'
);
return;
};
1;
# vim: set tabstop=4 expandtab:

@ -8,11 +8,21 @@ has 'template' => (
);
around handle => sub {
my ($self, $c) = @_;
my ($foo, $self, $c) = @_;
print "++++ ResellerOverview::handle\n";
return;
};
around filter => sub {
my ($foo, $self, $c) = @_;
return $self if(
$c->check_user_roles(qw/administrator/) &&
ref $c->controller eq 'NGCP::Panel::Controller::Dashboard'
);
return;
};
1;
# vim: set tabstop=4 expandtab:

@ -8,11 +8,21 @@ has 'template' => (
);
around handle => sub {
my ($self, $c) = @_;
my ($foo, $self, $c) = @_;
print "++++ SystemOverview::handle\n";
return;
};
around filter => sub {
my ($foo, $self, $c) = @_;
return $self if(
$c->check_user_roles(qw/administrator/) &&
ref $c->controller eq 'NGCP::Panel::Controller::Dashboard'
);
return;
};
1;
# vim: set tabstop=4 expandtab:

@ -57,7 +57,7 @@
<div id="header">
<div class="container">
<a href="./index.html" class="brand">Dashboard Admin</a>
<a href="[% c.uri_for('/dashboard') %]" class="brand">Dashboard</a>
<a href="javascript:;" class="btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<i class="icon-reorder"></i>
</a>

Loading…
Cancel
Save