diff --git a/src/lib/Hydra/Controller/Admin.pm b/src/lib/Hydra/Controller/Admin.pm index a6194293..dd659da3 100644 --- a/src/lib/Hydra/Controller/Admin.pm +++ b/src/lib/Hydra/Controller/Admin.pm @@ -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."); diff --git a/src/root/topbar.tt b/src/root/topbar.tt index 30609cac..9d71a08a 100644 --- a/src/root/topbar.tt +++ b/src/root/topbar.tt @@ -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