cs: Fix code style (safe rules only).

This commit is contained in:
Pol Dellaiera
2021-11-23 14:06:38 +01:00
parent 149d7ce991
commit 8f96a1121d
1223 changed files with 65199 additions and 64625 deletions

View File

@@ -1,5 +1,12 @@
<?php
/**
* 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;
use Symfony\Component\HttpKernel\Bundle\Bundle;

View File

@@ -1,13 +1,18 @@
<?php
/**
* 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\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
/**
* Class AdminController
*
* @package Chill\DocStoreBundle\Controller
* Class AdminController.
*/
class AdminController extends AbstractController
{
@@ -18,7 +23,7 @@ class AdminController extends AbstractController
{
return $this->render('ChillDocStoreBundle:Admin:layout.html.twig');
}
/**
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
@@ -26,5 +31,4 @@ class AdminController extends AbstractController
{
return $this->redirectToRoute('chill_main_admin_central');
}
}
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* 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\Controller;
use Chill\DocStoreBundle\Entity\AccompanyingCourseDocument;
@@ -7,26 +14,23 @@ use Chill\DocStoreBundle\Form\AccompanyingCourseDocumentType;
use Chill\DocStoreBundle\Security\Authorization\AccompanyingCourseDocumentVoter;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Privacy\PrivacyEvent;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use DateTime;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* @Route("/{_locale}/parcours/{course}/document")
*/
class DocumentAccompanyingCourseController extends AbstractController
{
/**
*
* @var TranslatorInterface
* @var AuthorizationHelper
*/
protected $translator;
protected $authorizationHelper;
/**
* @var EventDispatcherInterface
@@ -34,16 +38,12 @@ class DocumentAccompanyingCourseController extends AbstractController
protected $eventDispatcher;
/**
* @var AuthorizationHelper
* @var TranslatorInterface
*/
protected $authorizationHelper;
protected $translator;
/**
* DocumentAccompanyingCourseController constructor.
* @param TranslatorInterface $translator
* @param EventDispatcherInterface $eventDispatcher
* @param AuthorizationHelper $authorizationHelper
*/
public function __construct(
TranslatorInterface $translator,
@@ -55,6 +55,66 @@ class DocumentAccompanyingCourseController extends AbstractController
$this->authorizationHelper = $authorizationHelper;
}
/**
* @Route("/{id}", name="accompanying_course_document_delete", methods="DELETE")
*/
public function delete(Request $request, AccompanyingPeriod $course, AccompanyingCourseDocument $document): Response
{
$this->denyAccessUnlessGranted(AccompanyingCourseDocumentVoter::DELETE, $document);
if ($this->isCsrfTokenValid('delete' . $document->getId(), $request->request->get('_token'))) {
$em = $this->getDoctrine()->getManager();
$em->remove($document);
$em->flush();
}
return $this->redirectToRoute(
'accompanying_course_document_index',
['accompanyingCourse' => $course->getId()]
);
}
/**
* @Route("/{id}/edit", name="accompanying_course_document_edit", methods="GET|POST")
*/
public function edit(Request $request, AccompanyingPeriod $course, AccompanyingCourseDocument $document): Response
{
$this->denyAccessUnlessGranted(AccompanyingCourseDocumentVoter::UPDATE, $document);
$document->setUser($this->getUser());
$document->setDate(new DateTime('Now'));
$form = $this->createForm(
AccompanyingCourseDocumentType::class,
$document
);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->getDoctrine()->getManager()->flush();
$this->addFlash('success', $this->translator->trans('The document is successfully updated'));
return $this->redirectToRoute(
'accompanying_course_document_edit',
['id' => $document->getId(), 'course' => $course->getId()]
);
}
if ($form->isSubmitted() and !$form->isValid()) {
$this->addFlash('error', $this->translator->trans('This form contains errors'));
}
return $this->render(
'ChillDocStoreBundle:AccompanyingCourseDocument:edit.html.twig',
[
'document' => $document,
'form' => $form->createView(),
'accompanyingCourse' => $course,
]
);
}
/**
* @Route("/", name="accompanying_course_document_index", methods="GET")
*/
@@ -62,14 +122,14 @@ class DocumentAccompanyingCourseController extends AbstractController
{
$em = $this->getDoctrine()->getManager();
if ($course === NULL) {
if (null === $course) {
throw $this->createNotFoundException('Accompanying period not found');
}
$this->denyAccessUnlessGranted(AccompanyingCourseDocumentVoter::SEE, $course);
$documents = $em
->getRepository("ChillDocStoreBundle:AccompanyingCourseDocument")
->getRepository('ChillDocStoreBundle:AccompanyingCourseDocument')
->findBy(
['course' => $course],
['date' => 'DESC']
@@ -79,8 +139,9 @@ class DocumentAccompanyingCourseController extends AbstractController
'ChillDocStoreBundle:AccompanyingCourseDocument:index.html.twig',
[
'documents' => $documents,
'accompanyingCourse' => $course
]);
'accompanyingCourse' => $course,
]
);
}
/**
@@ -88,14 +149,14 @@ class DocumentAccompanyingCourseController extends AbstractController
*/
public function new(Request $request, AccompanyingPeriod $course): Response
{
if ($course === NULL) {
if (null === $course) {
throw $this->createNotFoundException('Accompanying period not found');
}
$document = new AccompanyingCourseDocument();
$document->setUser($this->getUser());
$document->setCourse($course);
$document->setDate(new \DateTime('Now'));
$document->setDate(new DateTime('Now'));
$this->denyAccessUnlessGranted(AccompanyingCourseDocumentVoter::CREATE, $document);
@@ -104,18 +165,22 @@ class DocumentAccompanyingCourseController extends AbstractController
if ($form->isSubmitted() && $form->isValid()) {
$this->denyAccessUnlessGranted(
'CHILL_ACCOMPANYING_COURSE_DOCUMENT_CREATE', $document,
'creation of this activity not allowed');
'CHILL_ACCOMPANYING_COURSE_DOCUMENT_CREATE',
$document,
'creation of this activity not allowed'
);
$em = $this->getDoctrine()->getManager();
$em->persist($document);
$em->flush();
$this->addFlash('success', $this->translator->trans("The document is successfully registered"));
$this->addFlash('success', $this->translator->trans('The document is successfully registered'));
return $this->redirectToRoute('accompanying_course_document_index', ['course' => $course->getId()]);
} elseif ($form->isSubmitted() and !$form->isValid()) {
$this->addFlash('error', $this->translator->trans("This form contains errors"));
}
if ($form->isSubmitted() and !$form->isValid()) {
$this->addFlash('error', $this->translator->trans('This form contains errors'));
}
return $this->render('ChillDocStoreBundle:AccompanyingCourseDocument:new.html.twig', [
@@ -134,59 +199,7 @@ class DocumentAccompanyingCourseController extends AbstractController
return $this->render(
'ChillDocStoreBundle:AccompanyingCourseDocument:show.html.twig',
['document' => $document, 'accompanyingCourse' => $course]);
}
/**
* @Route("/{id}/edit", name="accompanying_course_document_edit", methods="GET|POST")
*/
public function edit(Request $request, AccompanyingPeriod $course, AccompanyingCourseDocument $document): Response
{
$this->denyAccessUnlessGranted(AccompanyingCourseDocumentVoter::UPDATE, $document);
$document->setUser($this->getUser());
$document->setDate(new \DateTime('Now'));
$form = $this->createForm(
AccompanyingCourseDocumentType::class, $document);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->getDoctrine()->getManager()->flush();
$this->addFlash('success', $this->translator->trans("The document is successfully updated"));
return $this->redirectToRoute(
'accompanying_course_document_edit',
['id' => $document->getId(), 'course' => $course->getId()]);
} elseif ($form->isSubmitted() and !$form->isValid()) {
$this->addFlash('error', $this->translator->trans("This form contains errors"));
}
return $this->render(
'ChillDocStoreBundle:AccompanyingCourseDocument:edit.html.twig',
[
'document' => $document,
'form' => $form->createView(),
'accompanyingCourse' => $course,
]);
}
/**
* @Route("/{id}", name="accompanying_course_document_delete", methods="DELETE")
*/
public function delete(Request $request, AccompanyingPeriod $course, AccompanyingCourseDocument $document): Response
{
$this->denyAccessUnlessGranted(AccompanyingCourseDocumentVoter::DELETE, $document);
if ($this->isCsrfTokenValid('delete'.$document->getId(), $request->request->get('_token'))) {
$em = $this->getDoctrine()->getManager();
$em->remove($document);
$em->flush();
}
return $this->redirectToRoute(
'accompanying_course_document_index', ['accompanyingCourse' => $course->getId()]);
['document' => $document, 'accompanyingCourse' => $course]
);
}
}

View File

@@ -1,9 +1,17 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\DocStoreBundle\Controller;
use Chill\DocStoreBundle\ChillDocStoreBundle;
use Chill\DocStoreBundle\Entity\DocumentCategory;
use Chill\DocStoreBundle\Entity\PersonDocument;
use Chill\DocStoreBundle\Form\DocumentCategoryType;
@@ -11,19 +19,73 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Chill\DocStoreBundle\ChillDocStoreBundle;
/**
* @Route("/{_locale}/admin/document/category")
*/
class DocumentCategoryController extends AbstractController
{
/**
* @Route("/{bundleId}/{idInsideBundle}", name="document_category_delete", methods="DELETE")
*
* @param mixed $bundleId
* @param mixed $idInsideBundle
*/
public function delete(Request $request, $bundleId, $idInsideBundle): Response
{
$em = $this->getDoctrine()->getManager();
$documentCategory = $em
->getRepository('ChillDocStoreBundle:DocumentCategory')
->findOneBy(
['bundleId' => $bundleId, 'idInsideBundle' => $idInsideBundle]
);
if ($this->isCsrfTokenValid('delete' . $bundleId . $idInsideBundle, $request->request->get('_token'))) {
$em->remove($documentCategory);
$em->flush();
}
return $this->redirectToRoute('document_category_index');
}
/**
* @Route("/{bundleId}/{idInsideBundle}/edit", name="document_category_edit", methods="GET|POST")
*
* @param mixed $bundleId
* @param mixed $idInsideBundle
*/
public function edit(Request $request, $bundleId, $idInsideBundle): Response
{
$em = $this->getDoctrine()->getManager();
$documentCategory = $em
->getRepository('ChillDocStoreBundle:DocumentCategory')
->findOneBy(
['bundleId' => $bundleId, 'idInsideBundle' => $idInsideBundle]
);
$form = $this->createForm(DocumentCategoryType::class, $documentCategory);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('document_category_index', [
'bundleId' => $documentCategory->getBundleId(),
'idInsideBundle' => $documentCategory->getIdInsideBundle(), ]);
}
return $this->render('ChillDocStoreBundle:DocumentCategory:edit.html.twig', [
'document_category' => $documentCategory,
'form' => $form->createView(),
]);
}
/**
* @Route("/", name="document_category_index", methods="GET")
*/
public function index(): Response
{
$em = $this->getDoctrine()->getManager();
$em = $this->getDoctrine()->getManager();
$categories = $em->getRepository(DocumentCategory::class)->findAll();
return $this->render(
@@ -68,64 +130,22 @@ class DocumentCategoryController extends AbstractController
/**
* @Route("/{bundleId}/{idInsideBundle}", name="document_category_show", methods="GET")
*
* @param mixed $bundleId
* @param mixed $idInsideBundle
*/
public function show($bundleId, $idInsideBundle): Response
{
$em = $this->getDoctrine()->getManager();
$documentCategory = $em
->getRepository("ChillDocStoreBundle:DocumentCategory")
->getRepository('ChillDocStoreBundle:DocumentCategory')
->findOneBy(
['bundleId' => $bundleId, 'idInsideBundle' => $idInsideBundle]);
['bundleId' => $bundleId, 'idInsideBundle' => $idInsideBundle]
);
return $this->render(
'ChillDocStoreBundle:DocumentCategory:show.html.twig',
['document_category' => $documentCategory]);
}
/**
* @Route("/{bundleId}/{idInsideBundle}/edit", name="document_category_edit", methods="GET|POST")
*/
public function edit(Request $request, $bundleId, $idInsideBundle): Response
{
$em = $this->getDoctrine()->getManager();
$documentCategory = $em
->getRepository("ChillDocStoreBundle:DocumentCategory")
->findOneBy(
['bundleId' => $bundleId, 'idInsideBundle' => $idInsideBundle]);
$form = $this->createForm(DocumentCategoryType::class, $documentCategory);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('document_category_index', [
'bundleId' => $documentCategory->getBundleId(),
'idInsideBundle' => $documentCategory->getIdInsideBundle(),]);
}
return $this->render('ChillDocStoreBundle:DocumentCategory:edit.html.twig', [
'document_category' => $documentCategory,
'form' => $form->createView(),
]);
}
/**
* @Route("/{bundleId}/{idInsideBundle}", name="document_category_delete", methods="DELETE")
*/
public function delete(Request $request, $bundleId, $idInsideBundle): Response
{
$em = $this->getDoctrine()->getManager();
$documentCategory = $em
->getRepository("ChillDocStoreBundle:DocumentCategory")
->findOneBy(
['bundleId' => $bundleId, 'idInsideBundle' => $idInsideBundle]);
if ($this->isCsrfTokenValid('delete'.$bundleId.$idInsideBundle, $request->request->get('_token'))) {
$em->remove($documentCategory);
$em->flush();
}
return $this->redirectToRoute('document_category_index');
['document_category' => $documentCategory]
);
}
}

View File

@@ -1,67 +1,147 @@
<?php
/**
* 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\Controller;
use Chill\DocStoreBundle\Entity\PersonDocument;
use Chill\DocStoreBundle\Form\PersonDocumentType;
use Chill\DocStoreBundle\Repository\DocumentRepository;
use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Privacy\PrivacyEvent;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use DateTime;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Chill\PersonBundle\Entity\Person;
use Symfony\Component\Security\Core\Role\Role;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter;
use Symfony\Component\Translation\TranslatorInterface;
/**
* Class DocumentPersonController
* Class DocumentPersonController.
*
* @package Chill\DocStoreBundle\Controller
* @Route("/{_locale}/person/{person}/document")
*
* TODO faire un controller abstrait ?
*/
class DocumentPersonController extends AbstractController
{
/**
*
* @var TranslatorInterface
*/
protected $translator;
/**
* @var EventDispatcherInterface
*/
protected $eventDispatcher;
/**
* @var AuthorizationHelper
*/
protected $authorizationHelper;
/**
* @var EventDispatcherInterface
*/
protected $eventDispatcher;
/**
* @var TranslatorInterface
*/
protected $translator;
/**
* DocumentPersonController constructor.
* @param TranslatorInterface $translator
* @param EventDispatcherInterface $eventDispatcher
* @param AuthorizationHelper $authorizationHelper
*/
public function __construct(
TranslatorInterface $translator,
EventDispatcherInterface $eventDispatcher,
TranslatorInterface $translator,
EventDispatcherInterface $eventDispatcher,
AuthorizationHelper $authorizationHelper
) {
$this->translator = $translator;
$this->eventDispatcher = $eventDispatcher;
$this->authorizationHelper = $authorizationHelper;
}
/**
* @Route("/{id}", name="person_document_delete", methods="DELETE")
*/
public function delete(Request $request, Person $person, PersonDocument $document): Response
{
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
$this->denyAccessUnlessGranted('CHILL_PERSON_DOCUMENT_DELETE', $document);
if ($this->isCsrfTokenValid('delete' . $document->getId(), $request->request->get('_token'))) {
$em = $this->getDoctrine()->getManager();
$em->remove($document);
$em->flush();
}
return $this->redirectToRoute(
'person_document_index',
['person' => $person->getId()]
);
}
/**
* @Route("/{id}/edit", name="person_document_edit", methods="GET|POST")
*/
public function edit(Request $request, Person $person, PersonDocument $document): Response
{
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
$this->denyAccessUnlessGranted('CHILL_PERSON_DOCUMENT_UPDATE', $document);
$document->setUser($this->getUser());
$document->setDate(new DateTime('Now'));
$form = $this->createForm(
PersonDocumentType::class,
$document,
[
'center' => $document->getCenter(),
'role' => new Role('CHILL_PERSON_DOCUMENT_UPDATE'),
]
);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->getDoctrine()->getManager()->flush();
$this->addFlash('success', $this->translator->trans('The document is successfully updated'));
$event = new PrivacyEvent($person, [
'element_class' => PersonDocument::class,
'element_id' => $document->getId(),
'action' => 'update',
]);
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
return $this->redirectToRoute(
'person_document_edit',
['id' => $document->getId(), 'person' => $person->getId()]
);
}
if ($form->isSubmitted() and !$form->isValid()) {
$this->addFlash('error', $this->translator->trans('This form contains errors'));
}
$event = new PrivacyEvent($person, [
'element_class' => PersonDocument::class,
'element_id' => $document->getId(),
'action' => 'edit',
]);
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
return $this->render(
'ChillDocStoreBundle:PersonDocument:edit.html.twig',
[
'document' => $document,
'form' => $form->createView(),
'person' => $person,
]
);
}
/**
* @Route("/", name="person_document_index", methods="GET")
*/
@@ -69,7 +149,7 @@ class DocumentPersonController extends AbstractController
{
$em = $this->getDoctrine()->getManager();
if ($person === NULL) {
if (null === $person) {
throw $this->createNotFoundException('Person not found');
}
@@ -77,28 +157,31 @@ class DocumentPersonController extends AbstractController
$reachableScopes = $this->authorizationHelper
->getReachableScopes(
$this->getUser(), new Role(PersonDocumentVoter::SEE),
$person->getCenter());
$documents = $em
->getRepository("ChillDocStoreBundle:PersonDocument")
->findBy(
array('person' => $person, 'scope' => $reachableScopes),
array('date' => 'DESC')
$this->getUser(),
new Role(PersonDocumentVoter::SEE),
$person->getCenter()
);
$event = new PrivacyEvent($person, array(
$documents = $em
->getRepository('ChillDocStoreBundle:PersonDocument')
->findBy(
['person' => $person, 'scope' => $reachableScopes],
['date' => 'DESC']
);
$event = new PrivacyEvent($person, [
'element_class' => PersonDocument::class,
'action' => 'index'
));
'action' => 'index',
]);
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
return $this->render(
'ChillDocStoreBundle:PersonDocument:index.html.twig',
[
'documents' => $documents,
'person' => $person
]);
'person' => $person,
]
);
}
/**
@@ -106,7 +189,7 @@ class DocumentPersonController extends AbstractController
*/
public function new(Request $request, Person $person): Response
{
if ($person === NULL) {
if (null === $person) {
throw $this->createNotFoundException('person not found');
}
@@ -115,28 +198,32 @@ class DocumentPersonController extends AbstractController
$document = new PersonDocument();
$document->setUser($this->getUser());
$document->setPerson($person);
$document->setDate(new \DateTime('Now'));
$document->setDate(new DateTime('Now'));
$form = $this->createForm(PersonDocumentType::class, $document, array(
$form = $this->createForm(PersonDocumentType::class, $document, [
'center' => $document->getCenter(),
'role' => new Role('CHILL_PERSON_DOCUMENT_CREATE')
));
'role' => new Role('CHILL_PERSON_DOCUMENT_CREATE'),
]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->denyAccessUnlessGranted(
'CHILL_PERSON_DOCUMENT_CREATE', $document,
'creation of this activity not allowed');
'CHILL_PERSON_DOCUMENT_CREATE',
$document,
'creation of this activity not allowed'
);
$em = $this->getDoctrine()->getManager();
$em->persist($document);
$em->flush();
$this->addFlash('success', $this->translator->trans("The document is successfully registered"));
$this->addFlash('success', $this->translator->trans('The document is successfully registered'));
return $this->redirectToRoute('person_document_index', ['person' => $person->getId()]);
} elseif ($form->isSubmitted() and !$form->isValid()) {
$this->addFlash('error', $this->translator->trans("This form contains errors"));
}
if ($form->isSubmitted() and !$form->isValid()) {
$this->addFlash('error', $this->translator->trans('This form contains errors'));
}
return $this->render('ChillDocStoreBundle:PersonDocument:new.html.twig', [
@@ -153,88 +240,17 @@ class DocumentPersonController extends AbstractController
{
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
$this->denyAccessUnlessGranted('CHILL_PERSON_DOCUMENT_SEE', $document);
$event = new PrivacyEvent($person, array(
$event = new PrivacyEvent($person, [
'element_class' => PersonDocument::class,
'element_id' => $document->getId(),
'action' => 'show'
));
'action' => 'show',
]);
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
return $this->render(
'ChillDocStoreBundle:PersonDocument:show.html.twig',
['document' => $document, 'person' => $person]);
}
/**
* @Route("/{id}/edit", name="person_document_edit", methods="GET|POST")
*/
public function edit(Request $request, Person $person, PersonDocument $document): Response
{
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
$this->denyAccessUnlessGranted('CHILL_PERSON_DOCUMENT_UPDATE', $document);
$document->setUser($this->getUser());
$document->setDate(new \DateTime('Now'));
$form = $this->createForm(
PersonDocumentType::class, $document, array(
'center' => $document->getCenter(),
'role' => new Role('CHILL_PERSON_DOCUMENT_UPDATE'),
));
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->getDoctrine()->getManager()->flush();
$this->addFlash('success', $this->translator->trans("The document is successfully updated"));
$event = new PrivacyEvent($person, array(
'element_class' => PersonDocument::class,
'element_id' => $document->getId(),
'action' => 'update'
));
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
return $this->redirectToRoute(
'person_document_edit',
['id' => $document->getId(), 'person' => $person->getId()]);
} elseif ($form->isSubmitted() and !$form->isValid()) {
$this->addFlash('error', $this->translator->trans("This form contains errors"));
}
$event = new PrivacyEvent($person, array(
'element_class' => PersonDocument::class,
'element_id' => $document->getId(),
'action' => 'edit'
));
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
return $this->render(
'ChillDocStoreBundle:PersonDocument:edit.html.twig',
[
'document' => $document,
'form' => $form->createView(),
'person' => $person,
]);
}
/**
* @Route("/{id}", name="person_document_delete", methods="DELETE")
*/
public function delete(Request $request, Person $person, PersonDocument $document): Response
{
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
$this->denyAccessUnlessGranted('CHILL_PERSON_DOCUMENT_DELETE', $document);
if ($this->isCsrfTokenValid('delete'.$document->getId(), $request->request->get('_token'))) {
$em = $this->getDoctrine()->getManager();
$em->remove($document);
$em->flush();
}
return $this->redirectToRoute(
'person_document_index', ['person' => $person->getId()]);
['document' => $document, 'person' => $person]
);
}
}

View File

@@ -1,35 +1,24 @@
<?php
/*
* Copyright (C) 2018 Champs Libres Cooperative <info@champs-libres.coop>
/**
* Chill is a software for social workers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\DocStoreBundle\DataFixtures\ORM;
use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter;
use Chill\MainBundle\DataFixtures\ORM\LoadPermissionsGroup;
use Chill\MainBundle\DataFixtures\ORM\LoadScopes;
use Chill\MainBundle\Entity\RoleScope;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Chill\MainBundle\DataFixtures\ORM\LoadPermissionsGroup;
use Chill\MainBundle\Entity\RoleScope;
use Chill\MainBundle\DataFixtures\ORM\LoadScopes;
use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter;
/**
* Adding acl for person document
*
* Adding acl for person document.
*/
class LoadDocumentACL extends AbstractFixture implements OrderedFixtureInterface
{
@@ -38,13 +27,13 @@ class LoadDocumentACL extends AbstractFixture implements OrderedFixtureInterface
return 35000;
}
public function load(ObjectManager $manager)
{
foreach (LoadPermissionsGroup::$refs as $permissionsGroupRef) {
$permissionsGroup = $this->getReference($permissionsGroupRef);
printf("processing permission group %s \n", $permissionsGroup->getName());
foreach (LoadScopes::$references as $scopeRef){
foreach (LoadScopes::$references as $scopeRef) {
$scope = $this->getReference($scopeRef);
printf("processing scope %s \n", $scope->getName()['en']);
//create permission group
@@ -52,41 +41,47 @@ class LoadDocumentACL extends AbstractFixture implements OrderedFixtureInterface
case 'social':
if ($scope->getName()['en'] === 'administrative') {
printf("denying power on administrative \n");
break 2; // we do not want any power on administrative
}
break;
case 'administrative':
case 'direction':
if (in_array($scope->getName()['en'], array('administrative', 'social'), true)) {
if (in_array($scope->getName()['en'], ['administrative', 'social'], true)) {
printf("denying power on %s\n", $scope->getName()['en']);
break 2; // we do not want any power on social or administrative
}
break;
}
printf("Adding Person report acl to %s "
printf(
'Adding Person report acl to %s '
. "permission group, scope '%s' \n",
$permissionsGroup->getName(), $scope->getName()['en']);
$permissionsGroup->getName(),
$scope->getName()['en']
);
$roleScopeUpdate = (new RoleScope())
->setRole(PersonDocumentVoter::CREATE)
->setScope($scope);
->setRole(PersonDocumentVoter::CREATE)
->setScope($scope);
$permissionsGroup->addRoleScope($roleScopeUpdate);
$roleScopeCreate = (new RoleScope())
->setRole(PersonDocumentVoter::UPDATE)
->setScope($scope);
->setRole(PersonDocumentVoter::UPDATE)
->setScope($scope);
$permissionsGroup->addRoleScope($roleScopeCreate);
$roleScopeDelete = (new RoleScope())
->setRole(PersonDocumentVoter::DELETE)
->setScope($scope);
->setRole(PersonDocumentVoter::DELETE)
->setScope($scope);
$permissionsGroup->addRoleScope($roleScopeDelete);
$manager->persist($roleScopeUpdate);
$manager->persist($roleScopeCreate);
$manager->persist($roleScopeDelete);
}
}
$manager->flush();
}
}

View File

@@ -1,60 +1,46 @@
<?php
/*
* Copyright (C) 2018 Champs Libres Cooperative <info@champs-libres.coop>
/**
* Chill is a software for social workers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\DocStoreBundle\DataFixtures\ORM;
use Chill\DocStoreBundle\Entity\DocumentCategory;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Chill\DocStoreBundle\Entity\DocumentCategory;
/**
*
*
*/
class LoadDocumentCategory extends AbstractFixture implements OrderedFixtureInterface
{
public function getOrder()
{
return 35010;
}
public function load(ObjectManager $manager)
{
$category = (new DocumentCategory('chill-doc-store', 10))
->setDocumentClass(\Chill\DocStoreBundle\Entity\PersonDocument::class)
->setName([
'fr' => "Document d'identité",
'en' => "Identity"
])
;
'en' => 'Identity',
]);
$manager->persist($category);
$category = (new DocumentCategory('chill-doc-store', 20))
->setDocumentClass(\Chill\DocStoreBundle\Entity\PersonDocument::class)
->setName([
'fr' => "Courrier reçu",
'en' => "Received email"
])
;
'fr' => 'Courrier reçu',
'en' => 'Received email',
]);
$manager->persist($category);
$manager->flush();
}
}

View File

@@ -1,31 +1,35 @@
<?php
/**
* 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\DependencyInjection;
use Chill\DocStoreBundle\Security\Authorization\AccompanyingCourseDocumentVoter;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
/**
* This is the class that loads and manages your bundle configuration
* This is the class that loads and manages your bundle configuration.
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class ChillDocStoreExtension extends Extension implements PrependExtensionInterface
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../config'));
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../config'));
$loader->load('services.yaml');
$loader->load('services/media.yaml');
$loader->load('services/controller.yaml');
@@ -41,40 +45,40 @@ class ChillDocStoreExtension extends Extension implements PrependExtensionInterf
$this->prependTwig($container);
}
protected function prependAuthorization(ContainerBuilder $container)
{
$container->prependExtensionConfig('security', [
'role_hierarchy' => [
PersonDocumentVoter::UPDATE => [PersonDocumentVoter::SEE_DETAILS],
PersonDocumentVoter::CREATE => [PersonDocumentVoter::SEE_DETAILS],
PersonDocumentVoter::DELETE => [PersonDocumentVoter::SEE_DETAILS],
PersonDocumentVoter::SEE_DETAILS => [PersonDocumentVoter::SEE],
AccompanyingCourseDocumentVoter::UPDATE => [AccompanyingCourseDocumentVoter::SEE_DETAILS],
AccompanyingCourseDocumentVoter::CREATE => [AccompanyingCourseDocumentVoter::SEE_DETAILS],
AccompanyingCourseDocumentVoter::DELETE => [AccompanyingCourseDocumentVoter::SEE_DETAILS],
AccompanyingCourseDocumentVoter::SEE_DETAILS => [AccompanyingCourseDocumentVoter::SEE],
],
]);
}
protected function prependRoute(ContainerBuilder $container)
{
//declare routes for task bundle
$container->prependExtensionConfig('chill_main', array(
'routing' => array(
'resources' => array(
'@ChillDocStoreBundle/config/routes.yaml',
'@ChampsLibresAsyncUploaderBundle/config/routes.yaml'
)
)
));
}
protected function prependAuthorization(ContainerBuilder $container)
{
$container->prependExtensionConfig('security', array(
'role_hierarchy' => array(
PersonDocumentVoter::UPDATE => [PersonDocumentVoter::SEE_DETAILS],
PersonDocumentVoter::CREATE => [PersonDocumentVoter::SEE_DETAILS],
PersonDocumentVoter::DELETE => [PersonDocumentVoter::SEE_DETAILS],
PersonDocumentVoter::SEE_DETAILS => [PersonDocumentVoter::SEE],
AccompanyingCourseDocumentVoter::UPDATE => [AccompanyingCourseDocumentVoter::SEE_DETAILS],
AccompanyingCourseDocumentVoter::CREATE => [AccompanyingCourseDocumentVoter::SEE_DETAILS],
AccompanyingCourseDocumentVoter::DELETE => [AccompanyingCourseDocumentVoter::SEE_DETAILS],
AccompanyingCourseDocumentVoter::SEE_DETAILS => [AccompanyingCourseDocumentVoter::SEE],
)
));
$container->prependExtensionConfig('chill_main', [
'routing' => [
'resources' => [
'@ChillDocStoreBundle/config/routes.yaml',
'@ChampsLibresAsyncUploaderBundle/config/routes.yaml',
],
],
]);
}
protected function prependTwig(ContainerBuilder $container)
{
$twigConfig = array(
'form_themes' => array('@ChillDocStore/Form/fields.html.twig')
);
$twigConfig = [
'form_themes' => ['@ChillDocStore/Form/fields.html.twig'],
];
$container->prependExtensionConfig('twig', $twigConfig);
}
}

View File

@@ -1,20 +1,24 @@
<?php
/**
* 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\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
/**
* This is the class that validates and merges configuration from your app/config files
* This is the class that validates and merges configuration from your app/config files.
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('chill_doc_store');

View File

@@ -1,13 +1,19 @@
<?php
/**
* 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\Entity;
use Chill\DocStoreBundle\Entity\Document;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity()
* @ORM\Entity
* @ORM\Table("chill_doc.accompanyingcourse_document")
*/
class AccompanyingCourseDocument extends Document

View File

@@ -1,33 +1,38 @@
<?php
/**
* 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\Entity;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Chill\MainBundle\Entity\HasScopeInterface;
use Chill\MainBundle\Entity\User;
use ChampsLibres\AsyncUploaderBundle\Validator\Constraints\AsyncFileExists;
use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\MappedSuperclass()
* @ORM\MappedSuperclass
*/
class Document implements HasScopeInterface
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
* @ORM\ManyToOne(targetEntity="Chill\DocStoreBundle\Entity\DocumentCategory")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="category_bundle_id", referencedColumnName="bundle_id"),
* @ORM\JoinColumn(name="category_id_inside_bundle", referencedColumnName="id_inside_bundle")
* })
*/
private $id;
private $category;
/**
* @ORM\Column(type="text")
* @Assert\Length(
* min=2, max=250
* )
* @ORM\Column(type="datetime")
*/
private $title;
private $date;
/**
* @ORM\Column(type="text")
@@ -35,72 +40,46 @@ class Document implements HasScopeInterface
private $description = '';
/**
* @ORM\ManyToOne(targetEntity="Chill\DocStoreBundle\Entity\DocumentCategory")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="category_bundle_id", referencedColumnName="bundle_id"),
* @ORM\JoinColumn(name="category_id_inside_bundle", referencedColumnName="id_inside_bundle")
* })
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $category;
private $id;
/**
* @ORM\ManyToOne(
* targetEntity="Chill\DocStoreBundle\Entity\StoredObject",
* cascade={"persist"}
* targetEntity="Chill\DocStoreBundle\Entity\StoredObject",
* cascade={"persist"}
* )
* @Assert\Valid()
* @Assert\Valid
* @Assert\NotNull(
* message="Upload a document"
* message="Upload a document"
* )
*/
private $object;
/**
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Scope")
*
* @var \Chill\MainBundle\Entity\Scope The document's center
*/
private $scope;
/**
* @ORM\Column(type="text")
* @Assert\Length(
* min=2, max=250
* )
*/
private $title;
/**
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User")
*
* @var \Chill\PersonBundle\Entity\user The user who encoded the exif_read_data
*/
private $user;
/**
* @ORM\Column(type="datetime")
*/
private $date;
public function getId()
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription($description): self
{
$this->description = (string) $description;
return $this;
}
/**
* @return DocumentCategory
*/
@@ -109,6 +88,46 @@ class Document implements HasScopeInterface
return $this->category;
}
public function getDate(): ?DateTimeInterface
{
return $this->date;
}
public function getDescription(): ?string
{
return $this->description;
}
public function getId()
{
return $this->id;
}
public function getObject(): ?StoredObject
{
return $this->object;
}
/**
* Get scope.
*
* @return \Chill\MainBundle\Entity\Scope
*/
public function getScope()
{
return $this->scope;
}
public function getTitle(): ?string
{
return $this->title;
}
public function getUser()
{
return $this->user;
}
public function setCategory(DocumentCategory $category): self
{
$this->category = $category;
@@ -116,14 +135,25 @@ class Document implements HasScopeInterface
return $this;
}
/**
* Get scope
*
* @return \Chill\MainBundle\Entity\Scope
*/
public function getScope()
public function setDate(DateTimeInterface $date): self
{
return $this->scope;
$this->date = $date;
return $this;
}
public function setDescription($description): self
{
$this->description = (string) $description;
return $this;
}
public function setObject(?StoredObject $object = null)
{
$this->object = $object;
return $this;
}
public function setScope($scope): self
@@ -133,9 +163,11 @@ class Document implements HasScopeInterface
return $this;
}
public function getUser()
public function setTitle(string $title): self
{
return $this->user;
$this->title = $title;
return $this;
}
public function setUser($user): self
@@ -144,28 +176,4 @@ class Document implements HasScopeInterface
return $this;
}
public function getDate(): ?\DateTimeInterface
{
return $this->date;
}
public function setDate(\DateTimeInterface $date): self
{
$this->date = $date;
return $this;
}
public function getObject(): ?StoredObject
{
return $this->object;
}
public function setObject(StoredObject $object = null)
{
$this->object = $object;
return $this;
}
}

View File

@@ -1,9 +1,14 @@
<?php
/**
* 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\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
@@ -13,25 +18,27 @@ use Doctrine\ORM\Mapping as ORM;
class DocumentCategory
{
/**
* @ORM\Id()
* @ORM\Id
* @ORM\Column(type="string", name="bundle_id")
*
* @var string The id of the bundle that has create the category (i.e. 'person', 'activity', ....)
*/
private $bundleId;
/**
* @ORM\Id()
* @ORM\Column(type="integer", name="id_inside_bundle")
* @var int The id which is unique inside the bundle
*/
private $idInsideBundle;
/**
* @ORM\Column(type="string", name="document_class")
*
* @var string The class of the document (ie Chill\DocStoreBundle\PersonDocument)
*/
private $documentClass;
/**
* @ORM\Id
* @ORM\Column(type="integer", name="id_inside_bundle")
*
* @var int The id which is unique inside the bundle
*/
private $idInsideBundle;
/**
* @ORM\Column(type="json")
@@ -44,19 +51,38 @@ class DocumentCategory
$this->idInsideBundle = $idInsideBundle;
}
public function getBundleId() // ::class BundleClass (FQDN)
public function getBundleId() // ::class BundleClass (FQDN)
{
return $this->bundleId;
}
public function getDocumentClass()
{
return $this->documentClass;
}
public function getIdInsideBundle()
{
return $this->idInsideBundle;
}
public function getDocumentClass()
public function getName($locale = null)
{
return $this->documentClass;
if ($locale) {
if (isset($this->name[$locale])) {
return $this->name[$locale];
}
foreach ($this->name as $name) {
if (!empty($name)) {
return $name;
}
}
return '';
}
return $this->name;
}
public function setDocumentClass($documentClass): self
@@ -66,24 +92,6 @@ class DocumentCategory
return $this;
}
public function getName($locale = null)
{
if ($locale) {
if (isset($this->name[$locale])) {
return $this->name[$locale];
} else {
foreach ($this->name as $name) {
if (!empty($name)) {
return $name;
}
}
}
return '';
} else {
return $this->name;
}
}
public function setName($name): self
{
$this->name = $name;

View File

@@ -1,29 +1,39 @@
<?php
/**
* 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\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Chill\MainBundle\Entity\HasCenterInterface;
use Chill\MainBundle\Entity\HasScopeInterface;
use Chill\PersonBundle\Entity\Person;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table("chill_doc.person_document")
* @ORM\Entity()
* @ORM\Entity
*/
class PersonDocument extends Document implements HasCenterInterface, HasScopeInterface
{
/**
* @ORM\ManyToOne(targetEntity="Chill\PersonBundle\Entity\Person")
*
* @var Person
*/
private $person;
public function getCenter()
{
return $this->getPerson()->getCenter();
}
/**
* Get person
* Get person.
*
* @return \Chill\MainBundle\Entity\Person
*/
@@ -38,9 +48,4 @@ class PersonDocument extends Document implements HasCenterInterface, HasScopeInt
return $this;
}
public function getCenter()
{
return $this->getPerson()->getCenter();
}
}

View File

@@ -1,36 +1,48 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\DocStoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use ChampsLibres\AsyncUploaderBundle\Model\AsyncFileInterface;
use ChampsLibres\AsyncUploaderBundle\Validator\Constraints\AsyncFileExists;
use ChampsLibres\WopiLib\Contract\Entity\Document;
use DateTime;
use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
use Symfony\Component\Serializer\Annotation as Serializer;
/**
* Represent a document stored in an object store
* Represent a document stored in an object store.
*
* @ORM\Entity()
* @ORM\Entity
* @ORM\Table("chill_doc.stored_object")
* @AsyncFileExists(
* message="The file is not stored properly"
* message="The file is not stored properly"
* )
*/
class StoredObject implements AsyncFileInterface, Document
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
* @ORM\Column(type="datetime", name="creation_date")
* @Serializer\Groups({"read"})
*/
private $id;
private DateTimeInterface $creationDate;
/**
* @ORM\Column(type="json", name="datas")
* @Serializer\Groups({"read"})
*/
private array $datas = [];
/**
* @ORM\Column(type="text")
@@ -39,28 +51,23 @@ class StoredObject implements AsyncFileInterface, Document
private $filename;
/**
* @ORM\Column(type="json", name="key")
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Serializer\Groups({"read"})
*/
private array $keyInfos = [];
private $id;
/**
*
* @var int[]
* @ORM\Column(type="json", name="iv")
*/
private array $iv = [];
/**
* @ORM\Column(type="uuid", unique=true)
* @Serializer\Groups({"read"})
* @ORM\Column(type="json", name="key")
*/
private UuidInterface $uuid;
/**
* @ORM\Column(type="datetime", name="creation_date")
* @Serializer\Groups({"read"})
*/
private DateTimeInterface $creationDate;
private array $keyInfos = [];
/**
* @ORM\Column(type="text", name="type")
@@ -69,68 +76,45 @@ class StoredObject implements AsyncFileInterface, Document
private string $type = '';
/**
* @ORM\Column(type="json", name="datas")
* @ORM\Column(type="uuid", unique=true)
* @Serializer\Groups({"read"})
*/
private array $datas = [];
private UuidInterface $uuid;
public function __construct()
{
$this->creationDate = new \DateTime();
$this->creationDate = new DateTime();
$this->uuid = Uuid::uuid4();
}
public function getId()
{
return $this->id;
}
public function getFilename()
{
return $this->filename;
}
public function getCreationDate(): \DateTime
public function getCreationDate(): DateTime
{
return $this->creationDate;
}
public function getType()
{
return $this->type;
}
public function getDatas()
{
return $this->datas;
}
public function setFilename($filename)
public function getFilename()
{
$this->filename = $filename;
return $this;
return $this->filename;
}
public function setCreationDate(\DateTime $creationDate)
public function getId()
{
$this->creationDate = $creationDate;
return $this;
return $this->id;
}
public function setType($type)
public function getIv()
{
$this->type = $type;
return $this;
return $this->iv;
}
public function setDatas(array $datas)
public function getKeyInfos()
{
$this->datas = $datas;
return $this;
return $this->keyInfos;
}
/**
@@ -141,28 +125,9 @@ class StoredObject implements AsyncFileInterface, Document
return $this->getFilename();
}
public function getKeyInfos()
public function getType()
{
return $this->keyInfos;
}
public function getIv()
{
return $this->iv;
}
public function setKeyInfos($keyInfos)
{
$this->keyInfos = $keyInfos;
return $this;
}
public function setIv($iv)
{
$this->iv = $iv;
return $this;
return $this->type;
}
public function getUuid(): UuidInterface
@@ -174,4 +139,46 @@ class StoredObject implements AsyncFileInterface, Document
{
return (string) $this->uuid;
}
public function setCreationDate(DateTime $creationDate)
{
$this->creationDate = $creationDate;
return $this;
}
public function setDatas(array $datas)
{
$this->datas = $datas;
return $this;
}
public function setFilename($filename)
{
$this->filename = $filename;
return $this;
}
public function setIv($iv)
{
$this->iv = $iv;
return $this;
}
public function setKeyInfos($keyInfos)
{
$this->keyInfos = $keyInfos;
return $this;
}
public function setType($type)
{
$this->type = $type;
return $this;
}
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\DocStoreBundle\EntityRepository;
@@ -36,7 +43,7 @@ class AccompanyingCourseDocumentRepository extends ServiceEntityRepository
->getResult()
;
}
*/
*/
/*
public function findOneBySomeField($value): ?AccompanyingCourseDocument
@@ -48,5 +55,5 @@ class AccompanyingCourseDocumentRepository extends ServiceEntityRepository
->getOneOrNullResult()
;
}
*/
*/
}

View File

@@ -1,29 +1,18 @@
<?php
/*
* Copyright (C) 2018 Champs-Libres <info@champs-libres.coop>
/**
* Chill is a software for social workers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\DocStoreBundle\EntityRepository;
use Doctrine\ORM\EntityRepository;
use Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice\Option;
/**
* Get an available idInsideBUndle
* Get an available idInsideBUndle.
*/
class DocumentCategoryRepository extends EntityRepository
{
@@ -31,7 +20,8 @@ class DocumentCategoryRepository extends EntityRepository
{
$array_res = $this->getEntityManager()
->createQuery(
'SELECT MAX(c.idInsideBundle) + 1 FROM ChillDocStoreBundle:DocumentCategory c')
'SELECT MAX(c.idInsideBundle) + 1 FROM ChillDocStoreBundle:DocumentCategory c'
)
->getSingleResult();
return reset($array_res);

View File

@@ -1,73 +1,72 @@
<?php
namespace Chill\DocStoreBundle\Form;
/**
* 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\Form;
use Chill\DocStoreBundle\Entity\Document;
use Chill\DocStoreBundle\Entity\PersonDocument;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\MainBundle\Form\Type\ChillTextareaType;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Doctrine\ORM\EntityRepository;
use Doctrine\Persistence\ObjectManager;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Doctrine\ORM\EntityRepository;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Doctrine\Persistence\ObjectManager;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\MainBundle\Form\Type\ScopePickerType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Chill\MainBundle\Form\Type\ChillTextareaType;
class AccompanyingCourseDocumentType extends AbstractType
{
/**
* the user running this form
*
* @var User
*/
protected $user;
/**
*
* @var AuthorizationHelper
*/
protected $authorizationHelper;
/**
*
* @var ObjectManager
*/
protected $om;
/**
*
* @var TranslatableStringHelper
*/
protected $translatableStringHelper;
/**
* the user running this form.
*
* @var User
*/
protected $user;
public function __construct(
TranslatableStringHelper $translatableStringHelper
)
{
) {
$this->translatableStringHelper = $translatableStringHelper;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('title', TextType::class)
->add('description', ChillTextareaType::class, [
'required' => false
'required' => false,
])
->add('object', StoredObjectType::class, [
'error_bubbling' => true
'error_bubbling' => true,
])
->add('date', ChillDateType::class)
//TODO : adapt to using AccompanyingCourseDocument categories. Currently there are none...
->add('category', EntityType::class, array(
->add('category', EntityType::class, [
'placeholder' => 'Choose a document category',
'class' => 'ChillDocStoreBundle:DocumentCategory',
'query_builder' => function (EntityRepository $er) {
@@ -78,9 +77,7 @@ class AccompanyingCourseDocumentType extends AbstractType
'choice_label' => function ($entity = null) {
return $entity ? $this->translatableStringHelper->localize($entity->getName()) : '';
},
))
;
]);
}
public function configureOptions(OptionsResolver $resolver)
@@ -88,7 +85,7 @@ class AccompanyingCourseDocumentType extends AbstractType
$resolver->setDefaults([
'data_class' => Document::class,
]);
// $resolver->setRequired(['role', 'center'])
// ->setAllowedTypes('role', [ \Symfony\Component\Security\Core\Role\Role::class ])
// ->setAllowedTypes('center', [ \Chill\MainBundle\Entity\Center::class ])

View File

@@ -1,13 +1,20 @@
<?php
/**
* 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\Form;
use Chill\DocStoreBundle\Entity\DocumentCategory;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class DocumentCategoryType extends AbstractType
{
@@ -17,28 +24,26 @@ class DocumentCategoryType extends AbstractType
{
// TODO faire un service dans CHillMain
foreach ($kernelBundles as $key => $value) {
if(substr($key, 0, 5) === 'Chill') {
if (substr($key, 0, 5) === 'Chill') {
$this->chillBundlesFlipped[$value] = $key;
}
}
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('bundleId', ChoiceType::class, array(
->add('bundleId', ChoiceType::class, [
'choices' => $this->chillBundlesFlipped,
'disabled' => true,
))
->add('idInsideBundle', null, array(
])
->add('idInsideBundle', null, [
'disabled' => true,
))
->add('documentClass', null, array(
])
->add('documentClass', null, [
'disabled' => true,
)) // cahcerh par default PersonDocument
->add('name', TranslatableStringFormType::class)
;
]) // cahcerh par default PersonDocument
->add('name', TranslatableStringFormType::class);
}
public function configureOptions(OptionsResolver $resolver)

View File

@@ -1,76 +1,76 @@
<?php
namespace Chill\DocStoreBundle\Form;
/**
* 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\Form;
use Chill\DocStoreBundle\Entity\Document;
use Chill\DocStoreBundle\Entity\PersonDocument;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\MainBundle\Form\Type\ChillTextareaType;
use Chill\MainBundle\Form\Type\ScopePickerType;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Doctrine\ORM\EntityRepository;
use Doctrine\Persistence\ObjectManager;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Doctrine\ORM\EntityRepository;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Doctrine\Persistence\ObjectManager;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\MainBundle\Form\Type\ScopePickerType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Chill\MainBundle\Form\Type\ChillTextareaType;
class PersonDocumentType extends AbstractType
{
/**
* the user running this form
*
* @var User
*/
protected $user;
/**
*
* @var AuthorizationHelper
*/
protected $authorizationHelper;
/**
*
* @var ObjectManager
*/
protected $om;
/**
*
* @var TranslatableStringHelper
*/
protected $translatableStringHelper;
/**
* the user running this form.
*
* @var User
*/
protected $user;
public function __construct(
TranslatableStringHelper $translatableStringHelper
)
{
) {
$this->translatableStringHelper = $translatableStringHelper;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('title', TextType::class)
->add('description', ChillTextareaType::class, [
'required' => false
'required' => false,
])
->add('object', StoredObjectType::class, [
'error_bubbling' => true
'error_bubbling' => true,
])
->add('scope', ScopePickerType::class, [
'center' => $options['center'],
'role' => $options['role']
'role' => $options['role'],
])
->add('date', ChillDateType::class)
->add('category', EntityType::class, array(
->add('category', EntityType::class, [
'placeholder' => 'Choose a document category',
'class' => 'ChillDocStoreBundle:DocumentCategory',
'query_builder' => function (EntityRepository $er) {
@@ -81,9 +81,7 @@ class PersonDocumentType extends AbstractType
'choice_label' => function ($entity = null) {
return $entity ? $this->translatableStringHelper->localize($entity->getName()) : '';
},
))
;
]);
}
public function configureOptions(OptionsResolver $resolver)
@@ -91,10 +89,9 @@ class PersonDocumentType extends AbstractType
$resolver->setDefaults([
'data_class' => Document::class,
]);
$resolver->setRequired(['role', 'center'])
->setAllowedTypes('role', [ \Symfony\Component\Security\Core\Role\Role::class ])
->setAllowedTypes('center', [ \Chill\MainBundle\Entity\Center::class ])
;
->setAllowedTypes('role', [\Symfony\Component\Security\Core\Role\Role::class])
->setAllowedTypes('center', [\Chill\MainBundle\Entity\Center::class]);
}
}

View File

@@ -1,108 +1,115 @@
<?php
/*
*/
namespace Chill\DocStoreBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use ChampsLibres\AsyncUploaderBundle\Form\Type\AsyncUploaderType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Chill\DocStoreBundle\Entity\StoredObject;
use Symfony\Component\Form\CallbackTransformer;
use Doctrine\ORM\EntityManagerInterface;
/**
* Form type which allow to join a document
* 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\Form;
use ChampsLibres\AsyncUploaderBundle\Form\Type\AsyncUploaderType;
use Chill\DocStoreBundle\Entity\StoredObject;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\CallbackTransformer;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use function json_decode;
use function json_encode;
/**
* Form type which allow to join a document.
*/
class StoredObjectType extends AbstractType
{
/**
*
* @var EntityManagerInterface
*/
protected $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('filename', AsyncUploaderType::class)
->add('type', HiddenType::class)
->add('keyInfos', HiddenType::class)
->add('iv', HiddenType::class)
;
->add('iv', HiddenType::class);
$builder
->get('keyInfos')
->addModelTransformer(new CallbackTransformer(
[$this, 'transform'], [$this, 'reverseTransform']
));
[$this, 'transform'],
[$this, 'reverseTransform']
));
$builder
->get('iv')
->addModelTransformer(new CallbackTransformer(
[$this, 'transform'], [$this, 'reverseTransform']
));
[$this, 'transform'],
[$this, 'reverseTransform']
));
$builder
->addModelTransformer(new CallbackTransformer(
[ $this, 'transformObject'], [$this, 'reverseTransformObject']
));
[$this, 'transformObject'],
[$this, 'reverseTransformObject']
));
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefault('data_class', StoredObject::class);
}
public function getBlockPrefix()
{
return 'stored_object';
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefault('data_class', StoredObject::class)
;
}
public function reverseTransform($value)
{
if ($value === null) {
if (null === $value) {
return null;
}
return \json_decode($value, true);
return json_decode($value, true);
}
public function reverseTransformObject($object)
{
if (null === $object) {
return null;
}
if (null === $object->getFilename()) {
// remove the original object
$this->em->remove($object);
return null;
}
return $object;
}
public function transform($object)
{
if ($object === null) {
if (null === $object) {
return null;
}
return \json_encode($object);
return json_encode($object);
}
public function transformObject($object = null)
{
return $object;
}
public function reverseTransformObject($object)
{
if (NULL === $object) {
return null;
}
if (NULL === $object->getFilename()) {
// remove the original object
$this->em->remove($object);
return null;
}
return $object;
}
}

View File

@@ -1,19 +1,27 @@
<?php
/*
/**
* 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\Menu;
use Chill\DocStoreBundle\Security\Authorization\AccompanyingCourseDocumentVoter;
use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter;
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
use Knp\Menu\MenuItem;
use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter;
use LogicException;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
final class MenuBuilder implements LocalMenuBuilderInterface
{
private Security $security;
protected TranslatorInterface $translator;
private TranslatorInterface $translator;
public function __construct(
Security $security,
@@ -23,57 +31,61 @@ final class MenuBuilder implements LocalMenuBuilderInterface
$this->translator = $translator;
}
public function buildMenu($menuId, MenuItem $menu, array $parameters)
{
switch($menuId) {
switch ($menuId) {
case 'accompanyingCourse':
$this->buildMenuAccompanyingCourse($menu, $parameters);
break;
case 'person':
$this->buildMenuPerson($menu, $parameters);
break;
default:
throw new \LogicException("this menuid $menuId is not implemented");
throw new LogicException("this menuid {$menuId} is not implemented");
}
}
protected function buildMenuPerson(MenuItem $menu, array $parameters)
public static function getMenuIds(): array
{
/* @var $person \Chill\PersonBundle\Entity\Person */
$person = $parameters['person'];
if ($this->security->isGranted(PersonDocumentVoter::SEE, $person)) {
$menu->addChild($this->translator->trans('Documents'), [
'route' => 'person_document_index',
'routeParameters' => [
'person' => $person->getId()
]
])
->setExtras([
'order'=> 350
]);
}
return ['person', 'accompanyingCourse'];
}
protected function buildMenuAccompanyingCourse(MenuItem $menu, array $parameters){
private function buildMenuAccompanyingCourse(MenuItem $menu, array $parameters)
{
$course = $parameters['accompanyingCourse'];
if ($this->security->isGranted(AccompanyingCourseDocumentVoter::SEE, $course)) {
$menu->addChild($this->translator->trans('Documents'), [
'route' => 'accompanying_course_document_index',
'routeParameters' => [
'course' => $course->getId()
]
'course' => $course->getId(),
],
])
->setExtras([
'order' => 400
'order' => 400,
]);
}
}
public static function getMenuIds(): array
private function buildMenuPerson(MenuItem $menu, array $parameters)
{
return [ 'person', 'accompanyingCourse' ];
/* @var $person \Chill\PersonBundle\Entity\Person */
$person = $parameters['person'];
if ($this->security->isGranted(PersonDocumentVoter::SEE, $person)) {
$menu->addChild($this->translator->trans('Documents'), [
'route' => 'person_document_index',
'routeParameters' => [
'person' => $person->getId(),
],
])
->setExtras([
'order' => 350,
]);
}
}
}

View File

@@ -1,33 +1,31 @@
<?php
/*
/**
* 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\Object;
use ChampsLibres\AsyncUploaderBundle\Form\AsyncFileTransformer\AsyncFileTransformerInterface;
use ChampsLibres\AsyncUploaderBundle\Model\AsyncFileInterface;
use Chill\DocStoreBundle\Entity\StoredObject;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Doctrine\ORM\EntityManagerInterface;
/**
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class ObjectToAsyncFileTransformer implements AsyncFileTransformerInterface
{
/**
*
* @var EntityManagerInterface
*/
protected $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
public function toAsyncFile($data)
{
if ($data instanceof StoredObject) {
@@ -39,11 +37,9 @@ class ObjectToAsyncFileTransformer implements AsyncFileTransformerInterface
{
$object = $this->em
->getRepository(StoredObject::class)
->findByFilename($asyncFile->getObjectName())
;
->findByFilename($asyncFile->getObjectName());
return $object ?? (new StoredObject())
->setFilename($asyncFile->getObjectName())
;
->setFilename($asyncFile->getObjectName());
}
}

View File

@@ -1,40 +1,38 @@
<?php
/*
/**
* 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\Object;
use ChampsLibres\AsyncUploaderBundle\Persistence\PersistenceCheckerInterface;
use Chill\DocStoreBundle\Entity\StoredObject;
use Doctrine\ORM\EntityManagerInterface;
/**
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class PersistenceChecker implements PersistenceCheckerInterface
{
/**
*
* @var EntityManagerInterface
*/
protected $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
public function isPersisted($object_name): bool
{
$qb = $this->em->createQueryBuilder();
$qb->select('COUNT(m)')
->from(StoredObject::class, 'm')
->where($qb->expr()->eq('m.filename', ':object_name'))
->setParameter('object_name', $object_name)
;
->setParameter('object_name', $object_name);
return 1 === $qb->getQuery()->getSingleScalarResult();
}
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\DocStoreBundle\Repository;
@@ -18,6 +25,11 @@ final class StoredObjectRepository implements ObjectRepository
$this->repository = $entityManager->getRepository(StoredObject::class);
}
public function find($id, $lockMode = null, $lockVersion = null): ?StoredObject
{
return $this->repository->find($id, $lockMode, $lockVersion);
}
/**
* @return array<int, StoredObject>
*/
@@ -27,6 +39,9 @@ final class StoredObjectRepository implements ObjectRepository
}
/**
* @param mixed|null $limit
* @param mixed|null $offset
*
* @return array<int, StoredObject>
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
@@ -43,9 +58,4 @@ final class StoredObjectRepository implements ObjectRepository
{
return StoredObject::class;
}
public function find($id, $lockMode = null, $lockVersion = null): ?StoredObject
{
return $this->repository->find($id, $lockMode, $lockVersion);
}
}

View File

@@ -1,36 +1,47 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\DocStoreBundle\Security\Authorization;
use Chill\DocStoreBundle\Entity\AccompanyingCourseDocument;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Security\Authorization\AbstractChillVoter;
use Chill\MainBundle\Security\Authorization\VoterHelperFactoryInterface;
use Chill\MainBundle\Security\Authorization\VoterHelperInterface;
use Chill\MainBundle\Security\ProvideRoleHierarchyInterface;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Security;
use function in_array;
/**
*
*/
class AccompanyingCourseDocumentVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterface
{
const CREATE = 'CHILL_ACCOMPANYING_COURSE_DOCUMENT_CREATE';
const SEE = 'CHILL_ACCOMPANYING_COURSE_DOCUMENT_SEE';
const SEE_DETAILS = 'CHILL_ACCOMPANYING_COURSE_DOCUMENT_SEE_DETAILS';
const UPDATE = 'CHILL_ACCOMPANYING_COURSE_DOCUMENT_UPDATE';
const DELETE = 'CHILL_ACCOMPANYING_COURSE_DOCUMENT_DELETE';
public const CREATE = 'CHILL_ACCOMPANYING_COURSE_DOCUMENT_CREATE';
public const DELETE = 'CHILL_ACCOMPANYING_COURSE_DOCUMENT_DELETE';
public const SEE = 'CHILL_ACCOMPANYING_COURSE_DOCUMENT_SEE';
public const SEE_DETAILS = 'CHILL_ACCOMPANYING_COURSE_DOCUMENT_SEE_DETAILS';
public const UPDATE = 'CHILL_ACCOMPANYING_COURSE_DOCUMENT_UPDATE';
protected LoggerInterface $logger;
protected VoterHelperInterface $voterHelper;
protected Security $security;
protected VoterHelperInterface $voterHelper;
public function __construct(
LoggerInterface $logger,
Security $security,
@@ -52,10 +63,20 @@ class AccompanyingCourseDocumentVoter extends AbstractChillVoter implements Prov
self::SEE,
self::SEE_DETAILS,
self::UPDATE,
self::DELETE
self::DELETE,
];
}
public function getRolesWithHierarchy(): array
{
return ['accompanyingCourseDocument' => $this->getRoles()];
}
public function getRolesWithoutScope(): array
{
return [];
}
protected function supports($attribute, $subject)
{
return $this->voterHelper->supports($attribute, $subject);
@@ -63,7 +84,7 @@ class AccompanyingCourseDocumentVoter extends AbstractChillVoter implements Prov
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
$this->logger->debug(sprintf("Voting from %s class", self::class));
$this->logger->debug(sprintf('Voting from %s class', self::class));
if (!$token->getUser() instanceof User) {
return false;
@@ -71,7 +92,7 @@ class AccompanyingCourseDocumentVoter extends AbstractChillVoter implements Prov
if ($subject instanceof AccompanyingPeriod) {
if (AccompanyingPeriod::STEP_CLOSED === $subject->getStep()) {
if ($attribute === self::CREATE) {
if (self::CREATE === $attribute) {
return false;
}
}
@@ -81,21 +102,11 @@ class AccompanyingCourseDocumentVoter extends AbstractChillVoter implements Prov
}
if (AccompanyingPeriod::STEP_CLOSED === $subject->getCourse()->getStep()
&& \in_array($attribute, [self::CREATE, self::DELETE, self::UPDATE], true)) {
&& in_array($attribute, [self::CREATE, self::DELETE, self::UPDATE], true)) {
return false;
}
}
return $this->voterHelper->voteOnAttribute($attribute, $subject, $token);
}
public function getRolesWithoutScope(): array
{
return [];
}
public function getRolesWithHierarchy(): array
{
return ['accompanyingCourseDocument' => $this->getRoles()];
}
}

View File

@@ -1,29 +1,42 @@
<?php
/**
* 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\Security\Authorization;
use Chill\DocStoreBundle\Entity\PersonDocument;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Security\Authorization\AbstractChillVoter;
use Chill\MainBundle\Security\Authorization\VoterHelperFactoryInterface;
use Chill\MainBundle\Security\Authorization\VoterHelperInterface;
use Chill\MainBundle\Security\ProvideRoleHierarchyInterface;
use Chill\DocStoreBundle\Entity\PersonDocument;
use Chill\PersonBundle\Entity\Person;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Security;
class PersonDocumentVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterface
{
const CREATE = 'CHILL_PERSON_DOCUMENT_CREATE';
const SEE = 'CHILL_PERSON_DOCUMENT_SEE';
const SEE_DETAILS = 'CHILL_PERSON_DOCUMENT_SEE_DETAILS';
const UPDATE = 'CHILL_PERSON_DOCUMENT_UPDATE';
const DELETE = 'CHILL_PERSON_DOCUMENT_DELETE';
public const CREATE = 'CHILL_PERSON_DOCUMENT_CREATE';
public const DELETE = 'CHILL_PERSON_DOCUMENT_DELETE';
public const SEE = 'CHILL_PERSON_DOCUMENT_SEE';
public const SEE_DETAILS = 'CHILL_PERSON_DOCUMENT_SEE_DETAILS';
public const UPDATE = 'CHILL_PERSON_DOCUMENT_UPDATE';
protected LoggerInterface $logger;
protected Security $security;
protected VoterHelperInterface $voterHelper;
public function __construct(
@@ -47,25 +60,34 @@ class PersonDocumentVoter extends AbstractChillVoter implements ProvideRoleHiera
self::SEE,
self::SEE_DETAILS,
self::UPDATE,
self::DELETE
self::DELETE,
];
}
public function getRolesWithHierarchy(): array
{
return ['PersonDocument' => $this->getRoles()];
}
public function getRolesWithoutScope(): array
{
return [];
}
protected function supports($attribute, $subject)
{
return $this->voterHelper->supports($attribute, $subject);
}
/**
*
* @param string $attribute
* @param PersonDocument $subject
* @param TokenInterface $token
* @return boolean
*
* @return bool
*/
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
$this->logger->debug(sprintf("Voting from %s class", self::class));
$this->logger->debug(sprintf('Voting from %s class', self::class));
if (!$token->getUser() instanceof User) {
return false;
@@ -78,14 +100,4 @@ class PersonDocumentVoter extends AbstractChillVoter implements ProvideRoleHiera
return $this->voterHelper->voteOnAttribute($attribute, $subject, $token);
}
public function getRolesWithoutScope(): array
{
return [];
}
public function getRolesWithHierarchy(): array
{
return ['PersonDocument' => $this->getRoles()];
}
}

View File

@@ -1,15 +1,31 @@
<?php declare(strict_types=1);
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\Migrations\DocStore;
use Doctrine\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Create schema for chill_doc
* Create schema for chill_doc.
*/
final class Version20180605102533 extends AbstractMigration
{
public function down(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('DROP SCHEMA chill_doc CASCADE');
}
public function up(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
@@ -27,12 +43,4 @@ final class Version20180605102533 extends AbstractMigration
$this->addSql('ALTER TABLE chill_doc.person_document ADD CONSTRAINT FK_41DA53CA76ED395 FOREIGN KEY (user_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE chill_doc.person_document ADD CONSTRAINT FK_41DA53C217BBB47 FOREIGN KEY (person_id) REFERENCES chill_person_person (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
}
public function down(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('DROP SCHEMA chill_doc CASCADE');
}
}

View File

@@ -1,15 +1,35 @@
<?php declare(strict_types=1);
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\Migrations\DocStore;
use Doctrine\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Add schema for stored object
* Add schema for stored object.
*/
final class Version20180606133338 extends AbstractMigration
{
public function down(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE chill_doc.person_document DROP CONSTRAINT FK_41DA53C232D562B');
$this->addSql('DROP SEQUENCE chill_doc.stored_object_id_seq CASCADE');
$this->addSql('DROP TABLE chill_doc.stored_object');
$this->addSql('ALTER TABLE chill_doc.person_document ADD content TEXT DEFAULT NULL');
$this->addSql('ALTER TABLE chill_doc.person_document DROP object_id');
}
public function up(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
@@ -21,15 +41,4 @@ final class Version20180606133338 extends AbstractMigration
$this->addSql('ALTER TABLE chill_doc.person_document ADD CONSTRAINT FK_41DA53C232D562B FOREIGN KEY (object_id) REFERENCES chill_doc.stored_object (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE INDEX IDX_41DA53C232D562B ON chill_doc.person_document (object_id)');
}
public function down(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE chill_doc.person_document DROP CONSTRAINT FK_41DA53C232D562B');
$this->addSql('DROP SEQUENCE chill_doc.stored_object_id_seq CASCADE');
$this->addSql('DROP TABLE chill_doc.stored_object');
$this->addSql('ALTER TABLE chill_doc.person_document ADD content TEXT DEFAULT NULL');
$this->addSql('ALTER TABLE chill_doc.person_document DROP object_id');
}
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\Migrations\DocStore;
@@ -12,6 +19,12 @@ use Doctrine\Migrations\AbstractMigration;
*/
final class Version20210903091534 extends AbstractMigration
{
public function down(Schema $schema): void
{
$this->addSql('DROP SEQUENCE chill_doc.accompanyingcourse_document_id_seq CASCADE');
$this->addSql('DROP TABLE chill_doc.accompanyingcourse_document');
}
public function getDescription(): string
{
return '';
@@ -24,10 +37,4 @@ final class Version20210903091534 extends AbstractMigration
$this->addSql('CREATE INDEX IDX_A45098F6591CC992 ON chill_doc.accompanyingcourse_document (course_id)');
$this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document ADD CONSTRAINT FK_A45098F6591CC992 FOREIGN KEY (course_id) REFERENCES chill_person_accompanying_period (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
}
public function down(Schema $schema): void
{
$this->addSql('DROP SEQUENCE chill_doc.accompanyingcourse_document_id_seq CASCADE');
$this->addSql('DROP TABLE chill_doc.accompanyingcourse_document');
}
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\Migrations\DocStore;
@@ -12,6 +19,26 @@ use Doctrine\Migrations\AbstractMigration;
*/
final class Version20210903123835 extends AbstractMigration
{
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP CONSTRAINT FK_A45098F6369A0BE36EF62EFC');
$this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP CONSTRAINT FK_A45098F6232D562B');
$this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP CONSTRAINT FK_A45098F6682B5931');
$this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP CONSTRAINT FK_A45098F6A76ED395');
$this->addSql('DROP INDEX IDX_A45098F6369A0BE36EF62EFC');
$this->addSql('DROP INDEX IDX_A45098F6232D562B');
$this->addSql('DROP INDEX IDX_A45098F6682B5931');
$this->addSql('DROP INDEX IDX_A45098F6A76ED395');
$this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP category_bundle_id');
$this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP category_id_inside_bundle');
$this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP object_id');
$this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP scope_id');
$this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP user_id');
$this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP title');
$this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP description');
$this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP date');
}
public function getDescription(): string
{
return '';
@@ -36,24 +63,4 @@ final class Version20210903123835 extends AbstractMigration
$this->addSql('CREATE INDEX IDX_A45098F6682B5931 ON chill_doc.accompanyingcourse_document (scope_id)');
$this->addSql('CREATE INDEX IDX_A45098F6A76ED395 ON chill_doc.accompanyingcourse_document (user_id)');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP CONSTRAINT FK_A45098F6369A0BE36EF62EFC');
$this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP CONSTRAINT FK_A45098F6232D562B');
$this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP CONSTRAINT FK_A45098F6682B5931');
$this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP CONSTRAINT FK_A45098F6A76ED395');
$this->addSql('DROP INDEX IDX_A45098F6369A0BE36EF62EFC');
$this->addSql('DROP INDEX IDX_A45098F6232D562B');
$this->addSql('DROP INDEX IDX_A45098F6682B5931');
$this->addSql('DROP INDEX IDX_A45098F6A76ED395');
$this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP category_bundle_id');
$this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP category_id_inside_bundle');
$this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP object_id');
$this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP scope_id');
$this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP user_id');
$this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP title');
$this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP description');
$this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP date');
}
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\Migrations\DocStore;
@@ -9,6 +16,11 @@ use Doctrine\Migrations\AbstractMigration;
final class Version20210928182542 extends AbstractMigration
{
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_doc.stored_object DROP uuid');
}
public function getDescription(): string
{
return 'Create UUID column on StoredObject table.';
@@ -22,9 +34,4 @@ final class Version20210928182542 extends AbstractMigration
$this->addSql('ALTER TABLE chill_doc.stored_object ALTER uuid SET NOT NULL');
$this->addSql('CREATE UNIQUE INDEX UNIQ_49604E36D17F50A6 ON chill_doc.stored_object (uuid)');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_doc.stored_object DROP uuid');
}
}

View File

@@ -1,4 +1,12 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\Migrations\DocStore;
@@ -8,6 +16,11 @@ use Doctrine\Migrations\AbstractMigration;
final class Version20211119173558 extends AbstractMigration
{
public function down(Schema $schema): void
{
$this->throwIrreversibleMigrationException();
}
public function getDescription(): string
{
return 'remove comment on deprecated json_array type';
@@ -23,12 +36,7 @@ final class Version20211119173558 extends AbstractMigration
];
foreach ($columns as $col) {
$this->addSql("COMMENT ON COLUMN $col IS NULL");
$this->addSql("COMMENT ON COLUMN {$col} IS NULL");
}
}
public function down(Schema $schema): void
{
$this->throwIrreversibleMigrationException();
}
}