forked from lix-project/hydra
refactored admin controller, using chains, to avoid using requireadmin on each endpoint
This commit is contained in:
parent
7a79d17a36
commit
368c4cd813
2 changed files with 12 additions and 15 deletions
|
@ -6,25 +6,27 @@ use base 'Catalyst::Controller';
|
||||||
use Hydra::Helper::Nix;
|
use Hydra::Helper::Nix;
|
||||||
use Hydra::Helper::CatalystUtils;
|
use Hydra::Helper::CatalystUtils;
|
||||||
|
|
||||||
sub admin : Path('/admin') Args(0) {
|
|
||||||
|
sub admin : Chained('/') PathPart('admin') CaptureArgs(0) {
|
||||||
my ($self, $c) = @_;
|
my ($self, $c) = @_;
|
||||||
requireAdmin($c);
|
requireAdmin($c);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub index : Chained('admin') PathPart('') Args(0) {
|
||||||
|
my ($self, $c) = @_;
|
||||||
$c->stash->{template} = 'admin.tt';
|
$c->stash->{template} = 'admin.tt';
|
||||||
}
|
}
|
||||||
|
|
||||||
sub clearfailedcache : Path('/admin/clear-failed-cache') Args(0) {
|
sub clearfailedcache : Chained('admin') Path('clear-failed-cache') Args(0) {
|
||||||
my ($self, $c) = @_;
|
my ($self, $c) = @_;
|
||||||
requireAdmin($c);
|
|
||||||
|
|
||||||
my $r = `nix-store --clear-failed-paths '*'`;
|
my $r = `nix-store --clear-failed-paths '*'`;
|
||||||
|
|
||||||
$c->res->redirect("/admin");
|
$c->res->redirect("/admin");
|
||||||
}
|
}
|
||||||
|
|
||||||
sub clearevalcache : Path('/admin/clear-eval-cache') Args(0) {
|
sub clearevalcache : Chained('admin') Path('clear-eval-cache') Args(0) {
|
||||||
my ($self, $c) = @_;
|
my ($self, $c) = @_;
|
||||||
requireAdmin($c);
|
|
||||||
|
|
||||||
print "Clearing evaluation cache\n";
|
print "Clearing evaluation cache\n";
|
||||||
$c->model('DB::JobsetInputHashes')->delete_all;
|
$c->model('DB::JobsetInputHashes')->delete_all;
|
||||||
|
@ -32,9 +34,8 @@ sub clearevalcache : Path('/admin/clear-eval-cache') Args(0) {
|
||||||
$c->res->redirect("/admin");
|
$c->res->redirect("/admin");
|
||||||
}
|
}
|
||||||
|
|
||||||
sub clearvcscache : Path('/admin/clear-vcs-cache') Args(0) {
|
sub clearvcscache : Chained('admin') Path('clear-vcs-cache') Args(0) {
|
||||||
my ($self, $c) = @_;
|
my ($self, $c) = @_;
|
||||||
requireAdmin($c);
|
|
||||||
|
|
||||||
print "Clearing path cache\n";
|
print "Clearing path cache\n";
|
||||||
$c->model('DB::CachedPathInputs')->delete_all;
|
$c->model('DB::CachedPathInputs')->delete_all;
|
||||||
|
@ -48,19 +49,17 @@ sub clearvcscache : Path('/admin/clear-vcs-cache') Args(0) {
|
||||||
$c->res->redirect("/admin");
|
$c->res->redirect("/admin");
|
||||||
}
|
}
|
||||||
|
|
||||||
sub managenews : Path('/admin/news') Args(0) {
|
sub managenews : Chained('admin') Path('news') Args(0) {
|
||||||
my ($self, $c) = @_;
|
my ($self, $c) = @_;
|
||||||
requireAdmin($c);
|
|
||||||
|
|
||||||
$c->stash->{newsItems} = [$c->model('DB::NewsItems')->search({}, {order_by => 'createtime DESC'})];
|
$c->stash->{newsItems} = [$c->model('DB::NewsItems')->search({}, {order_by => 'createtime DESC'})];
|
||||||
|
|
||||||
$c->stash->{template} = 'news.tt';
|
$c->stash->{template} = 'news.tt';
|
||||||
}
|
}
|
||||||
|
|
||||||
sub news_submit : Path('/admin/news/submit') Args(0) {
|
sub news_submit : Chained('admin') Path('news/submit') Args(0) {
|
||||||
my ($self, $c) = @_;
|
my ($self, $c) = @_;
|
||||||
|
|
||||||
requireAdmin($c);
|
|
||||||
requirePost($c);
|
requirePost($c);
|
||||||
|
|
||||||
my $contents = trim $c->request->params->{"contents"};
|
my $contents = trim $c->request->params->{"contents"};
|
||||||
|
@ -75,11 +74,9 @@ sub news_submit : Path('/admin/news/submit') Args(0) {
|
||||||
$c->res->redirect("/admin/news");
|
$c->res->redirect("/admin/news");
|
||||||
}
|
}
|
||||||
|
|
||||||
sub news_delete : Path('/admin/news/delete') Args(1) {
|
sub news_delete : Chained('admin') Path('news/delete') Args(1) {
|
||||||
my ($self, $c, $id) = @_;
|
my ($self, $c, $id) = @_;
|
||||||
|
|
||||||
requireAdmin($c);
|
|
||||||
|
|
||||||
txn_do($c->model('DB')->schema, sub {
|
txn_do($c->model('DB')->schema, sub {
|
||||||
my $newsItem = $c->model('DB::NewsItems')->find($id)
|
my $newsItem = $c->model('DB::NewsItems')->find($id)
|
||||||
or notFound($c, "Newsitem with id $id doesn't exist.");
|
or notFound($c, "Newsitem with id $id doesn't exist.");
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
[% IF c.user_exists %]
|
[% IF c.user_exists %]
|
||||||
[% IF c.check_user_roles('admin') %]
|
[% IF c.check_user_roles('admin') %]
|
||||||
[% INCLUDE makeLink
|
[% INCLUDE makeLink
|
||||||
uri = c.uri_for(c.controller('Admin').action_for('admin'))
|
uri = c.uri_for(c.controller('Admin').action_for('index'))
|
||||||
title = "Admin" %]
|
title = "Admin" %]
|
||||||
[% END %]
|
[% END %]
|
||||||
[% INCLUDE makeLink
|
[% INCLUDE makeLink
|
||||||
|
|
Loading…
Reference in a new issue