Exemplo n.º 1
0
 public function testCreateAdmin()
 {
     $user = self::$f->createUser('*****@*****.**', 'A user', '');
     $this->assertFalse($user->isAdmin());
     self::$f->setAdminPrivileges($user, true);
     $this->assertTrue($user->isAdmin());
     // reload user
     $user = self::$f->load('*****@*****.**');
     $this->assertTrue($user->isAdmin());
     self::$f->setAdminPrivileges($user, false);
     $this->assertFalse($user->isAdmin());
     $user = self::$f->load('*****@*****.**');
     $this->assertFalse($user->isAdmin());
 }
 /**
  * @inheritdoc
  */
 public function exec(Server $server, ConnectionInterface $db, CacheInterface $cache)
 {
     $userFactory = new UserFactory($db, $cache);
     $user = $userFactory->load($_REQUEST['user']);
     $response = new OperationResponse();
     if (!$user) {
         $response->setStatus(400);
         $response->setBody(array('error' => 'Argument "user" is referring to a user that does not exist'));
     } elseif ($this->user->isEqual($user)) {
         $response->setStatus(400);
         $response->setBody(array('error' => 'A user can not change admin privileges for its own user account'));
     } else {
         $userFactory->setAdminPrivileges($user, $_REQUEST['admin'] == '1');
         $response->setStatus(204);
     }
     return $response;
 }