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
|
@ -6,25 +6,27 @@ use base 'Catalyst::Controller';
|
|||
use Hydra::Helper::Nix;
|
||||
use Hydra::Helper::CatalystUtils;
|
||||
|
||||
sub admin : Path('/admin') Args(0) {
|
||||
|
||||
sub admin : Chained('/') PathPart('admin') CaptureArgs(0) {
|
||||
my ($self, $c) = @_;
|
||||
requireAdmin($c);
|
||||
}
|
||||
|
||||
sub index : Chained('admin') PathPart('') Args(0) {
|
||||
my ($self, $c) = @_;
|
||||
$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) = @_;
|
||||
requireAdmin($c);
|
||||
|
||||
my $r = `nix-store --clear-failed-paths '*'`;
|
||||
|
||||
$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) = @_;
|
||||
requireAdmin($c);
|
||||
|
||||
print "Clearing evaluation cache\n";
|
||||
$c->model('DB::JobsetInputHashes')->delete_all;
|
||||
|
@ -32,9 +34,8 @@ sub clearevalcache : Path('/admin/clear-eval-cache') Args(0) {
|
|||
$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) = @_;
|
||||
requireAdmin($c);
|
||||
|
||||
print "Clearing path cache\n";
|
||||
$c->model('DB::CachedPathInputs')->delete_all;
|
||||
|
@ -48,19 +49,17 @@ sub clearvcscache : Path('/admin/clear-vcs-cache') Args(0) {
|
|||
$c->res->redirect("/admin");
|
||||
}
|
||||
|
||||
sub managenews : Path('/admin/news') Args(0) {
|
||||
sub managenews : Chained('admin') Path('news') Args(0) {
|
||||
my ($self, $c) = @_;
|
||||
requireAdmin($c);
|
||||
|
||||
$c->stash->{newsItems} = [$c->model('DB::NewsItems')->search({}, {order_by => 'createtime DESC'})];
|
||||
|
||||
$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) = @_;
|
||||
|
||||
requireAdmin($c);
|
||||
requirePost($c);
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
sub news_delete : Path('/admin/news/delete') Args(1) {
|
||||
sub news_delete : Chained('admin') Path('news/delete') Args(1) {
|
||||
my ($self, $c, $id) = @_;
|
||||
|
||||
requireAdmin($c);
|
||||
|
||||
txn_do($c->model('DB')->schema, sub {
|
||||
my $newsItem = $c->model('DB::NewsItems')->find($id)
|
||||
or notFound($c, "Newsitem with id $id doesn't exist.");
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
[% IF c.user_exists %]
|
||||
[% IF c.check_user_roles('admin') %]
|
||||
[% INCLUDE makeLink
|
||||
uri = c.uri_for(c.controller('Admin').action_for('admin'))
|
||||
uri = c.uri_for(c.controller('Admin').action_for('index'))
|
||||
title = "Admin" %]
|
||||
[% END %]
|
||||
[% INCLUDE makeLink
|
||||
|
|
Loading…
Reference in a new issue