Changeset 1091 for trunk


Ignore:
Timestamp:
12/23/09 00:26:25 (2 years ago)
Author:
bogdan2412
Message:

Many many small fixes.

  • Changed task-tag action from simple-critical to simple-edit.
  • Fixed downloading attachments containing grader from normal (non-task) pages.
  • Moved a call to remote_ip_info() from common/ to www/ where it's supposed to be in MVC.
  • Fixed round and task tests.
  • Fixed test cleanup to delete only the created users and to delete them from the forum also.
  • Check that the username doesn't exist in the forum when someone tries to register (there are users on the forum that are not on infoarena, because of the import from info.devnet.ro i guess). Having two smf users with the same name crashes things.
  • Allow rounds to have no tasks.

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

Location:
trunk
Files:
8 edited

Legend:

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

    r1070 r1091  
    131131// $user must be a valid user struct, user_id ignored 
    132132// Returns created $user or throws up on error. 
    133 function user_create($user) 
     133function user_create($user, $remote_ip_info=null) 
    134134{ 
    135135    log_assert_valid(user_validate($user)); 
     
    150150    $replace = array("user_id" => $user['username']); 
    151151    textblock_copy_replace("template/newuser", IA_USER_TEXTBLOCK_PREFIX.$user['username'], 
    152                            $replace, "public", $new_user['id'], remote_ip_info()); 
     152                           $replace, "public", $new_user['id'], $remote_ip_info); 
    153153 
    154154    // Create SMF user 
  • trunk/common/security.php

    r1087 r1091  
    129129        case 'task-create': 
    130130        case 'task-delete': 
     131        case 'task-tag': 
    131132        case 'round-delete': 
    132133        case 'textblock-delete': 
     
    143144        case 'textblock-change-security': 
    144145        case 'task-edit-owner': 
    145         case 'task-tag': 
    146146        case 'round-tag': 
    147147        case 'textblock-tag': 
     
    280280// FIXME: attach-grader? 
    281281function security_attach($user, $action, $attach) { 
    282  
    283282    $att_name = $attach['name']; 
    284283    $att_page = normalize_page_name($attach['page']); 
     
    296295    } 
    297296 
    298     // HACK: magic prefix. 
    299     if (preg_match('/^grader\_/', $att_name)) { 
     297    // Speed hack: avatars are always visible. This is good. 
     298    if ($action == 'attach-download' && $att_name == 'avatar' && 
     299            starts_with($att_page, IA_USER_TEXTBLOCK_PREFIX)) { 
     300        return true; 
     301    } 
     302 
     303    // Forward to textblock. 
     304    $tb = textblock_get_revision($attach['page']); 
     305    if (!$tb) { 
     306        log_print_r($attach); 
     307    } 
     308    log_assert($tb, "Orphan attachment"); 
     309 
     310    // Convert action into a grader action if the textblock is a task 
     311    // textblock and the attachment has the grader_ prefix. 
     312    if (preg_match("/^ \s* task: \s* (".IA_RE_TASK_ID.") \s* $/xi", $tb["security"]) && 
     313        preg_match('/^grader\_/', $att_name)) { 
    300314        $newaction = preg_replace('/^attach/', 'grader', $action); 
    301315        if (IA_LOG_SECURITY) { 
     
    304318        $action = $newaction; 
    305319    } 
    306  
    307     // Speed hack: avatars are always visible. This is good. 
    308     if ($action == 'attach-download' && $att_name = 'avatar' && 
    309             strstr($att_page, IA_USER_TEXTBLOCK_PREFIX) === $att_page) { 
    310         return true; 
    311     } 
    312  
    313     // Forward to textblock. 
    314     $tb = textblock_get_revision($attach['page']); 
    315     if (!$tb) { 
    316         log_print_r($attach); 
    317     } 
    318     log_assert($tb, "Orphan attachment"); 
    319320 
    320321    return security_textblock($user, $action, $tb); 
  • trunk/tests/round.php

    r1026 r1091  
    7474            'type' => 'classic', 
    7575            'rating_update' => true, 
    76 ))); 
    77 log_assert_equal($res['url'], url_absolute(url_round_edit('test_round'))); 
    78 log_assert(strstr($res['content'], 'Concurs clasic')); 
     76            'start_time' => db_date_format(time() + 3600), 
     77))); 
     78log_assert(!strstr($res['content'], '<span class="fieldError"')); 
     79log_assert(strstr($res['content'], '<option value="classic" selected="selected">Concurs clasic')); 
     80log_assert_equal($res['url'], url_absolute(url_round_edit('test_round'))); 
    7981 
    8082log_print("Admin adds tasks adunare and cmmdc to round."); 
     
    197199log_assert_equal($res['url'], url_absolute(url_textblock('runda/tEst_Round'))); 
    198200log_assert(strstr($res['content'], 'xzx-round-title-xzx')); 
    199 log_assert(!strstr($res['content'], 'Nu esti inscris la'),  
     201log_assert(!strstr($res['content'], 'Nu esti inscris la'), 
    200202    "Round still waiting, is the evaluator ON?"); 
    201203log_assert(strstr($res['content'], 'Nu se mai pot face inscrieri')); 
  • trunk/tests/task.php

    r852 r1091  
    3939        'post' => array( 
    4040                'title' => 'xzx-task1-title-xzx', 
    41                 'author' => 'xzx-task1-author-xzx', 
     41                'tag_author' => 'xzx-task1-author-xzx', 
    4242                'source' => 'xzx-task1-source-xzx', 
    4343))); 
     
    223223log_assert(strstr($res['content'], 'xzx-task1-author-xzx')); 
    224224log_assert(strstr($res['content'], 'xzx-task1-source-xzx')); 
    225 log_assert(strstr($res['content'], 'name="author"')); 
     225log_assert(strstr($res['content'], 'name="tag_author"')); 
    226226log_assert(!strstr($res['content'], 'name="hidden"')); 
    227227 
  • trunk/tests/utilities.php

    r1051 r1091  
    6666    $res['content'] = $content; 
    6767    curl_close($ch); 
    68     
     68 
    6969    if (getattr($args, 'validate_html', false)) { 
    7070        validate_html($content); 
     
    132132function test_cleanup() 
    133133{ 
    134     db_query("DELETE FROM ia_user WHERE `username` LIKE 'test_%'"); 
    135     db_query("DELETE FROM ia_task WHERE `id` LIKE 'test_%'"); 
    136     db_query("DELETE FROM ia_round WHERE `id` LIKE 'test_%'"); 
     134    $test_accounts = "('test_dudE1', 'teSt_dude2', 'teSt_helper1', 'test_hElper2', 'tEst_adMin')"; 
     135    db_query("DELETE FROM ia_user WHERE `username` IN $test_accounts"); 
     136    db_query("DELETE FROM ia_smf_members WHERE `memberName` IN $test_accounts"); 
     137    db_query("DELETE FROM ia_task WHERE `id` LIKE 'test\_%'"); 
     138    db_query("DELETE FROM ia_round WHERE `id` LIKE 'test\_%'"); 
    137139    // Remove various stuff from the wiki. 
    138140    $prefixes = array('sandbox', 'utilizator', 'runda', 'problema'); 
    139141    foreach ($prefixes as $prefix) { 
    140142        db_query("DELETE FROM `ia_textblock` ". 
    141                  "WHERE `name` LIKE '$prefix/test_%'"); 
     143                 "WHERE `name` LIKE '$prefix/test\_%'"); 
    142144        db_query("DELETE FROM `ia_textblock_revision` ". 
    143                  "WHERE `name` LIKE '$prefix/test_%'"); 
     145                 "WHERE `name` LIKE '$prefix/test\_%'"); 
    144146        db_query("DELETE FROM `ia_file` ". 
    145                  "WHERE `page` LIKE '$prefix/test_%'"); 
     147                 "WHERE `page` LIKE '$prefix/test\_%'"); 
    146148    } 
    147149} 
  • trunk/www/controllers/account_validator.php

    r997 r1091  
    4646                                  .'invalide.'; 
    4747        } 
    48         elseif (user_get_by_username($data['username'])) { 
     48        elseif (user_get_by_username($data['username']) || 
     49                smf_get_member_by_name($data['username'])) { 
    4950            $errors['username'] = 'Nume utilizator rezervat de altcineva. Va ' 
    5051                                  .'rugam alegeti altul.'; 
  • trunk/www/controllers/register.php

    r986 r1091  
    4747 
    4848            // There are no acceptable errors in user_create. 
    49             user_create($user); 
     49            user_create($user, remote_ip_info()); 
    5050            flash("Felicitari! Contul a fost creat. Acum te poti " 
    5151                  ."autentifica."); 
     
    5959        $data['tnc'] = 1; 
    6060    } 
    61      
     61 
    6262    if(!IA_DEVELOPMENT_MODE) { 
    6363        $view['captcha'] = recaptcha_get_html(IA_CAPTCHA_PUBLIC_KEY); 
  • trunk/www/controllers/round.php

    r1090 r1091  
    134134    } 
    135135 
    136     if (request_is_post() && count($values['tasks']) == 0) { 
    137         $errors['tasks'] = "Trebuie sa alegi cel putin o problema"; 
    138     } 
    139  
    140136    // Additional validation for user defined tasks 
    141137    if (!array_key_exists('tasks', $errors) 
Note: See TracChangeset for help on using the changeset viewer.