Example #1
0
 public function getPackageMaintainersQueryBuilder(Package $package, User $excludeUser = null)
 {
     $qb = $this->createQueryBuilder('u')->select('u')->innerJoin('u.packages', 'p', 'WITH', 'p.id = :packageId')->setParameter(':packageId', $package->getId())->orderBy('u.username', 'ASC');
     if ($excludeUser) {
         $qb->andWhere('u.id <> :userId')->setParameter(':userId', $excludeUser->getId());
     }
     return $qb;
 }
Example #2
0
 /**
  * @dataProvider githubApiProvider
  */
 public function testGithubApi($url)
 {
     $client = self::createClient();
     $package = new Package();
     $package->setRepository($url);
     $user = new User();
     $user->addPackages($package);
     $repo = $this->getMockBuilder('Packagist\\WebBundle\\Entity\\UserRepository')->disableOriginalConstructor()->getMock();
     $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $updater = $this->getMockBuilder('Packagist\\WebBundle\\Package\\Updater')->disableOriginalConstructor()->getMock();
     $repo->expects($this->once())->method('findOneBy')->with($this->equalTo(array('username' => 'test', 'apiToken' => 'token')))->will($this->returnValue($user));
     static::$kernel->getContainer()->set('packagist.user_repository', $repo);
     static::$kernel->getContainer()->set('doctrine.orm.entity_manager', $em);
     static::$kernel->getContainer()->set('packagist.package_updater', $updater);
     $payload = json_encode(array('repository' => array('url' => 'git://github.com/composer/composer')));
     $client->request('POST', '/api/github?username=test&apiToken=token', array('payload' => $payload));
     $this->assertEquals(202, $client->getResponse()->getStatusCode());
 }
Example #3
0
 public function isVendorTaken($vendor, User $user)
 {
     $query = $this->getEntityManager()->createQuery("SELECT p.name, m.id user_id\n                FROM Packagist\\WebBundle\\Entity\\Package p\n                JOIN p.maintainers m\n                WHERE p.name LIKE :vendor")->setParameters(array('vendor' => $vendor . '/%'));
     $rows = $query->getArrayResult();
     if (!$rows) {
         return false;
     }
     foreach ($rows as $row) {
         if ($row['user_id'] === $user->getId()) {
             return false;
         }
     }
     return true;
 }
 /**
  * Find a user package given by its full URL
  *
  * @param User $user
  * @param string $url
  * @param string $urlRegex
  * @return array the packages found
  */
 protected function findPackagesByUrl(User $user, $url, $urlRegex)
 {
     if (!preg_match($urlRegex, $url, $matched)) {
         return array();
     }
     $packages = array();
     foreach ($user->getPackages() as $package) {
         if (preg_match($urlRegex, $package->getRepository(), $candidate) && $candidate['host'] === $matched['host'] && $candidate['path'] === $matched['path']) {
             $packages[] = $package;
         }
     }
     return $packages;
 }
Example #5
0
 /**
  * @param Request $req
  * @param User $user
  * @return Pagerfanta
  */
 protected function getUserPackages($req, $user)
 {
     $packages = $this->getDoctrine()->getRepository('PackagistWebBundle:Package')->getFilteredQueryBuilder(array('maintainer' => $user->getId()))->orderBy('p.name');
     $paginator = new Pagerfanta(new DoctrineORMAdapter($packages, true));
     $paginator->setMaxPerPage(15);
     $paginator->setCurrentPage($req->query->get('page', 1), false, true);
     return $paginator;
 }
 /**
  * @Route("/users/{name}/favorites/{package}", name="user_remove_fav", defaults={"_format" = "json"}, requirements={"package"="[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"})
  * @ParamConverter("user", options={"mapping": {"name": "username"}})
  * @ParamConverter("package", options={"mapping": {"package": "name"}})
  * @Method({"DELETE"})
  */
 public function deleteFavoriteAction(User $user, Package $package)
 {
     if ($user->getId() !== $this->getUser()->getId()) {
         throw new AccessDeniedException('You can only change your own favorites');
     }
     $this->get('packagist.favorite_manager')->removeFavorite($user, $package);
     return new Response('{"status": "success"}', 204);
 }
Example #7
0
 public function getQueryBuilderByMaintainer(User $user)
 {
     $qb = $this->getBaseQueryBuilder()->select('p, v')->where('m.id = ?0')->setParameters(array($user->getId()));
     return $qb;
 }