Merge branch 'master' into household_filiation

This commit is contained in:
2021-11-12 17:20:46 +01:00
298 changed files with 8036 additions and 3185 deletions

View File

@@ -3,12 +3,18 @@
namespace Chill\PersonBundle\Controller;
use Chill\MainBundle\CRUD\Controller\ApiController;
use Chill\MainBundle\Serializer\Model\Collection;
use Chill\PersonBundle\AccompanyingPeriod\Suggestion\ReferralsSuggestionInterface;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Chill\PersonBundle\Privacy\AccompanyingPeriodPrivacyEvent;
use Chill\PersonBundle\Entity\Person;
@@ -19,7 +25,6 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment;
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
use Chill\MainBundle\Entity\Scope;
use Chill\PersonBundle\Repository\AccompanyingPeriodACLAwareRepository;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Symfony\Component\Workflow\Registry;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
@@ -31,28 +36,36 @@ class AccompanyingCourseApiController extends ApiController
private Registry $registry;
private ReferralsSuggestionInterface $referralAvailable;
public function __construct(
EventDispatcherInterface $eventDispatcher,
ValidatorInterface $validator,
Registry $registry,
AccompanyingPeriodACLAwareRepository $accompanyingPeriodACLAwareRepository
AccompanyingPeriodACLAwareRepository $accompanyingPeriodACLAwareRepository,
ReferralsSuggestionInterface $referralAvailable
) {
$this->eventDispatcher = $eventDispatcher;
$this->validator = $validator;
$this->registry = $registry;
$this->accompanyingPeriodACLAwareRepository = $accompanyingPeriodACLAwareRepository;
$this->referralAvailable = $referralAvailable;
}
public function confirmApi($id, Request $request, $_format): Response
{
/** @var AccompanyingPeriod $accompanyingPeriod */
/** @var AccompanyingPeriod $accompanyingPeriod */
$accompanyingPeriod = $this->getEntity('participation', $id, $request);
$this->checkACL('confirm', $request, $_format, $accompanyingPeriod);
$workflow = $this->registry->get($accompanyingPeriod);
$workflow = $this->registry->get($accompanyingPeriod);
if (FALSE === $workflow->can($accompanyingPeriod, 'confirm')) {
throw new BadRequestException('It is not possible to confirm this period');
// throw new BadRequestException('It is not possible to confirm this period');
$errors = $this->validator->validate($accompanyingPeriod, null, [$accompanyingPeriod::STEP_CONFIRMED]);
if( count($errors) > 0 ){
return $this->json($errors, 422);
}
}
$workflow->apply($accompanyingPeriod, 'confirm');
@@ -63,10 +76,10 @@ $workflow = $this->registry->get($accompanyingPeriod);
'groups' => [ 'read' ]
]);
}
public function participationApi($id, Request $request, $_format)
{
/** @var AccompanyingPeriod $accompanyingPeriod */
/** @var AccompanyingPeriod $accompanyingPeriod */
$accompanyingPeriod = $this->getEntity('participation', $id, $request);
$person = $this->getSerializer()
->deserialize($request->getContent(), Person::class, $_format, []);
@@ -104,6 +117,13 @@ $workflow = $this->registry->get($accompanyingPeriod);
public function resourceApi($id, Request $request, string $_format): Response
{
$accompanyingPeriod = $this->getEntity('resource', $id, $request);
$errors = $this->validator->validate($accompanyingPeriod);
if ($errors->count() > 0) {
return $this->json($errors, 422);
}
return $this->addRemoveSomething('resource', $id, $request, $_format, 'resource', Resource::class);
}
@@ -157,7 +177,7 @@ $workflow = $this->registry->get($accompanyingPeriod);
->deserialize($request->getContent(), $class, $_format, []);
} catch (RuntimeException $e) {
$exceptions[] = $e;
}
}
}
if ($requestor === null) {
throw new BadRequestException('Could not find any person or requestor', 0, $exceptions[0]);
@@ -205,4 +225,28 @@ $workflow = $this->registry->get($accompanyingPeriod);
return $this->json(\array_values($accompanyingPeriodsChecked), Response::HTTP_OK, [], ['groups' => [ 'read']]);
}
/**
* @Route("/api/1.0/person/accompanying-course/{id}/referrers-suggested.{_format}",
* requirements={ "_format"="json"},
* name="chill_api_person_accompanying_period_referrers_suggested")
* @param AccompanyingPeriod $period
* @return JsonResponse
*/
public function suggestReferrals(AccompanyingPeriod $period, string $_format = 'json'): JsonResponse
{
$this->denyAccessUnlessGranted(AccompanyingPeriodVoter::EDIT, $period);
$total = $this->referralAvailable->countReferralSuggested($period);
$paginator = $this->getPaginatorFactory()->create($total);
if (0 < $total) {
$users = $this->referralAvailable->findReferralSuggested($period, $paginator->getItemsPerPage(),
$paginator->getCurrentPageFirstItemNumber());
} else {
$users = [];
}
return $this->json(new Collection($users, $paginator), Response::HTTP_OK,
[], [ AbstractNormalizer::GROUPS => [ 'read' ]]);
}
}

View File

@@ -11,7 +11,10 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Form\Form;
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository;
use Psr\Log\LoggerInterface;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
class AccompanyingCourseWorkController extends AbstractController
{
@@ -19,17 +22,20 @@ class AccompanyingCourseWorkController extends AbstractController
private SerializerInterface $serializer;
private AccompanyingPeriodWorkRepository $workRepository;
private PaginatorFactory $paginator;
protected LoggerInterface $logger;
public function __construct(
TranslatorInterface $trans,
SerializerInterface $serializer,
AccompanyingPeriodWorkRepository $workRepository,
PaginatorFactory $paginator
PaginatorFactory $paginator,
LoggerInterface $chillLogger
) {
$this->trans = $trans;
$this->serializer = $serializer;
$this->workRepository = $workRepository;
$this->paginator = $paginator;
$this->logger = $logger;
}
/**
@@ -106,4 +112,65 @@ class AccompanyingCourseWorkController extends AbstractController
'paginator' => $paginator
]);
}
/**
* @Route(
* "{_locale}/person/accompanying-period/work/{id}/delete",
* name="chill_person_accompanying_period_work_delete",
* methods={"GET", "POST", "DELETE"}
* )
*/
public function deleteWork(AccompanyingPeriodWork $work, Request $request): Response
{
// TODO ACL
$em = $this->getDoctrine()->getManager();
$form = $this->createDeleteForm($work->getId());
if ($request->getMethod() === Request::METHOD_DELETE) {
$form->handleRequest($request);
if ($form->isValid()) {
$this->logger->notice("An accompanying period work has been removed", [
'by_user' => $this->getUser()->getUsername(),
'work_id' => $work->getId(),
'accompanying_period_id' => $work->getAccompanyingPeriod()->getId()
]);
$em->remove($work);
$em->flush();
$this->addFlash(
'success',
$this->trans->trans("The accompanying period work has been successfully removed.")
);
return $this->redirectToRoute('chill_person_accompanying_period_work_list', [
'id' => $work->getAccompanyingPeriod()->getId()
]);
}
}
return $this->render('@ChillPerson/AccompanyingCourseWork/delete.html.twig', [
'accompanyingCourse' => $work->getAccompanyingPeriod(),
'work' => $work,
'delete_form' => $form->createView()
]);
}
private function createDeleteForm(int $id): Form
{
$params['id'] = $id;
return $this->createFormBuilder()
->setAction($this->generateUrl('chill_person_accompanying_period_work_delete', $params))
->setMethod('DELETE')
->add('submit', SubmitType::class, ['label' => 'Delete'])
->getForm()
;
}
}

View File

@@ -16,6 +16,8 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Chill\PersonBundle\Entity\Household\Household;
use Chill\PersonBundle\Entity\Household\Position;
use Chill\PersonBundle\Repository\Household\PositionRepository;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Symfony\Component\Security\Core\Security;
/**
* @Route("/{_locale}/person/household")
@@ -28,14 +30,18 @@ class HouseholdController extends AbstractController
private SerializerInterface $serializer;
private Security $security;
public function __construct(
TranslatorInterface $translator,
PositionRepository $positionRepository,
SerializerInterface $serializer
SerializerInterface $serializer,
Security $security
) {
$this->translator = $translator;
$this->positionRepository = $positionRepository;
$this->serializer = $serializer;
$this->security = $security;
}
/**
@@ -84,17 +90,46 @@ class HouseholdController extends AbstractController
*/
public function accompanyingPeriod(Request $request, Household $household)
{
// TODO ACL
$members = $household->getMembers();
foreach($members as $m) {
$accompanyingPeriods = $m->getPerson()->getAccompanyingPeriods();
$currentMembers = $household->getCurrentPersons();
$accompanyingPeriods = [];
foreach ($currentMembers as $p) {
$accompanyingPeriodsMember = $p->getCurrentAccompanyingPeriods();
foreach ($accompanyingPeriodsMember as $accompanyingPeriod) {
if (!$this->security->isGranted(AccompanyingPeriodVoter::SEE, $accompanyingPeriod)) {
continue;
} else {
$accompanyingPeriods[$accompanyingPeriod->getId()] = $accompanyingPeriod;
}
}
}
$oldMembers = $household->getNonCurrentMembers();
$accompanyingPeriodsOld = [];
foreach ($oldMembers as $m) {
$accompanyingPeriodsOldMember = $m->getPerson()->getAccompanyingPeriods();
foreach ($accompanyingPeriodsOldMember as $accompanyingPeriod) {
if (!$this->security->isGranted(AccompanyingPeriodVoter::SEE, $accompanyingPeriod)) {
continue;
} else {
$id = $accompanyingPeriod->getId();
if (!array_key_exists($id, $accompanyingPeriodsOld) && !array_key_exists($id, $accompanyingPeriods)) {
$accompanyingPeriodsOld[$id] = $accompanyingPeriod;
}
}
}
}
return $this->render('@ChillPerson/Household/accompanying_period.html.twig',
[
'household' => $household,
'accompanying_periods' => $accompanyingPeriods
'accompanying_periods' => $accompanyingPeriods,
'accompanying_periods_old' => $accompanyingPeriodsOld
]
);
}

View File

@@ -150,7 +150,7 @@ final class PersonController extends AbstractController
));
}
public function editAction($person_id)
public function editAction($person_id, Request $request)
{
$person = $this->_getPerson($person_id);
@@ -163,57 +163,33 @@ final class PersonController extends AbstractController
$form = $this->createForm(PersonType::class, $person,
array(
"action" => $this->generateUrl('chill_person_general_update',
array("person_id" => $person_id)),
"cFGroup" => $this->getCFGroup()
)
);
return $this->render('ChillPersonBundle:Person:edit.html.twig',
array('person' => $person, 'form' => $form->createView()));
}
public function updateAction($person_id, Request $request)
{
$person = $this->_getPerson($person_id);
if ($person === null) {
return $this->createNotFoundException();
}
$this->denyAccessUnlessGranted('CHILL_PERSON_UPDATE', $person,
'You are not allowed to edit this person');
$form = $this->createForm(PersonType::class, $person,
array("cFGroup" => $this->getCFGroup()));
if ($request->getMethod() === 'POST') {
$form->handleRequest($request);
if ( ! $form->isValid() ) {
$this->get('session')
->getFlashBag()->add('error', $this->translator
->trans('This form contains errors'));
return $this->render('ChillPersonBundle:Person:edit.html.twig',
array('person' => $person,
'form' => $form->createView()));
}
$form->handleRequest($request);
if ($form->isSubmitted() && !$form->isValid()) {
$this->get('session')
->getFlashBag()->add('error', $this->translator
->trans('This form contains errors'));
} elseif ($form->isSubmitted() && $form->isValid()) {
$this->get('session')->getFlashBag()
->add('success',
$this->get('translator')
->trans('The person data has been updated')
);
->add('success',
$this->get('translator')
->trans('The person data has been updated')
);
$this->em->flush();
$url = $this->generateUrl('chill_person_view', array(
return $this->redirectToRoute('chill_person_view', [
'person_id' => $person->getId()
));
return $this->redirect($url);
]);
}
return $this->render('ChillPersonBundle:Person:edit.html.twig',
array('person' => $person, 'form' => $form->createView()));
}
/**