示例#1
0
 /**
  * Removes an admin from a contest
  *
  * @param Request $r
  * @return array
  * @throws InvalidDatabaseOperationException
  * @throws ForbiddenAccessException
  */
 public static function apiRemoveAdmin(Request $r)
 {
     // Authenticate logged user
     self::authenticateRequest($r);
     // Check contest_alias
     Validators::isStringNonEmpty($r["contest_alias"], "contest_alias");
     $r["user"] = UserController::resolveUser($r["usernameOrEmail"]);
     try {
         $r["contest"] = ContestsDAO::getByAlias($r["contest_alias"]);
     } catch (Exception $e) {
         // Operation failed in the data layer
         throw new InvalidDatabaseOperationException($e);
     }
     // Only admin is alowed to make modifications
     if (!Authorization::IsContestAdmin($r["current_user_id"], $r["contest"])) {
         throw new ForbiddenAccessException();
     }
     // Check if admin to delete is actually an admin
     if (!Authorization::IsContestAdmin($r["user"]->getUserId(), $r["contest"])) {
         throw new NotFoundException();
     }
     $contest_user = new UserRoles();
     $contest_user->setContestId($r["contest"]->getContestId());
     $contest_user->setUserId($r["user"]->getUserId());
     $contest_user->setRoleId(CONTEST_ADMIN_ROLE);
     // Delete the role
     try {
         UserRolesDAO::delete($contest_user);
     } catch (Exception $e) {
         // Operation failed in the data layer
         throw new InvalidDatabaseOperationException($e);
     }
     return array("status" => "ok");
 }
 /**
  * Removes an admin from a contest
  *
  * @param Request $r
  * @return array
  * @throws InvalidDatabaseOperationException
  * @throws ForbiddenAccessException
  */
 public static function apiRemoveAdmin(Request $r)
 {
     // Authenticate logged user
     self::authenticateRequest($r);
     // Check whether problem exists
     Validators::isStringNonEmpty($r['problem_alias'], 'problem_alias');
     $r['user'] = UserController::resolveUser($r['usernameOrEmail']);
     try {
         $r['problem'] = ProblemsDAO::getByAlias($r['problem_alias']);
     } catch (Exception $e) {
         // Operation failed in the data layer
         throw new InvalidDatabaseOperationException($e);
     }
     if (!Authorization::IsProblemAdmin($r['current_user_id'], $r['problem'])) {
         throw new ForbiddenAccessException();
     }
     // Check if admin to delete is actually an admin
     if (!Authorization::IsProblemAdmin($r['user']->user_id, $r['problem'])) {
         throw new NotFoundException();
     }
     $user_role = new UserRoles();
     $user_role->setContestId($r['problem']->problem_id);
     $user_role->setUserId($r['user']->user_id);
     $user_role->setRoleId(PROBLEM_ADMIN_ROLE);
     // Delete the role
     try {
         UserRolesDAO::delete($user_role);
     } catch (Exception $e) {
         // Operation failed in the data layer
         throw new InvalidDatabaseOperationException($e);
     }
     return array('status' => 'ok');
 }