Changeset 1036 for trunk/common


Ignore:
Timestamp:
03/14/09 22:31:53 (3 years ago)
Author:
bogdan2412
Message:

Smarter submit page

Solves ticket #366.

Reviewed: http://reviewboard.infoarena.ro/r/71/

Location:
trunk/common
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/common/db/task.php

    r1010 r1036  
    160160} 
    161161 
     162// Returns list of running round ids that include this task to which 
     163// $user_id can submit 
     164function task_get_submit_rounds($task_id, $user_id) { 
     165    $rounds = task_get_parent_rounds($task_id); 
     166    foreach($rounds as $id => $round) { 
     167        $round = round_get($rounds[$id]); 
     168        if (!security_query($user_id, "round-submit", $round)) { 
     169            unset($rounds[$id]); 
     170        } 
     171    } 
     172    return array_values($rounds); 
     173} 
     174 
    162175?> 
  • trunk/common/job.php

    r997 r1036  
    2929    // Validate round id. 
    3030    $round = null; 
    31     if (array_key_exists('round_id', $args)) { 
    32         if (!is_round_id($args['round_id'])) { 
    33             $errors['round_id'] = "Id de runda invalid"; 
    34         } else if (is_null($round = round_get($args['round_id']))) { 
    35             $errors['round_id'] = "Runda '{$args['round_id']}' nu exista."; 
    36         } 
     31    if (!array_key_exists('round_id', $args)) { 
     32        $errors['round_id'] = "Nu ai specificat un concurs."; 
     33    } else if (!is_round_id($args['round_id'])) { 
     34        $errors['round_id'] = "Nu ai specificat un concurs corect."; 
     35    } else if (is_null($round = round_get($args['round_id']))) { 
     36        $errors['round_id'] = "Runda '{$args['round_id']}' nu exista."; 
     37    } 
     38    // Check if task is new and hasn't been added to any rounds 
     39    if (getattr($args, "round_id") == "" && 
     40        security_query($user, 'task-submit', $task)) { 
     41        unset($errors["round_id"]); 
    3742    } 
    3843 
     
    6570        $errors[] = "Nu ai voie sa trimiti la acest task."; 
    6671    } 
    67     if ($round && !security_query($round, 'task-submit', $round)) { 
     72    if ($round && !security_query($user, 'round-submit', $round)) { 
    6873        $errors[] = "Nu poti sa trimiti la aceasta runda."; 
    6974    } 
    7075 
    71     // FIXME: check round-submit or something? 
    72  
    7376    // Only now create the job. 
    7477    if (count($errors) === 0) { 
    75         // round_id can be missing. 
    76         // If it's missing then the job is multiplied and sent to all parent rounds. 
    77         // This is compatible with 2.1.3 
    78         if (array_key_exists('round_id', $args)) { 
    79             job_create($args['task_id'], $args['round_id'], $user['id'], 
    80                     $args['compiler_id'], $args['solution'], 
    81                     getattr($args, 'remote_ip_info')); 
    82         } else { 
    83             $parent_rounds = task_get_parent_rounds($args['task_id']); 
    84             if (count($parent_rounds) === 0) { 
    85                 // some jobs just don't have a round 
    86                 job_create($args['task_id'], '', $user['id'], 
    87                         $args['compiler_id'], $args['solution'], 
    88                         getattr($args, 'remote_ip_info')); 
    89             } 
    90             else { 
    91                 foreach ($parent_rounds as $round_id) { 
    92                     if (security_query($user, 'round-submit', round_get($round_id))) { 
    93                         job_create($args['task_id'], $round_id, $user['id'], 
    94                                 $args['compiler_id'], $args['solution'], 
    95                                 getattr($args, 'remote_ip_info')); 
    96                     } 
    97                 } 
    98             } 
    99         } 
     78        job_create($args['task_id'], $args['round_id'], $user['id'], 
     79                $args['compiler_id'], $args['solution'], 
     80                getattr($args, 'remote_ip_info')); 
    10081    } 
    10182 
  • trunk/common/security.php

    r1030 r1036  
    509509 
    510510        case 'round-submit': 
    511             // FIXME: This sucks. 
    512             // FIXME: job_get_submit_targets 
    513             $rparams = round_get_parameters($round['id']); 
    514             $time = time(); 
    515             $rstart = db_date_parse($round['start_time']); 
    516             $rduration = getattr($rparams, 'duration', 10000000) * 60 * 60; 
    517             if ($time >= $rstart && $time <= $rstart + $rduration) { 
    518                 return true; 
    519             } else { 
    520                 return false; 
    521             } 
     511            return $round["state"] == "running"; 
    522512 
    523513        case 'sensitive-info': 
Note: See TracChangeset for help on using the changeset viewer.