Пример #1
0
 /**
  * Basic create group test
  */
 public function testCreateGroup()
 {
     $owner = UserFactory::createUser();
     $name = Utils::CreateRandomString();
     $description = Utils::CreateRandomString();
     $alias = Utils::CreateRandomString();
     $response = GroupController::apiCreate(new Request(array('auth_token' => self::login($owner), 'name' => $name, 'alias' => $alias, 'description' => $description)));
     $this->assertEquals('ok', $response['status']);
     $groups = GroupsDAO::search(new Groups(array('name' => $name)));
     $group = $groups[0];
     $this->assertNotNull($group);
     $this->assertEquals($description, $group->getDescription());
     $this->assertEquals($owner->getUserId(), $group->getOwnerId());
 }
Пример #2
0
 /**
  * Create group
  * 
  * @param type $owner
  * @param type $name
  * @param type $description
  */
 public static function createGroup($owner = null, $name = null, $description = null, $alias = null)
 {
     if (is_null($owner)) {
         $owner = UserFactory::createUser();
     }
     if (is_null($name)) {
         $name = Utils::CreateRandomString();
     }
     if (is_null($description)) {
         $description = Utils::CreateRandomString();
     }
     if (is_null($alias)) {
         $alias = Utils::CreateRandomString();
     }
     $r = new Request(array("auth_token" => OmegaupTestCase::login($owner), "name" => $name, "description" => $description, "alias" => $alias));
     $response = GroupController::apiCreate($r);
     $groups = GroupsDAO::search(new Groups(array("alias" => $alias)));
     return array("request" => $r, "response" => $response, "owner" => $owner, "group" => $groups[0]);
 }
Пример #3
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');
 }
 /**
  * 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');
 }
Пример #5
0
 /**
  * Returns a list of groups by owner
  * 
  * @param Request $r
  */
 public static function apiList(Request $r)
 {
     self::authenticateRequest($r);
     $response = array();
     $response["groups"] = array();
     try {
         $groups = GroupsDAO::search(new Groups(array("owner_id" => $r["current_user_id"])));
         foreach ($groups as $group) {
             $response["groups"][] = $group->asArray();
         }
     } catch (Exception $ex) {
         throw new InvalidDatabaseOperationException($ex);
     }
     $response["status"] = "ok";
     return $response;
 }
Пример #6
0
 /**
  * Returns a list of groups that match a partial name. This returns an
  * array instead of an object since it is used by typeahead.
  *
  * @param Request $r
  */
 public static function apiList(Request $r)
 {
     self::authenticateRequest($r);
     if (is_null($r['query'])) {
         throw new InvalidParameterException('parameterEmpty', 'query');
     }
     if (strlen($r['query']) < 2) {
         throw new InvalidParameterException('parameterInvalid', 'query');
     }
     try {
         $groups = GroupsDAO::SearchByName($r['query']);
     } catch (Exception $ex) {
         throw new InvalidDatabaseOperationException($ex);
     }
     $response = array();
     foreach ($groups as $group) {
         array_push($response, array('label' => $group->name, 'value' => $group->alias));
     }
     return $response;
 }