]> iEval git - plack-app-gruntmaster.git/blobdiff - lib/Plack/App/Gruntmaster.pm
Remove unnecessary forbids
[plack-app-gruntmaster.git] / lib / Plack / App / Gruntmaster.pm
index 87e9e5a18586bc654a8a36852af55b7c39df1255..bd8a90469fc79155ff223a18b1b7b8c7e7da2b20 100644 (file)
@@ -4,10 +4,8 @@ use 5.014000;
 use strict;
 our $VERSION = '5999.000_001';
 
-use CSS::Minifier::XS;
 use Encode qw/encode decode/;
 use File::Slurp qw/read_file/;
-use JavaScript::Minifier::XS;
 use JSON::MaybeXS qw/encode_json/;
 use PerlX::Maybe;
 use Scope::Upper qw/unwind SUB UP/;
@@ -55,8 +53,6 @@ use constant FORMAT_EXTENSION => {
 
 use constant NOT_FOUND => [404, ['X-Forever' => 1, 'Content-Type' => 'text/plain'], ['Not found']];
 
-sub development() { ($ENV{PLACK_ENV} // 'development') eq 'development' }
-
 my ($env, $privacy);
 
 sub db { $env->{'gruntmaster.dbic'} }
@@ -98,22 +94,6 @@ sub dispatch_request{
        $privacy = 'public';
 
        sub (GET) {
-               sub (/css/:theme) {
-                       my $theme = $_{theme};
-                       return NOT_FOUND unless -e "css/themes/$theme.css";
-                       my $css = read_file "css/themes/$theme.css";
-                       $css .= read_file $_ for <css/*.css>;
-                       my @headers = ('X-Forever' => 1, 'Cache-Control' => 'public, max-age=604800', 'Content-Type' => 'text/css; charset=utf-8');
-                       [200, \@headers, [development ? $css : CSS::Minifier::XS::minify $css]]
-               },
-
-               sub (/js.js) {
-                       my $js;
-                       $js .= read_file $_ for <js/*.js>;
-                       my @headers = ('X-Forever' => 1, 'Cache-Control' => 'public, max-age=604800', 'Content-Type' => 'application/javascript; charset=utf-8');
-                       [200, \@headers, [development ? $js : JavaScript::Minifier::XS::minify $js]]
-               },
-
                sub (/robots.txt) { NOT_FOUND },
 
                sub (/src/:job) {
@@ -127,18 +107,6 @@ sub dispatch_request{
                        [200, \@headers, [job->source]]
                },
 
-               sub (?:contest=) {
-                       return NOT_FOUND if !contest;
-                       forbid contest->is_pending;
-                       response_filter { return shift }
-               },
-
-               sub (?:problem=) {
-                       return NOT_FOUND if !problem;
-                       forbid problem->is_private;
-                       response_filter { return shift }
-               },
-
                sub (?:format~) {
                        my $format = lc ($_{format} // '');
                        response_filter {
@@ -185,7 +153,7 @@ sub dispatch_request{
                },
                sub (/pb/  + ?:owner~&:contest~&:private~)                  {
                        forbid $_{private};
-                       response pb => 'Problems', {%{db->problem_list(%_)}, maybe contest => $_{contest}}
+                       response pb => 'Problems', db->problem_list(%_)
                },
 
                sub (/us/:user)    { response us_entry => user->name, db->user_entry($_{user}) },
@@ -197,16 +165,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};
                },
 
@@ -219,17 +188,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.025721 seconds and 4 git commands to generate.