Ejemplo n.º 1
0
 /**
  * Removes a group admin from a contest
  *
  * @param Request $r
  * @return array
  * @throws InvalidDatabaseOperationException
  * @throws ForbiddenAccessException
  */
 public static function apiRemoveGroupAdmin(Request $r)
 {
     // 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 admin is alowed to make modifications
     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);
     // Delete the role
     try {
         GroupRolesDAO::delete($group_role);
     } catch (Exception $e) {
         // Operation failed in the data layer
         throw new InvalidDatabaseOperationException($e);
     }
     return array('status' => 'ok');
 }
Ejemplo n.º 2
0
 /**
  * Removes a group admin from a problem
  *
  * @param Request $r
  * @return array
  * @throws InvalidDatabaseOperationException
  * @throws ForbiddenAccessException
  */
 public static function apiRemoveGroupAdmin(Request $r)
 {
     // Authenticate logged user
     self::authenticateRequest($r);
     // Check whether problem exists
     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);
     // Delete the role
     try {
         GroupRolesDAO::delete($group_role);
     } catch (Exception $e) {
         // Operation failed in the data layer
         throw new InvalidDatabaseOperationException($e);
     }
     return array('status' => 'ok');
 }