From 5cce06c984f11a0f6787660eb82756ed5161c715 Mon Sep 17 00:00:00 2001 From: swag Date: Sun, 18 Dec 2022 14:00:54 -0500 Subject: [PATCH] Use perlcritic theme; add is_admin() helper; clean up some things --- .perlcriticrc | 2 +- cpanfile | 1 + lib/PostText.pm | 19 ++++++++++++++++++- migrations/11/up.sql | 6 ++++-- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.perlcriticrc b/.perlcriticrc index 63b7d3b..13dfb1a 100644 --- a/.perlcriticrc +++ b/.perlcriticrc @@ -1 +1 @@ -exclude = Subroutines::ProhibitSubroutinePrototypes +theme = community diff --git a/cpanfile b/cpanfile index b6c6f53..d8d50c5 100644 --- a/cpanfile +++ b/cpanfile @@ -4,3 +4,4 @@ requires 'Mojolicious::Plugin::TagHelpers::Pagination'; requires 'Mojolicious::Plugin::AssetPack'; requires 'Crypt::Passphrase::Argon2'; requires 'Crypt::Passphrase::Bcrypt'; # Needed for old passphrases +requires 'Perl::Critic::Community'; diff --git a/lib/PostText.pm b/lib/PostText.pm index 9bb8189..cce99f0 100644 --- a/lib/PostText.pm +++ b/lib/PostText.pm @@ -58,6 +58,14 @@ sub startup($self) { return undef; }); + $self->helper(is_admin => sub ($c) { + if (my $admin_id = $c->session->{'admin_id'}) { + return 1 if $admin_id =~ /\d+/ + } + + return undef; + }); + # Finish configuring some things $self->secrets($self->config->{'secrets'}) || die $@; @@ -144,7 +152,7 @@ sub startup($self) { my $moderator = $r->under('/moderator', sub ($c) { return 1 if $c->is_mod; - # Return false otherwise a body is rendered with the redirect... + # Return undef otherwise a body is rendered with the redirect... return $c->redirect_to('mod_login'), undef; }); @@ -183,6 +191,15 @@ sub startup($self) { $mod_remark->get('/unhide/:remark_id', [remark_id => qr/\d+/]) ->to('moderator#unhide_remark') ->name('unhide_remark'); + + my $admin = $moderator->under('/admin', sub ($c) { + return 1 if $c->is_admin; + + # Return undef otherwise a body is rendered with the redirect... + return $c->recirect_to('mod_login'), undef; + }); + + # Actions to create mods... } 1; diff --git a/migrations/11/up.sql b/migrations/11/up.sql index 3152134..58d0eae 100644 --- a/migrations/11/up.sql +++ b/migrations/11/up.sql @@ -1,2 +1,4 @@ -ALTER TABLE moderators - ADD admin_status BOOLEAN NOT NULL DEFAULT FALSE; + ALTER TABLE moderators + ADD admin_status BOOLEAN + NOT NULL +DEFAULT FALSE;