public static function CanEditClarification($user_id, Clarifications $clarification) { if (is_null($clarification) || !is_a($clarification, 'Clarifications')) { return false; } try { $contest = ContestsDAO::getByPK($clarification->getContestId()); $problem = ProblemsDAO::getByPK($clarification->getProblemId()); } catch (Exception $e) { throw new InvalidDatabaseOperationException($e); } if (is_null($contest) || is_null($problem)) { return false; } return $problem->getAuthorId() === $user_id || Authorization::IsContestAdmin($user_id, $contest); }
/** * Gets the details of a run. Includes admin details if admin. * * @param Request $r * @throws InvalidDatabaseOperationException */ public static function apiDetails(Request $r) { // Get the user who is calling this API self::authenticateRequest($r); self::validateDetailsRequest($r); try { $r['problem'] = ProblemsDAO::getByPK($r['run']->problem_id); } catch (Exception $e) { throw new InvalidDatabaseOperationException($e); } if (is_null($r['problem'])) { throw new NotFoundException('problemNotFound'); } if (!Authorization::CanViewRun($r['current_user_id'], $r['run'])) { throw new ForbiddenAccessException('userNotAllowed'); } $response = array(); // Get the error $grade_dir = RunController::getGradePath($r['run']); if (file_exists("{$grade_dir}/compile_error.log")) { $response['compile_error'] = file_get_contents("{$grade_dir}/compile_error.log"); } if (OMEGAUP_LOCKDOWN) { $response['source'] = 'lockdownDetailsDisabled'; $response['status'] = 'ok'; return $response; } // Get the source $response['source'] = file_get_contents(RunController::getSubmissionPath($r['run'])); if (Authorization::IsProblemAdmin($r['current_user_id'], $r['problem'])) { if (file_exists("{$grade_dir}/details.json")) { $response['groups'] = json_decode(file_get_contents("{$grade_dir}/details.json"), true); } if (file_exists("{$grade_dir}/run.log")) { $response['logs'] = file_get_contents("{$grade_dir}/run.log"); } $response['judged_by'] = $r['run']->judged_by; } $response['guid'] = $r['run']->guid; $response['status'] = 'ok'; return $response; }
/** * Gets the details of a run. Includes admin details if admin. * * @param Request $r * @throws InvalidDatabaseOperationException */ public static function apiDetails(Request $r) { // Get the user who is calling this API self::authenticateRequest($r); self::validateDetailsRequest($r); try { $r["problem"] = ProblemsDAO::getByPK($r['run']->problem_id); } catch (Exception $e) { throw new InvalidDatabaseOperationException($e); } if (is_null($r["problem"])) { throw new NotFoundException("problemNotFound"); } if (!Authorization::CanViewRun($r["current_user_id"], $r["run"])) { throw new ForbiddenAccessException("userNotAllowed"); } $response = array(); if (OMEGAUP_LOCKDOWN) { // OMI hotfix // @TODO @joemmanuel, hay que localizar este msg :P $response['source'] = "Ver el código ha sido temporalmente desactivado."; $response["status"] = "ok"; return $response; } // Get the source $response['source'] = file_get_contents(RunController::getSubmissionPath($r['run'])); // Get the error $grade_dir = RunController::getGradePath($r['run']); if (file_exists("{$grade_dir}/compile_error.log")) { $response['compile_error'] = file_get_contents("{$grade_dir}/compile_error.log"); } if (Authorization::IsProblemAdmin($r['current_user_id'], $r['problem'])) { if (file_exists("{$grade_dir}/details.json")) { $response['groups'] = json_decode(file_get_contents("{$grade_dir}/details.json"), true); } if (file_exists("{$grade_dir}/run.log")) { $response['logs'] = file_get_contents("{$grade_dir}/run.log"); } $response['judged_by'] = $r["run"]->judged_by; } $response['guid'] = $r['run']->guid; $response["status"] = "ok"; return $response; }
/** * Returns details of a Contest. This is shared between apiDetails and * apiAdminDetails. * * @param Request $r * @param $result */ private static function getCachedDetails(Request $r, &$result) { Cache::getFromCacheOrSet(Cache::CONTEST_INFO, $r["contest_alias"], $r, function (Request $r) { // Create array of relevant columns $relevant_columns = array("title", "description", "start_time", "finish_time", "window_length", "alias", "scoreboard", "points_decay_factor", "partial_score", "submissions_gap", "feedback", "penalty", "time_start", "penalty_type", "penalty_calc_policy", "public", "show_scoreboard_after", "contestant_must_register", "languages"); // Initialize response to be the contest information $result = $r["contest"]->asFilteredArray($relevant_columns); $result['start_time'] = strtotime($result['start_time']); $result['finish_time'] = strtotime($result['finish_time']); try { $result['director'] = UsersDAO::getByPK($r['contest']->director_id)->username; } catch (Exception $e) { // Operation failed in the data layer throw new InvalidDatabaseOperationException($e); } // Get problems of the contest $key_problemsInContest = new ContestProblems(array("contest_id" => $r["contest"]->getContestId())); try { $problemsInContest = ContestProblemsDAO::search($key_problemsInContest, "order"); } catch (Exception $e) { // Operation failed in the data layer throw new InvalidDatabaseOperationException($e); } // Add info of each problem to the contest $problemsResponseArray = array(); // Set of columns that we want to show through this API. Doesn't include the SOURCE $relevant_columns = array("title", "alias", "validator", "time_limit", "overall_wall_time_limit", "extra_wall_time", "memory_limit", "visits", "submissions", "accepted", "dificulty", "order", "languages"); $letter = 0; foreach ($problemsInContest as $problemkey) { try { // Get the data of the problem $temp_problem = ProblemsDAO::getByPK($problemkey->getProblemId()); } catch (Exception $e) { // Operation failed in the data layer throw new InvalidDatabaseOperationException($e); } // Add the 'points' value that is stored in the ContestProblem relationship $temp_array = $temp_problem->asFilteredArray($relevant_columns); $temp_array["points"] = $problemkey->getPoints(); $temp_array['letter'] = ContestController::columnName($letter++); if (!empty($result['languages'])) { $temp_array['languages'] = join(',', array_intersect(explode(',', $result['languages']), explode(',', $temp_array['languages']))); } // Save our array into the response array_push($problemsResponseArray, $temp_array); } // Add problems to response $result['problems'] = $problemsResponseArray; return $result; }, $result, APC_USER_CACHE_CONTEST_INFO_TIMEOUT); }
/** * Returns details of a Contest * * @param Request $r * @return array * @throws InvalidDatabaseOperationException */ public static function apiDetails(Request $r) { self::validateDetails($r); Cache::getFromCacheOrSet(Cache::CONTEST_INFO, $r["contest_alias"], $r, function (Request $r) { // Create array of relevant columns $relevant_columns = array("title", "description", "start_time", "finish_time", "window_length", "alias", "scoreboard", "points_decay_factor", "partial_score", "submissions_gap", "feedback", "penalty", "time_start", "penalty_type", "penalty_calc_policy", "public", "show_scoreboard_after", "contestant_must_register", "languages"); // Initialize response to be the contest information $result = $r["contest"]->asFilteredArray($relevant_columns); $result['start_time'] = strtotime($result['start_time']); $result['finish_time'] = strtotime($result['finish_time']); try { $result['director'] = UsersDAO::getByPK($r['contest']->director_id)->username; } catch (Exception $e) { // Operation failed in the data layer throw new InvalidDatabaseOperationException($e); } // Get problems of the contest $key_problemsInContest = new ContestProblems(array("contest_id" => $r["contest"]->getContestId())); try { $problemsInContest = ContestProblemsDAO::search($key_problemsInContest, "order"); } catch (Exception $e) { // Operation failed in the data layer throw new InvalidDatabaseOperationException($e); } // Add info of each problem to the contest $problemsResponseArray = array(); // Set of columns that we want to show through this API. Doesn't include the SOURCE $relevant_columns = array("title", "alias", "validator", "time_limit", "overall_wall_time_limit", "extra_wall_time", "memory_limit", "visits", "submissions", "accepted", "dificulty", "order", "languages"); $letter = 0; foreach ($problemsInContest as $problemkey) { try { // Get the data of the problem $temp_problem = ProblemsDAO::getByPK($problemkey->getProblemId()); } catch (Exception $e) { // Operation failed in the data layer throw new InvalidDatabaseOperationException($e); } // Add the 'points' value that is stored in the ContestProblem relationship $temp_array = $temp_problem->asFilteredArray($relevant_columns); $temp_array["points"] = $problemkey->getPoints(); $temp_array['letter'] = ContestController::columnName($letter++); if (!empty($result['languages'])) { $temp_array['languages'] = join(',', array_intersect(explode(',', $result['languages']), explode(',', $temp_array['languages']))); } // Save our array into the response array_push($problemsResponseArray, $temp_array); } // Add problems to response $result['problems'] = $problemsResponseArray; return $result; }, $result, APC_USER_CACHE_CONTEST_INFO_TIMEOUT); if (is_null($r['token'])) { // Adding timer info separately as it depends on the current user and we don't // want this to get generally cached for everybody // Save the time of the first access try { $contest_user = ContestsUsersDAO::CheckAndSaveFirstTimeAccess($r["current_user_id"], $r["contest"]->getContestId()); } catch (Exception $e) { // Operation failed in the data layer throw new InvalidDatabaseOperationException($e); } // Add time left to response if ($r["contest"]->getWindowLength() === null) { $result['submission_deadline'] = strtotime($r["contest"]->getFinishTime()); } else { $result['submission_deadline'] = min(strtotime($r["contest"]->getFinishTime()), strtotime($contest_user->getAccessTime()) + $r["contest"]->getWindowLength() * 60); } $result['admin'] = Authorization::IsContestAdmin($r["current_user_id"], $r["contest"]); } $result["status"] = "ok"; return $result; }