Skip to content

Commit

Permalink
Make licenses and patterns public
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 22, 2024
1 parent 9b52f9a commit e9ffbe5
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
6 changes: 3 additions & 3 deletions lib/Cavil.pm
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ sub startup ($self) {
$public->get('/pagination/reviews/recent')->to('Pagination#recent_reviews')->name('pagination_recent_reviews');
$public->get('/spdx/<id:num>')->to('Report#spdx')->name('spdx_report');

$admin->get('/licenses')->to('License#list')->name('licenses');
$admin->get('/pagination/licenses/known')->to('Pagination#known_licenses')->name('pagination_known_licenses');
$public->get('/licenses')->to('License#list')->name('licenses');
$public->get('/pagination/licenses/known')->to('Pagination#known_licenses')->name('pagination_known_licenses');
$admin->get('/licenses/new_pattern')->to('License#new_pattern')->name('new_pattern');
$admin->post('/licenses/new_pattern')->to('License#new_pattern');
$admin->post('/licenses/create_pattern')->to('License#create_pattern')->name('create_pattern');
Expand All @@ -219,7 +219,7 @@ sub startup ($self) {
$admin->post('/licenses/update_pattern/<id:num>')->to('License#update_pattern')->name('update_pattern');
$admin->post('/licenses/update_patterns')->to('License#update_patterns')->name('update_patterns');
$admin->delete('/licenses/remove_pattern/<id:num>')->to('License#remove_pattern')->name('remove_pattern');
$admin->get('/licenses/*name')->to('License#show')->name('license_show');
$public->get('/licenses/*name')->to('License#show')->name('license_show');

$public->get('/products')->to('Product#list')->name('products');
$public->get('/pagination/products/known')->to('Pagination#known_products')->name('pagination_known_products');
Expand Down
4 changes: 2 additions & 2 deletions t/index.t
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ $config->{acceptable_risk} = 5;
$t = Test::Mojo->new(Cavil => $config);

# License management requires a login
$t->get_ok('/licenses')->status_is(403)->content_like(qr/Permission/);
$t->get_ok('/licenses/edit_pattern/1')->status_is(403)->content_like(qr/Permission/);
$t->get_ok('/login')->status_is(302)->header_is(Location => '/');
$t->get_ok('/licenses')->status_is(200)->content_like(qr/Licenses/);
$t->get_ok('/licenses/edit_pattern/1')->status_is(200)->content_like(qr/License/);

subtest 'Pattern change' => sub {
$t->get_ok('/licenses/edit_pattern/1')->status_is(200)->element_exists('input[name=license][value=Apache-2.0]')
Expand Down
9 changes: 3 additions & 6 deletions t/login.t
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ subtest 'Not authenticated' => sub {
$t->post_ok('/reviews/add_ignore')->status_is(403)->content_like(qr/Permission/);
$t->post_ok('/reviews/reindex/1')->status_is(403)->content_like(qr/Permission/);
$t->get_ok('/reviews/file_view/1/LICENSE')->status_is(403)->content_like(qr/Permission/);
$t->get_ok('/licenses')->status_is(403)->content_like(qr/Permission/);
$t->get_ok('/licenses/new_pattern')->status_is(403)->content_like(qr/Permission/);
$t->post_ok('/licenses/create_pattern')->status_is(403)->content_like(qr/Permission/);
$t->get_ok('/licenses/Apache-2.0')->status_is(403)->content_like(qr/Permission/);
$t->get_ok('/licenses/edit_pattern/1')->status_is(403)->content_like(qr/Permission/);
$t->post_ok('/licenses/update_pattern/1')->status_is(403)->content_like(qr/Permission/);
$t->post_ok('/licenses/update_patterns')->status_is(403)->content_like(qr/Permission/);
Expand All @@ -57,12 +55,11 @@ subtest 'OpenID' => sub {
subtest 'Dummy' => sub {
delete $config->{openid};
$t = Test::Mojo->new(Cavil => $config);
$t->get_ok('/licenses')->status_is(403)->content_like(qr/Permission/);
$t->get_ok('/upload')->status_is(403)->content_like(qr/Permission/);
$t->get_ok('/login')->status_is(302)->header_is(Location => '/');
$t->get_ok('/licenses')->status_is(200)->content_like(qr/Licenses/);
$t->get_ok('/licenses/Apache-2.0')->status_is(200)->content_like(qr/Apache-2.0/);
$t->get_ok('/upload')->status_is(200)->content_like(qr/Upload/);
$t->get_ok('/logout')->status_is(302)->header_is(Location => '/');
$t->get_ok('/licenses')->status_is(403)->content_like(qr/Permission/);
$t->get_ok('/upload')->status_is(403)->content_like(qr/Permission/);
};

done_testing;
6 changes: 3 additions & 3 deletions templates/layouts/default.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
<li class="nav-item">
%= link_to 'Products' => '/products', class => 'nav-link'
</li>
<li class="nav-item">
%= link_to 'Licenses' => '/licenses', class => 'nav-link'
</li>
% if (current_user_has_role 'admin') {
<li class="nav-item">
%= link_to 'Licenses' => '/licenses', class => 'nav-link'
</li>
<li class="nav-item">
%= link_to 'Upload' => '/upload', class => 'nav-link'
</li>
Expand Down
6 changes: 5 additions & 1 deletion templates/license/show.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@
</div>

<h3>Patterns for this license
% if (current_user_has_role 'admin') {
%= link_to '(Add new)' => url_for('new_pattern')->query('license-name' => $license), class => 'btn', role => 'btn'
% }
</h3>

<ul>

% for my $match (@$patterns) {
<li>
<div>Created <time class="timeago" datetime="<%= $match->{created} %>"><%= $match->{created} %></time>
<a href="<%= url_for('edit_pattern', id => $match->{id}) %>" title="Edit" style="float: right"><i class="fas fa-edit"></i></a>
% if (current_user_has_role 'admin') {
<a href="<%= url_for('edit_pattern', id => $match->{id}) %>" title="Edit" style="float: right"><i class="fas fa-edit"></i></a>
% }
</div>
<pre><%= $match->{pattern} %></pre>
% if ($match->{packname}) {
Expand Down

0 comments on commit e9ffbe5

Please sign in to comment.