Change private problem handling
authorMarius Gavrilescu <marius@ieval.ro>
Tue, 3 Mar 2015 16:54:01 +0000 (18:54 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Tue, 3 Mar 2015 16:57:30 +0000 (18:57 +0200)
lib/Plack/App/Gruntmaster.pm

index a3fde9ed9a33489307400236242977be10f679e4..814c70ff273ac8108cf31fad3eb736323cd6d008 100644 (file)
@@ -115,7 +115,7 @@ sub dispatch_request{
 
                sub (?:problem=) {
                        return NOT_FOUND if !problem;
-                       forbid problem->is_private;
+                       forbid problem->private;
                        response_filter { return shift }
                },
 
@@ -177,16 +177,17 @@ sub dispatch_request{
                sub (/pb/:problem + ?contest~) {
                        my (undef, undef, $contest) = @_;
                        $_{contest} = $contest;
-                       return NOT_FOUND if !contest && !problem->is_in_archive || contest && !db->contest_problems->find($_{contest}, $_{problem});
-                       forbid problem->is_private;
-                       if (contest && contest->is_running) {
+                       return NOT_FOUND if contest && !db->contest_problems->find($_{contest}, $_{problem});
+                       forbid problem->private && !contest;
+                       if (contest) {
+                               return redirect "/pb/$_{problem}" unless contest->is_running;
                                forbid !remote_user;
                                $privacy = 'private';
                        }
                        response pb_entry => problem->name, {%{db->problem_entry($_{problem}, $_{contest}, remote_user && remote_user->id)}, maybe contest => $_{contest}};
                },
                sub (/sol/:problem) {
-                       forbid !problem->is_in_archive;
+                       forbid problem->private;
                        response sol => 'Solution of ' . problem->name, {solution => db->problem($_{problem})->solution};
                },
 
@@ -199,17 +200,17 @@ sub dispatch_request{
                sub (/action/submit + %:problem=&:contest~&:prog_format=&:source_code~ + *prog~) {
                        my (undef, undef, $prog) = @_;
                        forbid !remote_user;
+                       my $private = (problem->private && !contest) ? 1 : 0;
                        return reply 'This contest has finished' if contest && contest->is_finished;
-                       return reply 'This contest has not yet started' if !admin && contest && contest->is_pending;
-                       return reply 'This problem does not belong to this contest' if !contest && !problem->is_in_archive || contest && !db->contest_problems->find($_{contest}, $_{problem});
+                       return reply 'This contest has not yet started' if contest && contest->is_pending;
+                       return reply 'This problem is private' if !admin && $private;
+                       return reply 'This problem does not belong to this contest' if contest && !db->contest_problems->find($_{contest}, $_{problem});
                        return reply 'Maximum source size is 10KB' if ($prog ? $prog->size : length $_{source_code}) > 10 * 1024;
                        return reply 'You must wait 30 seconds between jobs' if !admin && time <= remote_user->lastjob + 30;
                        remote_user->update({lastjob => time});
 
                        my $source = $prog ? read_file $prog->path : $_{source_code};
                        unlink $prog->path if $prog;
-                       my $private = (problem->private && !$_{contest}) ? 1 : 0;
-                       $private = 1 if contest && contest->is_pending;
                        my $newjob = db->jobs->create({
                                maybe contest => $_{contest},
                                private => $private,
This page took 0.012307 seconds and 4 git commands to generate.