コード例 #1
0
 /**
  * Adds an group admin to a contest
  *
  * @param Request $r
  * @return array
  * @throws InvalidDatabaseOperationException
  * @throws ForbiddenAccessException
  */
 public static function apiAddGroupAdmin(Request $r)
 {
     if (OMEGAUP_LOCKDOWN) {
         throw new ForbiddenAccessException('lockdown');
     }
     // Authenticate logged user
     self::authenticateRequest($r);
     // Check contest_alias
     Validators::isStringNonEmpty($r['contest_alias'], 'contest_alias');
     $group = GroupsDAO::FindByAlias($r['group']);
     if ($group == null) {
         throw new InvalidParameterException('invalidParameters');
     }
     try {
         $r['contest'] = ContestsDAO::getByAlias($r['contest_alias']);
     } catch (Exception $e) {
         // Operation failed in the data layer
         throw new InvalidDatabaseOperationException($e);
     }
     // Only admins are allowed to modify contest
     if (!Authorization::IsContestAdmin($r['current_user_id'], $r['contest'])) {
         throw new ForbiddenAccessException();
     }
     $group_role = new GroupRoles();
     $group_role->setContestId($r['contest']->getContestId());
     $group_role->setGroupId($group->group_id);
     $group_role->setRoleId(CONTEST_ADMIN_ROLE);
     // Save the contest to the DB
     try {
         GroupRolesDAO::save($group_role);
     } catch (Exception $e) {
         // Operation failed in the data layer
         throw new InvalidDatabaseOperationException($e);
     }
     return array('status' => 'ok');
 }
コード例 #2
0
 /**
  * Adds a group admin to a problem
  *
  * @param Request $r
  * @return array
  * @throws InvalidDatabaseOperationException
  * @throws ForbiddenAccessException
  */
 public static function apiAddGroupAdmin(Request $r)
 {
     // Authenticate logged user
     self::authenticateRequest($r);
     // Check problem_alias
     Validators::isStringNonEmpty($r['problem_alias'], 'problem_alias');
     $group = GroupsDAO::FindByAlias($r['group']);
     if ($group == null) {
         throw new InvalidParameterException('invalidParameters');
     }
     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();
     }
     $group_role = new GroupRoles();
     $group_role->setContestId($r['problem']->problem_id);
     $group_role->setGroupId($group->group_id);
     $group_role->setRoleId(PROBLEM_ADMIN_ROLE);
     // Save the role
     try {
         GroupRolesDAO::save($group_role);
     } catch (Exception $e) {
         // Operation failed in the data layer
         self::$log->error('Failed to save user roles');
         self::$log->error($e);
         throw new InvalidDatabaseOperationException($e);
     }
     return array('status' => 'ok');
 }