Browse Source

Fix package edition

Jordi Boggiano 12 years ago
parent
commit
95afb15f24

+ 5 - 5
composer.lock

@@ -15,7 +15,7 @@
         },
         {
             "package": "doctrine/common",
-            "version": "2.2.2"
+            "version": "2.2.3"
         },
         {
             "package": "doctrine/dbal",
@@ -170,8 +170,8 @@
         {
             "package": "symfony/symfony",
             "version": "dev-master",
-            "source-reference": "31536c36ec8875aee1406aa7d7a0b5e38a04af66",
-            "commit-date": "1344599303"
+            "source-reference": "569e29d91fd35e91acc2dbcf490ad0f645eecd6d",
+            "commit-date": "1346331893"
         },
         {
             "package": "twig/extensions",
@@ -188,8 +188,8 @@
         {
             "package": "twig/twig",
             "version": "dev-master",
-            "source-reference": "f2f698c820d4396f519ef4175ad6fe79fcfb9ecf",
-            "commit-date": "1344328685"
+            "source-reference": "f76ed618c890165fd107a9cd4a06c7d73da75b9c",
+            "commit-date": "1346324412"
         },
         {
             "package": "white-october/pagerfanta-bundle",

+ 1 - 3
src/Packagist/WebBundle/Controller/PackageController.php

@@ -42,13 +42,11 @@ class PackageController extends Controller
             throw new AccessDeniedException;
         }
 
-        $form = $this->createFormBuilder($package, array("validation_groups" => array("update")))
+        $form = $this->createFormBuilder($package, array("validation_groups" => array("Update")))
             ->add("repository", "text")
             ->getForm();
 
         if ($req->isMethod("POST")) {
-            $package->setEntityRepository($packageRepo);
-
             $form->bind($req);
 
             if ($form->isValid()) {

+ 13 - 4
src/Packagist/WebBundle/Entity/Package.php

@@ -32,7 +32,8 @@ use Composer\Repository\RepositoryManager;
  *         @ORM\Index(name="dumped_idx",columns={"dumpedAt"})
  *     }
  * )
- * @Assert\Callback(methods={"isPackageUnique","isRepositoryValid"}, groups={"update"})
+ * @Assert\Callback(methods={"isPackageUnique"})
+ * @Assert\Callback(methods={"isRepositoryValid"}, groups={"Update", "Default"})
  * @author Jordi Boggiano <j.boggiano@seld.be>
  */
 class Package
@@ -74,7 +75,7 @@ class Package
 
     /**
      * @ORM\Column()
-     * @Assert\NotBlank(groups={"update"})
+     * @Assert\NotBlank(groups={"Update", "Default"})
      */
     private $repository;
 
@@ -111,10 +112,11 @@ class Package
     private $autoUpdated = false;
 
     private $entityRepository;
+
     /**
      * @var \Composer\Repository\Vcs\VcsDriverInterface
      */
-    private $vcsDriver;
+    private $vcsDriver = true;
 
     public function __construct()
     {
@@ -147,9 +149,14 @@ class Package
 
     public function isRepositoryValid(ExecutionContext $context)
     {
+        // vcs driver was not nulled which means the repository was not set/modified and is still valid
+        if (true === $this->vcsDriver && null !== $this->getName()) {
+            return;
+        }
+
         $property = 'repository';
         $driver = $this->vcsDriver;
-        if (!$driver) {
+        if (!is_object($driver)) {
             if (preg_match('{//.+@}', $this->repository)) {
                 $context->addViolationAtSubPath($property, 'URLs with user@host are not supported, use a read-only public URL', array(), null);
             } else {
@@ -293,6 +300,8 @@ class Package
      */
     public function setRepository($repository)
     {
+        $this->vcsDriver = null;
+
         // prevent local filesystem URLs
         if (preg_match('{^(\.|[a-z]:|/)}i', $repository)) {
             return;

+ 1 - 1
src/Packagist/WebBundle/Resources/views/Web/viewPackage.html.twig

@@ -8,7 +8,7 @@
 
 {% block content %}
     <div class="box">
-        <div class="package"{% if app.user and package.maintainers.contains(app.user) and package.crawledAt is null %} data-force-crawl="true"{% endif %}>
+        <div class="package"{% if app.user and package.crawledAt is null and (is_granted('ROLE_EDIT_PACKAGES') or package.maintainers.contains(app.user)) %} data-force-crawl="true"{% endif %}>
             {% if is_granted('ROLE_EDIT_PACKAGES') or package.maintainers.contains(app.user) %}
                 <form class="action" action="{{ path("edit_package", {name: package.name}) }}">
                     <input type="submit" value="Edit" />