Skip to content

Commit

Permalink
Do not show normal users the admin tools
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed May 30, 2024
1 parent fb75250 commit 09769a3
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
4 changes: 1 addition & 3 deletions assets/vue/EditSnippet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@
<div class="col mb-3">
<button name="create-pattern" type="submit" value="1" class="btn btn-primary mb-2">Create Pattern</button
>&nbsp;
<button name="mark-non-license" type="submit" value="1" class="btn btn-danger mb-2">
Mark as Non-License
</button>
<button name="propose-pattern" type="submit" value="1" class="btn btn-secondary mb-2">Propose Pattern</button>
</div>
</div>
<div v-if="closest !== null" class="row closest-container">
Expand Down
3 changes: 2 additions & 1 deletion lib/Cavil/Controller/Report.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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')
);
}
);
Expand Down
4 changes: 2 additions & 2 deletions lib/Cavil/Plugin/Helpers.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion templates/reviewer/file_source.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
% else {
<tr class="<%= $class %>">
% }
% 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
Expand Down
3 changes: 2 additions & 1 deletion templates/reviewer/report.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@

<h2>Files</h2>

% my $is_admin = current_user_has_role 'admin';
% for my $file (@{$report->{files}}) {
% my $id = $file->{id};
% next unless defined $linked_files{$id};
Expand All @@ -136,7 +137,7 @@
</div>
% 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 {
<div id="file-details-<%= $id %>" class="source" data-file-id="<%= $id %>"></div>
Expand Down

0 comments on commit 09769a3

Please sign in to comment.