From 09769a3e078fd37b1ff30add3d09b0cb51bef955 Mon Sep 17 00:00:00 2001 From: Sebastian Riedel Date: Thu, 30 May 2024 16:16:17 +0200 Subject: [PATCH] Do not show normal users the admin tools --- assets/vue/EditSnippet.vue | 4 +--- lib/Cavil/Controller/Report.pm | 3 ++- lib/Cavil/Plugin/Helpers.pm | 4 ++-- templates/reviewer/file_source.html.ep | 2 +- templates/reviewer/report.html.ep | 3 ++- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/assets/vue/EditSnippet.vue b/assets/vue/EditSnippet.vue index 2d87306a3e..d8af39d952 100644 --- a/assets/vue/EditSnippet.vue +++ b/assets/vue/EditSnippet.vue @@ -125,9 +125,7 @@
  - +
diff --git a/lib/Cavil/Controller/Report.pm b/lib/Cavil/Controller/Report.pm index 50dbe57519..3bb61dfcf5 100644 --- a/lib/Cavil/Controller/Report.pm +++ b/lib/Cavil/Controller/Report.pm @@ -66,7 +66,8 @@ sub source ($self) { filename => $source->{filename}, lines => lines_context($source->{lines}), hidden => 0, - packname => $source->{name} + packname => $source->{name}, + is_admin => $self->current_user_has_role('admin') ); } ); diff --git a/lib/Cavil/Plugin/Helpers.pm b/lib/Cavil/Plugin/Helpers.pm index b0b1297eae..ea306c8d67 100644 --- a/lib/Cavil/Plugin/Helpers.pm +++ b/lib/Cavil/Plugin/Helpers.pm @@ -81,9 +81,9 @@ sub _checksum ($c, $specfile, $report) { sub _current_user ($c) { $c->session('user') } -sub _current_user_has_role ($c, $role) { +sub _current_user_has_role ($c, @roles) { return undef unless my $user = $c->helpers->current_user; - return $c->users->has_role($user, $role); + return $c->users->has_role($user, @roles); } sub _current_user_roles ($c) { diff --git a/templates/reviewer/file_source.html.ep b/templates/reviewer/file_source.html.ep index 0c7721e0c0..c19892bbff 100644 --- a/templates/reviewer/file_source.html.ep +++ b/templates/reviewer/file_source.html.ep @@ -17,7 +17,7 @@ % else { % } - % if ($line->[1]->{end}) { + % if ($is_admin && $line->[1]->{end}) { % my $end_id = "$file-$i"; % my $data = { start => $line->[0], end => $line->[1]->{end}, 'prev-match' => $line->[1]->{prevstart} // 0, 'next-match' => $line->[1]->{nextend} // 0 }; %= tag 'td', class => "actions dropdown show" => data => $data => begin diff --git a/templates/reviewer/report.html.ep b/templates/reviewer/report.html.ep index ed8981d061..fa78bc5cc7 100644 --- a/templates/reviewer/report.html.ep +++ b/templates/reviewer/report.html.ep @@ -115,6 +115,7 @@

Files

+ % my $is_admin = current_user_has_role 'admin'; % for my $file (@{$report->{files}}) { % my $id = $file->{id}; % next unless defined $linked_files{$id}; @@ -136,7 +137,7 @@
% if ($file->{expand}) { <%= include 'reviewer/file_source', file => $id, filename => $path, lines => $file->{lines}, - packname => $package->{name} %> + packname => $package->{name}, is_admin => $is_admin %> % } % else {