本文整理汇总了PHP中Authorization::IsProblemAdmin方法的典型用法代码示例。如果您正苦于以下问题:PHP Authorization::IsProblemAdmin方法的具体用法?PHP Authorization::IsProblemAdmin怎么用?PHP Authorization::IsProblemAdmin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Authorization
的用法示例。
在下文中一共展示了Authorization::IsProblemAdmin方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: CanEditProblem
public static function CanEditProblem($user_id, Problems $problem)
{
if (is_null($problem) || !is_a($problem, 'Problems')) {
return false;
}
return Authorization::IsProblemAdmin($user_id, $problem);
}
示例2: apiDetails
/**
* 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;
}
示例3: apiDetails
/**
* 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;
}
示例4: apiDetails
/**
* Entry point for Problem Details API
*
* @param Request $r
* @throws InvalidFilesystemOperationException
* @throws InvalidDatabaseOperationException
*/
public static function apiDetails(Request $r)
{
// Get user.
// Allow unauthenticated requests if we are not openning a problem
// inside a contest.
try {
self::authenticateRequest($r);
} catch (UnauthorizedException $e) {
if (!is_null($r['contest_alias'])) {
throw $e;
}
}
// Validate request
self::validateDetails($r);
$response = array();
// Create array of relevant columns
$relevant_columns = array('title', 'alias', 'validator', 'time_limit', 'validator_time_limit', 'overall_wall_time_limit', 'extra_wall_time', 'memory_limit', 'output_limit', 'visits', 'submissions', 'accepted', 'difficulty', 'creation_date', 'source', 'order', 'points', 'public', 'languages', 'slow', 'stack_limit', 'email_clarifications');
// Read the file that contains the source
if (!ProblemController::isLanguageSupportedForProblem($r)) {
// If there is no language file for the problem, return the spanish version.
$r['lang'] = 'es';
}
$statement_type = ProblemController::getStatementType($r);
Cache::getFromCacheOrSet(Cache::PROBLEM_STATEMENT, $r['problem']->getAlias() . '-' . $r['lang'] . '-' . $statement_type, $r, 'ProblemController::getProblemStatement', $file_content, APC_USER_CACHE_PROBLEM_STATEMENT_TIMEOUT);
// Add problem statement to source
$response['problem_statement'] = $file_content;
$response['problem_statement_language'] = $r['lang'];
// Add the example input.
$sample_input = null;
Cache::getFromCacheOrSet(Cache::PROBLEM_SAMPLE, $r['problem']->getAlias() . '-sample.in', $r, 'ProblemController::getSampleInput', $sample_input, APC_USER_CACHE_PROBLEM_STATEMENT_TIMEOUT);
if (!empty($sample_input)) {
$response['sample_input'] = $sample_input;
}
// Add the problem the response
$response = array_merge($response, $r['problem']->asFilteredArray($relevant_columns));
// If the problem is public or if the user has admin privileges, show the
// problem source and alias of owner.
if ($r['problem']->public || Authorization::IsProblemAdmin($r['current_user_id'], $r['problem'])) {
$problemsetter = UsersDAO::getByPK($r['problem']->author_id);
if (!is_null($problemsetter)) {
$response['problemsetter'] = array('username' => $problemsetter->username, 'name' => is_null($problemsetter->name) ? $problemsetter->username : $problemsetter->name);
}
} else {
unset($response['source']);
}
if (!is_null($r['current_user_id'])) {
// Create array of relevant columns for list of runs
$relevant_columns = array('guid', 'language', 'status', 'verdict', 'runtime', 'penalty', 'memory', 'score', 'contest_score', 'time', 'submit_delay');
// Search the relevant runs from the DB
$contest = ContestsDAO::getByAlias($r['contest_alias']);
$keyrun = new Runs(array('user_id' => $r['current_user_id'], 'problem_id' => $r['problem']->getProblemId(), 'contest_id' => is_null($r['contest']) ? null : $r['contest']->getContestId()));
// Get all the available runs done by the current_user
try {
$runs_array = RunsDAO::search($keyrun);
} catch (Exception $e) {
// Operation failed in the data layer
throw new InvalidDatabaseOperationException($e);
}
// Add each filtered run to an array
if (count($runs_array) >= 0) {
$runs_filtered_array = array();
foreach ($runs_array as $run) {
$filtered = $run->asFilteredArray($relevant_columns);
$filtered['alias'] = $r['problem']->alias;
$filtered['username'] = $r['current_user']->username;
$filtered['time'] = strtotime($filtered['time']);
array_push($runs_filtered_array, $filtered);
}
}
$response['runs'] = $runs_filtered_array;
}
if (!is_null($r['contest'])) {
// At this point, contestant_user relationship should be established.
try {
ContestsUsersDAO::CheckAndSaveFirstTimeAccess($r['current_user_id'], $r['contest']->contest_id);
} catch (ApiException $e) {
throw $e;
} catch (Exception $e) {
// Operation failed in the data layer
throw new InvalidDatabaseOperationException($e);
}
// As last step, register the problem as opened
if (!ContestProblemOpenedDAO::getByPK($r['contest']->getContestId(), $r['problem']->getProblemId(), $r['current_user_id'])) {
//Create temp object
$keyContestProblemOpened = new ContestProblemOpened(array('contest_id' => $r['contest']->getContestId(), 'problem_id' => $r['problem']->getProblemId(), 'user_id' => $r['current_user_id']));
try {
// Save object in the DB
ContestProblemOpenedDAO::save($keyContestProblemOpened);
} catch (Exception $e) {
// Operation failed in the data layer
throw new InvalidDatabaseOperationException($e);
}
}
//.........这里部分代码省略.........
示例5: validateDownload
/**
* Validate problem Details API
*
* @param Request $r
* @throws ApiException
* @throws InvalidDatabaseOperationException
* @throws NotFoundException
* @throws ForbiddenAccessException
*/
private static function validateDownload(Request $r)
{
Validators::isStringNonEmpty($r["problem_alias"], "problem_alias");
try {
$r["problem"] = ProblemsDAO::getByAlias($r["problem_alias"]);
} catch (Exception $e) {
throw new InvalidDatabaseOperationException($e);
}
if (is_null($r["problem"])) {
throw new NotFoundException("problemNotFound");
}
if (!Authorization::IsProblemAdmin($r["current_user_id"], $r["problem"])) {
throw new ForbiddenAccessException();
}
}