Skip to content

Commit

Permalink
[Dropzone] allows to delete user drops
Browse files Browse the repository at this point in the history
phpcs
  • Loading branch information
Elorfin committed Jan 21, 2021
1 parent f94a50e commit addb500
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 633 deletions.
72 changes: 36 additions & 36 deletions src/plugin/drop-zone/Controller/API/DropController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Claroline\DropZoneBundle\Controller\API;

use Claroline\AppBundle\API\FinderProvider;
use Claroline\AppBundle\Controller\RequestDecoderTrait;
use Claroline\AppBundle\Persistence\ObjectManager;
use Claroline\CoreBundle\Entity\User;
use Claroline\CoreBundle\Library\Normalizer\DateNormalizer;
Expand All @@ -35,9 +36,12 @@

/**
* @Route("/dropzone", options={"expose"=true})
*
* @todo use crud
*/
class DropController
{
use RequestDecoderTrait;
use PermissionCheckerTrait;

/** @var FinderProvider */
Expand Down Expand Up @@ -130,6 +134,29 @@ public function createAction(Dropzone $dropzone, User $user, Team $team = null):
}
}

/**
* Delete Drop.
*
* @Route("/{id}/drops", name="claro_dropzone_drop_delete", methods={"DELETE"})
* @EXT\ParamConverter("dropzone", class="ClarolineDropZoneBundle:Dropzone", options={"mapping": {"id": "uuid"}})
*/
public function deleteAction(Dropzone $dropzone, Request $request): JsonResponse
{
$this->checkPermission('EDIT', $dropzone->getResourceNode(), [], true);

if (!$dropzone->hasLockDrops()) {
$drops = $this->decodeIdsString($request, Drop::class);

$this->om->startFlushSuite();
foreach ($drops as $drop) {
$this->manager->deleteDrop($drop);
}
$this->om->endFlushSuite();
}

return new JsonResponse(null, 204);
}

/**
* Submits Drop.
*
Expand Down Expand Up @@ -420,9 +447,9 @@ public function toolExecuteAction(DropzoneTool $tool, Document $document): JsonR
/**
* Downloads drops documents into a ZIP archive.
*
* @Route("/drops/download", name="claro_dropzone_drops_download", methods={"POST"})
* @Route("/drops/download", name="claro_dropzone_drops_download", methods={"GET"})
*/
public function dropsDownloadAction(Request $request): StreamedResponse
public function downloadAction(Request $request): StreamedResponse
{
$drops = $this->decodeIdsString($request, Drop::class);
/** @var Dropzone $dropzone */
Expand Down Expand Up @@ -451,7 +478,7 @@ function () use ($archive) {
* @Route("/{id}/drops/csv", name="claro_dropzone_drops_csv", methods={"GET"})
* @EXT\ParamConverter("dropzone", class="ClarolineDropZoneBundle:Dropzone", options={"mapping": {"id": "uuid"}})
*/
public function exportDropsCsvAction(Dropzone $dropzone): StreamedResponse
public function exportCsvAction(Dropzone $dropzone): StreamedResponse
{
$this->checkPermission('EDIT', $dropzone->getResourceNode(), [], true);

Expand Down Expand Up @@ -514,17 +541,10 @@ public function exportDropsCsvAction(Dropzone $dropzone): StreamedResponse
}

/**
* @Route(
* "/drop/{id}/next",
* name="claro_dropzone_drop_next"
* )
* @EXT\ParamConverter(
* "drop",
* class="ClarolineDropZoneBundle:Drop",
* options={"mapping": {"id": "uuid"}}
* )
* @Route("/drop/{id}/next", name="claro_dropzone_drop_next")
* @EXT\ParamConverter("drop", class="ClarolineDropZoneBundle:Drop", options={"mapping": {"id": "uuid"}})
*/
public function nextDropAction(Drop $drop, Request $request): JsonResponse
public function nextAction(Drop $drop, Request $request): JsonResponse
{
$dropzone = $drop->getDropzone();
$collection = new ResourceCollection([$dropzone->getResourceNode()]);
Expand Down Expand Up @@ -554,17 +574,10 @@ public function nextDropAction(Drop $drop, Request $request): JsonResponse
}

/**
* @Route(
* "/drop/{id}/previous",
* name="claro_dropzone_drop_previous"
* )
* @EXT\ParamConverter(
* "drop",
* class="ClarolineDropZoneBundle:Drop",
* options={"mapping": {"id": "uuid"}}
* )
* @Route("/drop/{id}/previous", name="claro_dropzone_drop_previous")
* @EXT\ParamConverter("drop", class="ClarolineDropZoneBundle:Drop", options={"mapping": {"id": "uuid"}})
*/
public function previousDropAction(Drop $drop, Request $request): JsonResponse
public function previousAction(Drop $drop, Request $request): JsonResponse
{
$dropzone = $drop->getDropzone();
$collection = new ResourceCollection([$dropzone->getResourceNode()]);
Expand Down Expand Up @@ -616,17 +629,4 @@ private function checkTeamUser(Team $team, User $user)
throw new AccessDeniedException();
}
}

/**
* @param string $class
*
* @return array
*/
protected function decodeIdsString(Request $request, $class)
{
$ids = json_decode($request->getContent(), true)['_ids'];
$property = is_numeric($ids[0]) ? 'id' : 'uuid';

return $this->om->findList($class, $property, $ids);
}
}
19 changes: 19 additions & 0 deletions src/plugin/drop-zone/Entity/Dropzone.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,15 @@ class Dropzone extends AbstractResource
*/
protected $revisionEnabled = false;

/**
* If true, drops for the current dropzone can not be deleted.
*
* @ORM\Column(name="lock_drops", type="boolean", nullable=false)
*
* @var bool
*/
protected $lockDrops = false;

/**
* Dropzone constructor.
*/
Expand Down Expand Up @@ -702,4 +711,14 @@ public function setRevisionEnabled($revisionEnabled)
{
$this->revisionEnabled = $revisionEnabled;
}

public function hasLockDrops(): bool
{
return $this->lockDrops;
}

public function setLockDrops(bool $locked)
{
$this->lockDrops = $locked;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Claroline\DropZoneBundle\Installation\Migrations\pdo_mysql;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated migration based on mapping information: modify it with caution.
*
* Generation date: 2021/01/20 12:08:30
*/
class Version20210120120829 extends AbstractMigration
{
public function up(Schema $schema)
{
$this->addSql('
ALTER TABLE claro_dropzonebundle_dropzone
ADD lock_drops TINYINT(1) NOT NULL
');

$this->addSql('
UPDATE claro_dropzonebundle_dropzone SET lock_drops = 0
');
}

public function down(Schema $schema)
{
$this->addSql('
ALTER TABLE claro_dropzonebundle_dropzone
DROP lock_drops
');
}
}
Loading

0 comments on commit addb500

Please # to comment.