Skip to content

Commit

Permalink
require authorization for uploading files
Browse files Browse the repository at this point in the history
  • Loading branch information
szabgab committed May 30, 2021
1 parent afd83e7 commit fc0dafd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/Course/Management.pm
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ sub startup ($self) {
$r->get('/')->to('main#welcome');
$r->post('/login')->to('main#login');
$r->get('/login/:code')->to('main#login_get');
$r->get('/logout')->to('main#logout');

# protected
$authorized->get('/')->to('course#list_courses');
$authorized->get('/:id')->to('course#list_exercises');
$r->post('/upload')->to('course#upload');
$r->get('/logout')->to('main#logout');
$authorized->post('/:id/upload')->to('course#upload');

$admin_authorized->get('/')->to('admin#list_courses');
$admin_authorized->get('/:id')->to('admin#list_solutions');
Expand Down
6 changes: 2 additions & 4 deletions t/upload.t
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ subtest upload_no_upload_dir => sub {
my $content = 'bar';
my $upload = {
$course_config->[0]{exercises}[0]{files}[0] => {content => $content, filename => 'baz.txt'},
id => $course_config->[0]{id},
};
$t->post_ok('/upload' => form => $upload)->status_is(500);
$t->post_ok("/course/$course_config->[0]{id}/upload" => form => $upload)->status_is(500);
#diag $t->tx->res->body;
$t->content_like(qr{Upload directory not configured});
};
Expand All @@ -50,9 +49,8 @@ subtest upload => sub {
my $content = 'bar';
my $upload = {
$course_config->[0]{exercises}[0]{files}[0] => {content => $content, filename => 'baz.txt'},
id => $course_config->[0]{id},
};
$t->post_ok('/upload' => form => $upload)->status_is(200);
$t->post_ok("/course/$course_config->[0]{id}/upload" => form => $upload)->status_is(200);
#diag $t->tx->res->body;
$t->content_like(qr{Uploaded});
(my $exercise_name = $course_config->[0]{exercises}[0]{url}) =~ s{[:/]+}{_}g;
Expand Down
3 changes: 1 addition & 2 deletions templates/course/list_exercises.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@


<p>
<form method="POST" action="/upload" enctype="multipart/form-data">
<input type="hidden" name="id" value="<%= $course->{id} %>">
<form method="POST" action="/course/<%= $course->{id} %>/upload" enctype="multipart/form-data">
<input type="submit" value="Upload">

<ul id="exercises">
Expand Down

0 comments on commit fc0dafd

Please sign in to comment.