mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Add DAV edit link to StoredObject serialization
Enabled the adding of access link, specifically DAV edit link to the JSON serialization of the StoredObject entity. The patch also adjusted the serializer groups of various attributes of StoredObject from "read, write" to "write". Lastly, these changes were reflected in the accompanying CourseWork Controller and the FormEvaluation Vue component.
This commit is contained in:
parent
0dd58cebec
commit
47a928a6cd
@ -48,14 +48,14 @@ class StoredObject implements AsyncFileInterface, Document, TrackCreationInterfa
|
||||
/**
|
||||
* @ORM\Column(type="json", name="datas")
|
||||
*
|
||||
* @Serializer\Groups({"read", "write"})
|
||||
* @Serializer\Groups({"write"})
|
||||
*/
|
||||
private array $datas = [];
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text")
|
||||
*
|
||||
* @Serializer\Groups({"read", "write"})
|
||||
* @Serializer\Groups({"write"})
|
||||
*/
|
||||
private string $filename = '';
|
||||
|
||||
@ -66,7 +66,7 @@ class StoredObject implements AsyncFileInterface, Document, TrackCreationInterfa
|
||||
*
|
||||
* @ORM\Column(type="integer")
|
||||
*
|
||||
* @Serializer\Groups({"read", "write"})
|
||||
* @Serializer\Groups({"write"})
|
||||
*/
|
||||
private ?int $id = null;
|
||||
|
||||
@ -75,35 +75,35 @@ class StoredObject implements AsyncFileInterface, Document, TrackCreationInterfa
|
||||
*
|
||||
* @ORM\Column(type="json", name="iv")
|
||||
*
|
||||
* @Serializer\Groups({"read", "write"})
|
||||
* @Serializer\Groups({"write"})
|
||||
*/
|
||||
private array $iv = [];
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="json", name="key")
|
||||
*
|
||||
* @Serializer\Groups({"read", "write"})
|
||||
* @Serializer\Groups({"write"})
|
||||
*/
|
||||
private array $keyInfos = [];
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text", name="title")
|
||||
*
|
||||
* @Serializer\Groups({"read", "write"})
|
||||
* @Serializer\Groups({"write"})
|
||||
*/
|
||||
private string $title = '';
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text", name="type", options={"default": ""})
|
||||
*
|
||||
* @Serializer\Groups({"read", "write"})
|
||||
* @Serializer\Groups({"write"})
|
||||
*/
|
||||
private string $type = '';
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="uuid", unique=true)
|
||||
*
|
||||
* @Serializer\Groups({"read", "write"})
|
||||
* @Serializer\Groups({"write"})
|
||||
*/
|
||||
private UuidInterface $uuid;
|
||||
|
||||
@ -137,8 +137,6 @@ class StoredObject implements AsyncFileInterface, Document, TrackCreationInterfa
|
||||
*/
|
||||
public function __construct(/**
|
||||
* @ORM\Column(type="text", options={"default": "ready"})
|
||||
*
|
||||
* @Serializer\Groups({"read"})
|
||||
*/
|
||||
private string $status = 'ready'
|
||||
) {
|
||||
|
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\DocStoreBundle\Serializer\Normalizer;
|
||||
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\DocStoreBundle\Security\Authorization\StoredObjectRoleEnum;
|
||||
use Chill\DocStoreBundle\Security\Guard\JWTDavTokenProviderInterface;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
|
||||
/**
|
||||
* Class StoredObjectNormalizer.
|
||||
*
|
||||
* Normalizes a StoredObject entity to an array of data.
|
||||
*/
|
||||
class StoredObjectNormalizer implements NormalizerInterface, NormalizerAwareInterface
|
||||
{
|
||||
use NormalizerAwareTrait;
|
||||
public const ADD_DAV_SEE_LINK_CONTEXT = 'dav-see-link-context';
|
||||
public const ADD_DAV_EDIT_LINK_CONTEXT = 'dav-edit-link-context';
|
||||
|
||||
public function __construct(
|
||||
private JWTDavTokenProviderInterface $JWTDavTokenProvider,
|
||||
private UrlGeneratorInterface $urlGenerator
|
||||
) {
|
||||
}
|
||||
|
||||
public function normalize($object, ?string $format = null, array $context = [])
|
||||
{
|
||||
/** @var StoredObject $object */
|
||||
$datas = [
|
||||
'datas' => $object->getDatas(),
|
||||
'filename' => $object->getFilename(),
|
||||
'id' => $object->getId(),
|
||||
'iv' => $object->getIv(),
|
||||
'keyInfos' => $object->getKeyInfos(),
|
||||
'title' => $object->getTitle(),
|
||||
'type' => $object->getType(),
|
||||
'uuid' => $object->getUuid(),
|
||||
'status' => $object->getStatus(),
|
||||
'createdAt' => $this->normalizer->normalize($object->getCreatedAt(), $format, $context),
|
||||
'createdBy' => $this->normalizer->normalize($object->getCreatedBy(), $format, $context),
|
||||
];
|
||||
|
||||
// deprecated property
|
||||
$datas['creationDate'] = $datas['createdAt'];
|
||||
|
||||
$canDavSee = in_array(self::ADD_DAV_SEE_LINK_CONTEXT, $context['groups'] ?? []);
|
||||
$canDavEdit = in_array(self::ADD_DAV_EDIT_LINK_CONTEXT, $context['groups'] ?? []);
|
||||
|
||||
if ($canDavSee || $canDavEdit) {
|
||||
$accessToken = $this->JWTDavTokenProvider->createToken(
|
||||
$object,
|
||||
$canDavEdit ? StoredObjectRoleEnum::EDIT : StoredObjectRoleEnum::SEE
|
||||
);
|
||||
|
||||
$datas['_links'] = [
|
||||
'dav_link' => [
|
||||
'href' => $this->urlGenerator->generate(
|
||||
'chill_docstore_dav_document_get',
|
||||
[
|
||||
'uuid' => $object->getUuid(),
|
||||
'access_token' => $accessToken,
|
||||
],
|
||||
UrlGeneratorInterface::ABSOLUTE_URL,
|
||||
),
|
||||
'expiration' => $this->JWTDavTokenProvider->getTokenExpiration($accessToken)->format('U'),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
return $datas;
|
||||
}
|
||||
|
||||
public function supportsNormalization($data, ?string $format = null)
|
||||
{
|
||||
return $data instanceof StoredObject && 'json' === $format;
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Controller;
|
||||
|
||||
use Chill\DocStoreBundle\Serializer\Normalizer\StoredObjectNormalizer;
|
||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use Chill\MainBundle\Templating\Listing\FilterOrderHelper;
|
||||
use Chill\MainBundle\Templating\Listing\FilterOrderHelperFactoryInterface;
|
||||
@ -134,7 +135,7 @@ final class AccompanyingCourseWorkController extends AbstractController
|
||||
{
|
||||
$this->denyAccessUnlessGranted(AccompanyingPeriodWorkVoter::UPDATE, $work);
|
||||
|
||||
$json = $this->serializer->normalize($work, 'json', ['groups' => ['read']]);
|
||||
$json = $this->serializer->normalize($work, 'json', ['groups' => ['read', StoredObjectNormalizer::ADD_DAV_EDIT_LINK_CONTEXT]]);
|
||||
|
||||
return $this->render('@ChillPerson/AccompanyingCourseWork/edit.html.twig', [
|
||||
'accompanyingCourse' => $work->getAccompanyingPeriod(),
|
||||
|
@ -135,6 +135,8 @@
|
||||
:filename="d.title"
|
||||
:can-edit="true"
|
||||
:execute-before-leave="submitBeforeLeaveToEditor"
|
||||
:davLink="d.storedObject._links.dav_link.href"
|
||||
:davLinkExpiration="d.storedObject._links.dav_link.expiration"
|
||||
@on-stored-object-status-change="onStatusDocumentChanged"
|
||||
></document-action-buttons-group>
|
||||
</li>
|
||||
|
Loading…
x
Reference in New Issue
Block a user