mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Merge branch 'master' into onTheFly
This commit is contained in:
commit
3cf9920718
@ -7,6 +7,7 @@ charset = utf-8
|
||||
end_of_line = LF
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
indent_size = 4
|
||||
|
||||
[*.{php,html,twig}]
|
||||
indent_style = space
|
||||
|
18
CHANGELOG.md
Normal file
18
CHANGELOG.md
Normal file
@ -0,0 +1,18 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to
|
||||
|
||||
* [Semantic Versioning](https://semver.org/spec/v2.0.0.html) for stable releases;
|
||||
* date versioning for test releases
|
||||
|
||||
## Unreleased
|
||||
|
||||
* [Household editor][UI] Update how household suggestion and addresses are picked;
|
||||
* [AddAddress] Handle address suggestion;
|
||||
|
||||
## Test release yyyy-mm-dd
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
"league/csv": "^9.7.1",
|
||||
"nyholm/psr7": "^1.4",
|
||||
"phpoffice/phpspreadsheet": "^1.16",
|
||||
"ramsey/uuid-doctrine": "^1.7",
|
||||
"sensio/framework-extra-bundle": "^5.5",
|
||||
"symfony/asset": "4.*",
|
||||
"symfony/browser-kit": "^5.2",
|
||||
@ -29,6 +30,7 @@
|
||||
"symfony/expression-language": "4.*",
|
||||
"symfony/form": "4.*",
|
||||
"symfony/intl": "4.*",
|
||||
"symfony/mime": "^4 || ^5",
|
||||
"symfony/monolog-bundle": "^3.5",
|
||||
"symfony/security-bundle": "4.*",
|
||||
"symfony/serializer": "^5.2",
|
||||
|
@ -29,17 +29,19 @@ class ListenToActivityCreate
|
||||
$activityData = $request->query->get('activityData');
|
||||
if (array_key_exists('calendarId', $activityData)) {
|
||||
$calendarId = $activityData['calendarId'];
|
||||
|
||||
// Attach the activity to the calendar
|
||||
$em = $event->getObjectManager();
|
||||
|
||||
$calendar = $em->getRepository(\Chill\CalendarBundle\Entity\Calendar::class)->find($calendarId);
|
||||
$calendar->setActivity($activity);
|
||||
|
||||
$em->persist($calendar);
|
||||
$em->flush();
|
||||
}
|
||||
}
|
||||
|
||||
// Attach the activity to the calendar
|
||||
$em = $event->getObjectManager();
|
||||
|
||||
$calendar = $em->getRepository(\Chill\CalendarBundle\Entity\Calendar::class)->find($calendarId);
|
||||
$calendar->setActivity($activity);
|
||||
|
||||
$em->persist($calendar);
|
||||
$em->flush();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ class AccompanyingCourseMenuBuilder implements LocalMenuBuilderInterface
|
||||
'routeParameters' => [
|
||||
'accompanying_period_id' => $period->getId(),
|
||||
]])
|
||||
->setExtras(['order' => 41]);
|
||||
->setExtras(['order' => 35]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ class DocGeneratorTemplateController extends AbstractController
|
||||
$em->flush();
|
||||
|
||||
return $this->redirectToRoute('chill_wopi_file_edit', [
|
||||
'fileId' => $genDocName,
|
||||
'fileId' => $storedObject->getUuid(),
|
||||
'returnPath' => $request->query->get('returnPath', "/")
|
||||
]);
|
||||
}
|
||||
|
@ -7,7 +7,10 @@ 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 DateTimeInterface;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Ramsey\Uuid\UuidInterface;
|
||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||
|
||||
/**
|
||||
@ -19,7 +22,7 @@ use Symfony\Component\Serializer\Annotation as Serializer;
|
||||
* message="The file is not stored properly"
|
||||
* )
|
||||
*/
|
||||
class StoredObject implements AsyncFileInterface
|
||||
class StoredObject implements AsyncFileInterface, Document
|
||||
{
|
||||
/**
|
||||
* @ORM\Id()
|
||||
@ -47,6 +50,12 @@ class StoredObject implements AsyncFileInterface
|
||||
*/
|
||||
private array $iv = [];
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="uuid", unique=true)
|
||||
* @Serializer\Groups({"read"})
|
||||
*/
|
||||
private UuidInterface $uuid;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="datetime", name="creation_date")
|
||||
* @Serializer\Groups({"read"})
|
||||
@ -68,6 +77,7 @@ class StoredObject implements AsyncFileInterface
|
||||
public function __construct()
|
||||
{
|
||||
$this->creationDate = new \DateTime();
|
||||
$this->uuid = Uuid::uuid4();
|
||||
}
|
||||
|
||||
public function getId()
|
||||
@ -155,5 +165,13 @@ class StoredObject implements AsyncFileInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUuid(): UuidInterface
|
||||
{
|
||||
return $this->uuid;
|
||||
}
|
||||
|
||||
public function getWopiDocId(): string
|
||||
{
|
||||
return (string) $this->uuid;
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,12 @@
|
||||
"description": "A Chill bundle to store documents",
|
||||
"type": "symfony-bundle",
|
||||
"autoload": {
|
||||
"psr-4": { "Chill\\DocStoreBundle\\" : "" }
|
||||
"psr-4": {
|
||||
"Chill\\DocStoreBundle\\": ""
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"symfony/mime": "^4 || ^5"
|
||||
},
|
||||
"license": "AGPL-3.0"
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\Migrations\DocStore;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20210928182542 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Create UUID column on StoredObject table.';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('CREATE EXTENSION IF NOT EXISTS "uuid-ossp"');
|
||||
$this->addSql('ALTER TABLE chill_doc.stored_object ADD uuid UUID DEFAULT NULL');
|
||||
$this->addSql('UPDATE chill_doc.stored_object SET uuid=uuid_generate_v4()');
|
||||
$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');
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\MainBundle\Controller;
|
||||
|
||||
use Chill\MainBundle\CRUD\Controller\ApiController;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
||||
|
||||
class AddressApiController extends ApiController
|
||||
{
|
||||
/**
|
||||
* Duplicate an existing address
|
||||
*
|
||||
* @Route("/api/1.0/main/address/{id}/duplicate.json", name="chill_api_main_address_duplicate",
|
||||
* methods={"POST"})
|
||||
*
|
||||
* @param Address $address
|
||||
*/
|
||||
public function duplicate(Address $address): JsonResponse
|
||||
{
|
||||
$this->denyAccessUnlessGranted('ROLE_USER');
|
||||
$new = Address::createFromAddress($address);
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$em->persist($new);
|
||||
$em->flush();
|
||||
|
||||
return $this->json($new, Response::HTTP_OK, [], [
|
||||
AbstractNormalizer::GROUPS => ['read']
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -19,6 +19,7 @@
|
||||
|
||||
namespace Chill\MainBundle\DependencyInjection;
|
||||
|
||||
use Chill\MainBundle\Controller\AddressApiController;
|
||||
use Chill\MainBundle\Controller\UserController;
|
||||
use Chill\MainBundle\Doctrine\DQL\STContains;
|
||||
use Chill\MainBundle\Doctrine\DQL\StrictWordSimilarityOPS;
|
||||
@ -319,6 +320,7 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
||||
'apis' => [
|
||||
[
|
||||
'class' => \Chill\MainBundle\Entity\Address::class,
|
||||
'controller' => AddressApiController::class,
|
||||
'name' => 'address',
|
||||
'base_path' => '/api/1.0/main/address',
|
||||
'base_role' => 'ROLE_USER',
|
||||
|
@ -376,10 +376,22 @@ class Address
|
||||
public static function createFromAddress(Address $original) : Address
|
||||
{
|
||||
return (new Address())
|
||||
->setBuildingName($original->getBuildingName())
|
||||
->setCorridor($original->getCorridor())
|
||||
->setCustoms($original->getCustoms())
|
||||
->setDistribution($original->getDistribution())
|
||||
->setExtra($original->getExtra())
|
||||
->setFlat($original->getFlat())
|
||||
->setFloor($original->getFloor())
|
||||
->setIsNoAddress($original->getIsNoAddress())
|
||||
->setLinkedToThirdParty($original->getLinkedToThirdParty())
|
||||
->setPoint($original->getPoint())
|
||||
->setPostcode($original->getPostcode())
|
||||
->setStreetAddress1($original->getStreetAddress1())
|
||||
->setStreetAddress2($original->getStreetAddress2())
|
||||
->setSteps($original->getSteps())
|
||||
->setStreet($original->getStreet())
|
||||
->setStreetNumber($original->getStreetNumber())
|
||||
->setValidFrom($original->getValidFrom())
|
||||
->setValidTo($original->getValidTo())
|
||||
;
|
||||
}
|
||||
|
||||
@ -506,7 +518,7 @@ class Address
|
||||
return $this->validTo;
|
||||
}
|
||||
|
||||
public function setValidTo(\DateTimeInterface $validTo): self
|
||||
public function setValidTo(?\DateTimeInterface $validTo = null): self
|
||||
{
|
||||
$this->validTo = $validTo;
|
||||
|
||||
|
@ -7,6 +7,7 @@ namespace Chill\MainBundle\Repository;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
|
||||
final class AddressRepository implements ObjectRepository
|
||||
@ -47,4 +48,9 @@ final class AddressRepository implements ObjectRepository
|
||||
public function getClassName() {
|
||||
return Address::class;
|
||||
}
|
||||
|
||||
public function createQueryBuilder(string $alias, ?string $indexBy = null): QueryBuilder
|
||||
{
|
||||
return $this->repository->createQueryBuilder($alias, $indexBy);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* Endpoint chill_api_single_country__index
|
||||
* method GET, get Country Object
|
||||
* @returns {Promise} a promise containing all Country object
|
||||
@ -14,7 +14,7 @@ const fetchCountries = () => {
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
/**
|
||||
* Endpoint chill_api_single_postal_code__index
|
||||
* method GET, get Country Object
|
||||
* @returns {Promise} a promise containing all Postal Code objects filtered with country
|
||||
@ -29,7 +29,7 @@ const fetchCities = (country) => {
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
/**
|
||||
* Endpoint chill_api_single_address_reference__index
|
||||
* method GET, get AddressReference Object
|
||||
* @returns {Promise} a promise containing all AddressReference objects filtered with postal code
|
||||
@ -44,7 +44,7 @@ const fetchReferenceAddresses = (postalCode) => {
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
/**
|
||||
* Endpoint chill_api_single_address_reference__index
|
||||
* method GET, get AddressReference Object
|
||||
* @returns {Promise} a promise containing all AddressReference objects filtered with postal code
|
||||
@ -60,7 +60,7 @@ const fetchAddresses = () => {
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
/**
|
||||
* Endpoint chill_api_single_address__entity__create
|
||||
* method POST, post Address Object
|
||||
* @returns {Promise}
|
||||
@ -81,8 +81,28 @@ const postAddress = (address) => {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param address
|
||||
* @returns {Promise<Response>}
|
||||
*/
|
||||
const duplicateAddress = (address) => {
|
||||
const url = `/api/1.0/main/address/${address.address_id}/duplicate.json`;
|
||||
return fetch(url, {
|
||||
'method': 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json;charset=utf-8'
|
||||
},
|
||||
}).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
}
|
||||
throw Error('Error with request resource response');
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
/**
|
||||
* Endpoint chill_api_single_address__entity__create
|
||||
* method PATCH, patch Address Instance
|
||||
*
|
||||
@ -142,6 +162,7 @@ const getAddress = (id) => {
|
||||
};
|
||||
|
||||
export {
|
||||
duplicateAddress,
|
||||
fetchCountries,
|
||||
fetchCities,
|
||||
fetchReferenceAddresses,
|
||||
|
@ -34,6 +34,7 @@
|
||||
v-bind:defaultz="this.defaultz"
|
||||
v-bind:entity="this.entity"
|
||||
v-bind:flag="this.flag"
|
||||
@pick-address="this.pickAddress"
|
||||
ref="suggestAddress">
|
||||
</suggest-pane>
|
||||
</template>
|
||||
@ -55,6 +56,7 @@
|
||||
v-bind:entity="this.entity"
|
||||
v-bind:flag="this.flag"
|
||||
v-bind:insideModal="false"
|
||||
@pick-address="this.pickAddress"
|
||||
ref="suggestAddress">
|
||||
|
||||
<template v-slot:before v-if="!bypassFirstStep">
|
||||
@ -217,7 +219,16 @@
|
||||
|
||||
<script>
|
||||
import Modal from 'ChillMainAssets/vuejs/_components/Modal';
|
||||
import { getAddress, fetchCountries, fetchCities, fetchReferenceAddresses, patchAddress, postAddress, postPostalCode } from '../api';
|
||||
import {
|
||||
duplicateAddress,
|
||||
fetchCountries,
|
||||
fetchCities,
|
||||
fetchReferenceAddresses,
|
||||
getAddress,
|
||||
patchAddress,
|
||||
postAddress,
|
||||
postPostalCode,
|
||||
} from '../api';
|
||||
import { postAddressToPerson, postAddressToHousehold } from "ChillPersonAssets/vuejs/_api/AddAddress.js";
|
||||
import ShowPane from './ShowPane.vue';
|
||||
import SuggestPane from './SuggestPane.vue';
|
||||
@ -234,6 +245,9 @@ export default {
|
||||
EditPane,
|
||||
DatePane
|
||||
},
|
||||
emits: {
|
||||
pickAddress: null
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
flag: {
|
||||
@ -311,8 +325,10 @@ export default {
|
||||
return (this.validFrom || this.validTo) ? true : false;
|
||||
},
|
||||
hasSuggestions() {
|
||||
// TODO
|
||||
//return addressSuggestions.length > 0
|
||||
console.log(this.context.suggestions);
|
||||
if (typeof(this.context.suggestions) !== 'undefined') {
|
||||
return this.context.suggestions.length > 0;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
displaySuggestions() {
|
||||
@ -647,9 +663,12 @@ export default {
|
||||
this.flag.loading = false;
|
||||
this.flag.success = true;
|
||||
resolve({
|
||||
address,
|
||||
targetOrigin: this.context.target,
|
||||
// for "legacy" use:
|
||||
target: this.context.target.name,
|
||||
targetId: this.context.target.id,
|
||||
addressId: this.entity.address.address_id
|
||||
addressId: this.entity.address.address_id,
|
||||
}
|
||||
);
|
||||
}))
|
||||
@ -695,6 +714,9 @@ export default {
|
||||
this.flag.loading = false;
|
||||
this.flag.success = true;
|
||||
return resolve({
|
||||
address,
|
||||
targetOrigin: this.context.target,
|
||||
// for "legacy" use:
|
||||
target: this.context.target.name,
|
||||
targetId: this.context.target.id,
|
||||
addressId: this.entity.address.address_id
|
||||
@ -705,6 +727,29 @@ export default {
|
||||
this.errorMsg.push(error);
|
||||
this.flag.loading = false;
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* @param address the address selected
|
||||
*/
|
||||
pickAddress(address) {
|
||||
console.log('pickAddress', address);
|
||||
duplicateAddress(address).then(newAddress => {
|
||||
this.entity.address = newAddress;
|
||||
this.flag.loading = false;
|
||||
this.flag.success = true;
|
||||
let payload = {
|
||||
address: newAddress,
|
||||
targetOrigin: this.context.target,
|
||||
// for "legacy" use:
|
||||
target: this.context.target.name,
|
||||
targetId: this.context.target.id,
|
||||
addressId: this.entity.address.address_id
|
||||
};
|
||||
this.addressChangedCallback(payload);
|
||||
this.closeSuggestPane();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,13 +10,14 @@
|
||||
<h4 class="h3">{{ $t('address_suggestions') }}</h4>
|
||||
|
||||
<div class="flex-table AddressSuggestionList">
|
||||
<div class="item-bloc">
|
||||
<div v-for="a in context.suggestions" class="item-bloc">
|
||||
<div class="float-button bottom">
|
||||
<div class="box">
|
||||
<div class="action">
|
||||
<!-- QUESTION normal que ça vienne avant l'adresse ? pourquoi pas après avoir affiché le address-render-box ? -->
|
||||
<ul class="record_actions">
|
||||
<li>
|
||||
<button class="btn btn-sm btn-choose">
|
||||
<button class="btn btn-sm btn-choose" @click="this.pickAddress(a)">
|
||||
{{ $t('use_this_address') }}
|
||||
</button>
|
||||
</li>
|
||||
@ -25,9 +26,7 @@
|
||||
<ul class="list-content fa-ul">
|
||||
<li>
|
||||
<i class="fa fa-li fa-map-marker"></i>
|
||||
<!--
|
||||
<address-render-box></address-render-box>
|
||||
-->
|
||||
<address-render-box :address="a"></address-render-box>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@ -68,9 +67,14 @@ export default {
|
||||
'flag',
|
||||
'entity',
|
||||
'errorMsg',
|
||||
'insideModal'
|
||||
'insideModal',
|
||||
],
|
||||
computed: {},
|
||||
methods: {}
|
||||
methods: {
|
||||
pickAddress(address) {
|
||||
console.log('pickAddress in suggest pane', address);
|
||||
this.$emit('pickAddress', address);
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@ -10,7 +10,7 @@
|
||||
{% endblock %}
|
||||
{% block table_entities_tbody %}
|
||||
{% for entity in entities %}
|
||||
<tr>
|
||||
<tr data-username="{{ entity.username|e('html_attr') }}">
|
||||
<td>
|
||||
{% if entity.isEnabled %}
|
||||
<i class="fa fa-check chill-green"></i>
|
||||
|
@ -17,32 +17,31 @@
|
||||
*/
|
||||
namespace Chill\MainBundle\Test;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
/**
|
||||
* Prepare a client authenticated with a user
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* Prepare a client authenticated with a user
|
||||
*/
|
||||
trait PrepareClientTrait
|
||||
{
|
||||
/**
|
||||
* Create a new client with authentication information.
|
||||
*
|
||||
*
|
||||
* @param string $username the username (default 'center a_social')
|
||||
* @param string $password the password (default 'password')
|
||||
* @return \Symfony\Component\BrowserKit\Client
|
||||
* @throws \LogicException
|
||||
*/
|
||||
public function getClientAuthenticated(
|
||||
$username = 'center a_social',
|
||||
$username = 'center a_social',
|
||||
$password = 'password'
|
||||
) {
|
||||
): KernelBrowser {
|
||||
if (!$this instanceof WebTestCase) {
|
||||
throw new \LogicException(sprintf("The current class does not "
|
||||
. "implements %s", WebTestCase::class));
|
||||
}
|
||||
|
||||
|
||||
return static::createClient(array(), array(
|
||||
'PHP_AUTH_USER' => $username,
|
||||
'PHP_AUTH_PW' => $password,
|
||||
|
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Controller;
|
||||
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Chill\MainBundle\Repository\AddressRepository;
|
||||
use Chill\MainBundle\Test\PrepareClientTrait;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
||||
|
||||
class AddressControllerTest extends \Symfony\Bundle\FrameworkBundle\Test\WebTestCase
|
||||
{
|
||||
private KernelBrowser $client;
|
||||
|
||||
use PrepareClientTrait;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
self::bootKernel();
|
||||
$this->client = $this->getClientAuthenticated();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider generateAddressIds
|
||||
* @param int $addressId
|
||||
*/
|
||||
public function testDuplicate(int $addressId)
|
||||
{
|
||||
$this->client->request('POST', "/api/1.0/main/address/$addressId/duplicate.json");
|
||||
|
||||
$this->assertResponseIsSuccessful('test that duplicate is successful');
|
||||
}
|
||||
|
||||
public function generateAddressIds()
|
||||
{
|
||||
self::bootKernel();
|
||||
$em = self::$container->get(EntityManagerInterface::class);
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$addresses = $qb->select('a')->from(Address::class, 'a')
|
||||
->setMaxResults(2)
|
||||
->getQuery()
|
||||
->getResult();
|
||||
|
||||
foreach ($addresses as $a) {
|
||||
yield [ $a->getId() ];
|
||||
}
|
||||
}
|
||||
}
|
@ -2,12 +2,17 @@
|
||||
|
||||
namespace Chill\MainBundle\Tests\Controller;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
|
||||
|
||||
class UserControllerTest extends WebTestCase
|
||||
{
|
||||
private $client;
|
||||
|
||||
private array $toDelete = [];
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
self::bootKernel();
|
||||
@ -22,18 +27,14 @@ class UserControllerTest extends WebTestCase
|
||||
public function testList()
|
||||
{
|
||||
// get the list
|
||||
$crawler = $this->client->request('GET', '/fr/admin/user/');
|
||||
$crawler = $this->client->request('GET', '/fr/admin/main/user');
|
||||
$this->assertEquals(200, $this->client->getResponse()->getStatusCode(),
|
||||
"Unexpected HTTP status code for GET /admin/user/");
|
||||
|
||||
$link = $crawler->selectLink('Ajouter un nouvel utilisateur')->link();
|
||||
$this->assertInstanceOf('Symfony\Component\DomCrawler\Link', $link);
|
||||
$this->assertRegExp('|/fr/admin/user/new$|', $link->getUri());
|
||||
"Unexpected HTTP status code for GET /admin/main/user");
|
||||
}
|
||||
|
||||
public function testNew()
|
||||
{
|
||||
$crawler = $this->client->request('GET', '/fr/admin/user/new');
|
||||
$crawler = $this->client->request('GET', '/fr/admin/main/user/new');
|
||||
|
||||
$username = 'Test_user'. uniqid();
|
||||
$password = 'Password1234!';
|
||||
@ -54,22 +55,15 @@ class UserControllerTest extends WebTestCase
|
||||
$this->assertGreaterThan(0, $crawler->filter('td:contains("Test_user")')->count(),
|
||||
'Missing element td:contains("Test user")');
|
||||
|
||||
$update = $crawler->selectLink('Modifier')->link();
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\DomCrawler\Link', $update);
|
||||
$this->assertRegExp('|/fr/admin/user/[0-9]{1,}/edit$|', $update->getUri());
|
||||
|
||||
//test the auth of the new client
|
||||
$this->isPasswordValid($username, $password);
|
||||
|
||||
return $update;
|
||||
}
|
||||
|
||||
protected function isPasswordValid($username, $password)
|
||||
{
|
||||
/* @var $passwordEncoder \Symfony\Component\Security\Core\Encoder\UserPasswordEncoder */
|
||||
$passwordEncoder = self::$kernel->getContainer()
|
||||
->get('security.password_encoder');
|
||||
$passwordEncoder = self::$container
|
||||
->get(UserPasswordEncoderInterface::class);
|
||||
|
||||
$user = self::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
@ -81,46 +75,33 @@ class UserControllerTest extends WebTestCase
|
||||
|
||||
/**
|
||||
*
|
||||
* @param \Symfony\Component\DomCrawler\Link $update
|
||||
* @depends testNew
|
||||
* @dataProvider dataGenerateUserId
|
||||
*/
|
||||
public function testUpdate(\Symfony\Component\DomCrawler\Link $update)
|
||||
public function testUpdate(int $userId, string $username)
|
||||
{
|
||||
$crawler = $this->client->click($update);
|
||||
$crawler = $this->client->request('GET', "/fr/admin/main/user/$userId/edit");
|
||||
|
||||
$username = 'Foo bar '.uniqid();
|
||||
$form = $crawler->selectButton('Mettre à jour')->form(array(
|
||||
$form = $crawler->selectButton('Enregistrer & fermer')->form(array(
|
||||
'chill_mainbundle_user[username]' => $username,
|
||||
));
|
||||
|
||||
$this->client->submit($form);
|
||||
$crawler = $this->client->followRedirect();
|
||||
// Check the element contains an attribute with value equals "Foo"
|
||||
$this->assertGreaterThan(0, $crawler->filter('[value="'.$username.'"]')->count(),
|
||||
'Missing element [value="Foo bar"]');
|
||||
|
||||
$updatePassword = $crawler->selectLink('Modifier le mot de passe')->link();
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\DomCrawler\Link', $updatePassword);
|
||||
$this->assertRegExp('|/fr/admin/user/[0-9]{1,}/edit_password$|',
|
||||
$updatePassword->getUri());
|
||||
|
||||
return array('link' => $updatePassword, 'username' => $username);
|
||||
$this->assertGreaterThan(0, $crawler->filter('[data-username="'.$username.'"]')->count(),
|
||||
'Missing element [data-username="Foo bar"]');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param \Symfony\Component\DomCrawler\Link $updatePassword
|
||||
* @depends testUpdate
|
||||
* @dataProvider dataGenerateUserId
|
||||
*/
|
||||
public function testUpdatePassword(array $params)
|
||||
public function testUpdatePassword(int $userId, $username)
|
||||
{
|
||||
$link = $params['link'];
|
||||
$username = $params['username'];
|
||||
$crawler = $this->client->request('GET', "/fr/admin/user/$userId/edit_password");
|
||||
$newPassword = '1234Password!';
|
||||
|
||||
$crawler = $this->client->click($link);
|
||||
|
||||
$form = $crawler->selectButton('Changer le mot de passe')->form(array(
|
||||
'chill_mainbundle_user_password[new_password][first]' => $newPassword,
|
||||
'chill_mainbundle_user_password[new_password][second]' => $newPassword,
|
||||
@ -130,10 +111,38 @@ class UserControllerTest extends WebTestCase
|
||||
|
||||
$this->assertTrue($this->client->getResponse()->isRedirect(),
|
||||
"the response is a redirection");
|
||||
$this->client->followRedirect();
|
||||
|
||||
$this->isPasswordValid($username, $newPassword);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
self::bootKernel();
|
||||
$em = self::$container->get(EntityManagerInterface::class);
|
||||
|
||||
foreach ($this->toDelete as list($class, $id)) {
|
||||
$obj = $em->getRepository($class)->find($id);
|
||||
$em->remove($obj);
|
||||
}
|
||||
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
public function dataGenerateUserId()
|
||||
{
|
||||
self::bootKernel();
|
||||
$em = self::$container->get(EntityManagerInterface::class);
|
||||
|
||||
$user = new User();
|
||||
$user->setUsername('Test_user '.uniqid());
|
||||
$user->setPassword(self::$container->get(UserPasswordEncoderInterface::class)->encodePassword($user,
|
||||
'password'));
|
||||
|
||||
$em->persist($user);
|
||||
$em->flush();
|
||||
|
||||
$this->toDelete[] = [User::class, $user->getId()];
|
||||
|
||||
yield [ $user->getId(), $user->getUsername() ];
|
||||
}
|
||||
}
|
||||
|
@ -293,6 +293,32 @@ paths:
|
||||
401:
|
||||
description: "Unauthorized"
|
||||
|
||||
/1.0/main/address/{id}/duplicate.json:
|
||||
post:
|
||||
tags:
|
||||
- address
|
||||
summary: Duplicate an existing address
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
required: true
|
||||
description: The address id that will be duplicated
|
||||
schema:
|
||||
type: integer
|
||||
format: integer
|
||||
minimum: 1
|
||||
responses:
|
||||
200:
|
||||
description: "ok"
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Address'
|
||||
404:
|
||||
description: "not found"
|
||||
401:
|
||||
description: "Unauthorized"
|
||||
|
||||
/1.0/main/address-reference.json:
|
||||
get:
|
||||
tags:
|
||||
|
@ -247,7 +247,6 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con
|
||||
if (\random_int(0, 10) > 3) {
|
||||
// always add social scope:
|
||||
$accompanyingPeriod->addScope($this->getReference('scope_social'));
|
||||
var_dump(count($accompanyingPeriod->getScopes()));
|
||||
|
||||
$accompanyingPeriod->setAddressLocation($this->createAddress());
|
||||
$manager->persist($accompanyingPeriod->getAddressLocation());
|
||||
|
@ -229,7 +229,7 @@ class Household
|
||||
))
|
||||
->andWhere($expr->orX(
|
||||
$expr->isNull('endDate'),
|
||||
$expr->gte('endDate', $date)
|
||||
$expr->gt('endDate', $date)
|
||||
));
|
||||
|
||||
return $criteria;
|
||||
@ -306,7 +306,7 @@ class Household
|
||||
)
|
||||
->orWhere(
|
||||
$expr->andX(
|
||||
$expr->lt('endDate', $date),
|
||||
$expr->lte('endDate', $date),
|
||||
$expr->neq('endDate', null)
|
||||
)
|
||||
);
|
||||
|
@ -199,7 +199,7 @@ final class PersonACLAwareRepository implements PersonACLAwareRepositoryInterfac
|
||||
}
|
||||
|
||||
if (NULL !== $birthdate) {
|
||||
$qb->andWhere($qb->expr()->eq('s.birthdate', ':birthdate'))
|
||||
$qb->andWhere($qb->expr()->eq('p.birthdate', ':birthdate'))
|
||||
->setParameter('birthdate', $birthdate);
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,7 @@ export default {
|
||||
this.toggleEditEvaluation();
|
||||
},
|
||||
buildEditLink(storedObject) {
|
||||
return `/fr/chill_wopi/edit/${storedObject.filename}?returnPath=` + encodeURIComponent(
|
||||
return `/edit/${storedObject.uuid}?returnPath=` + encodeURIComponent(
|
||||
window.location.pathname + window.location.search + window.location.hash);
|
||||
},
|
||||
}
|
||||
|
@ -2,171 +2,126 @@
|
||||
|
||||
<h2 class="mt-4">{{ $t('household_members_editor.household_part') }}</h2>
|
||||
|
||||
<div v-if="hasHousehold">
|
||||
<div v-if="mode == null">
|
||||
|
||||
<div class="flex-table">
|
||||
<div class="item-bloc">
|
||||
<household-render-box :household="household" :isAddressMultiline="true"></household-render-box>
|
||||
</div>
|
||||
</div>
|
||||
<div class="alert alert-info">{{ $t('household_members_editor.household.no_household_choose_one') }}</div>
|
||||
|
||||
<div v-if="isHouseholdNew && !hasHouseholdAddress">
|
||||
|
||||
<div v-if="hasAddressSuggestion" class="householdAddressSuggestion my-5">
|
||||
<h4 class="mb-3">
|
||||
{{ $t('household_members_editor.household.where_live_the_household') }}
|
||||
</h4>
|
||||
<div class="accordion" id="addressSuggestions">
|
||||
<div class="accordion-item">
|
||||
<h2 class="accordion-header" id="heading_address_suggestions">
|
||||
<button v-if="!showAddressSuggestion"
|
||||
class="accordion-button collapsed"
|
||||
type="button"
|
||||
data-bs-toggle="collapse"
|
||||
aria-expanded="false"
|
||||
@click="toggleAddressSuggestion">
|
||||
{{ $tc('household_members_editor.show_household_suggestion', countAddressSuggestion) }}
|
||||
</button>
|
||||
<button v-if="showAddressSuggestion"
|
||||
class="accordion-button"
|
||||
type="button"
|
||||
data-bs-toggle="collapse"
|
||||
aria-expanded="true"
|
||||
@click="toggleAddressSuggestion">
|
||||
{{ $t('household_members_editor.hide_household_suggestion') }}
|
||||
</button>
|
||||
</h2>
|
||||
<div class="accordion-collapse" id="collapse_address_suggestions"
|
||||
aria-labelledby="heading_address_suggestions" data-bs-parent="#addressSuggestions">
|
||||
<div v-if="showAddressSuggestion">
|
||||
<div class="flex-table householdAddressSuggestionList">
|
||||
<div v-for="a in filterAddressesSuggestion" class="item-bloc">
|
||||
<div class="float-button bottom">
|
||||
<div class="box">
|
||||
<div class="action">
|
||||
<ul class="record_actions">
|
||||
<li>
|
||||
<button class="btn btn-sm btn-choose" @click="setHouseholdAddress(a)">
|
||||
{{ $t('household_members_editor.household.household_live_to_this_address') }}
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<ul class="list-content fa-ul">
|
||||
<li>
|
||||
<i class="fa fa-li fa-map-marker"></i>
|
||||
<address-render-box :address="a"></address-render-box>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex-table householdSuggestionList">
|
||||
<div v-if="isModeNewAllowed" class="item-bloc">
|
||||
<div>
|
||||
<section>
|
||||
<div class="item-row">
|
||||
<div class="item-col">
|
||||
<div class="h4">
|
||||
<i class="fa fa-home"></i> {{ $t('household_members_editor.household.new_household') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<ul class="record_actions">
|
||||
<li>
|
||||
<button @click="setModeNew" class="btn btn-sm btn-create">{{ $t('household_members_editor.household.create_household') }}</button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- if allow leave household -->
|
||||
<div v-if="isModeLeaveAllowed" class="item-bloc">
|
||||
<div>
|
||||
<section>
|
||||
<div class="item-row">
|
||||
<div class="item-col">
|
||||
<div class="h4">
|
||||
<span class="fa-stack fa-lg">
|
||||
<i class="fa fa-home fa-stack-1x"></i>
|
||||
<i class="fa fa-ban fa-stack-2x text-danger"></i>
|
||||
</span>
|
||||
{{ $t('household_members_editor.household.leave_without_household') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="item-row">
|
||||
{{ $t('household_members_editor.household.will_leave_any_household_explanation')}}
|
||||
</div>
|
||||
</section>
|
||||
<ul class="record_actions">
|
||||
<li>
|
||||
<button @click="setModeLeave" class="btn btn-sm">
|
||||
<i class="fa fa-sign-out"></i>
|
||||
{{ $t('household_members_editor.household.leave') }}
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-for="item in getSuggestions">
|
||||
<div class="item-bloc">
|
||||
<household-render-box :household="item.household"></household-render-box>
|
||||
<ul class="record_actions">
|
||||
<li>
|
||||
<button class="btn btn-sm btn-choose" @click="selectHousehold(item.household)">
|
||||
{{ $t('household_members_editor.select_household') }}
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ul class="record_actions">
|
||||
<li >
|
||||
<add-address
|
||||
:context="addAddress.context"
|
||||
<div v-else>
|
||||
<div class="flex-table">
|
||||
<div class="item-bloc">
|
||||
<template v-if="isModeLeave">
|
||||
<section>
|
||||
<div class="item-row">
|
||||
<div class="item-col">
|
||||
<div class="h4">
|
||||
<span class="fa-stack fa-lg">
|
||||
<i class="fa fa-home fa-stack-1x"></i>
|
||||
<i class="fa fa-ban fa-stack-2x text-danger"></i>
|
||||
</span>
|
||||
{{ $t('household_members_editor.household.leave_without_household') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="item-row">
|
||||
{{ $t('household_members_editor.household.will_leave_any_household_explanation')}}
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
<template v-else>
|
||||
<household-render-box :household="household" :isAddressMultiline="true"></household-render-box>
|
||||
<ul class="record_actions">
|
||||
<li>
|
||||
<add-address
|
||||
:context="getAddressContext"
|
||||
:key="addAddress.key"
|
||||
:options="addAddress.options"
|
||||
:result="addAddress.result"
|
||||
@addressChangedCallback="setHouseholdCreatedAddress"
|
||||
ref="addAddress">
|
||||
</add-address>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div v-if="isHouseholdNew && hasHouseholdAddress">
|
||||
<ul class="record_actions">
|
||||
<li >
|
||||
<button class="btn btn-misc" @click="removeHouseholdAddress">
|
||||
{{ $t('household_members_editor.household.delete_this_address') }}
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div v-else-if="isForceLeaveWithoutHousehold">
|
||||
{{ $t('household_members_editor.household.will_leave_any_household') }}
|
||||
</div>
|
||||
<div v-else class="alert alert-info">{{ $t('household_members_editor.household.no_household_choose_one') }}</div>
|
||||
|
||||
<ul v-if="allowChangeHousehold" class="record_actions">
|
||||
<li v-if="allowHouseholdCreate">
|
||||
<button class="btn btn-create" @click="createHousehold">
|
||||
{{ $t('household_members_editor.household.create_household') }}
|
||||
</button>
|
||||
</li>
|
||||
<li v-if="allowHouseholdSearch">
|
||||
<button class="btn btn-misc">
|
||||
<i class="fa fa-search"></i>{{ $t('household_members_editor.household.search_household') }}
|
||||
</button>
|
||||
</li>
|
||||
<li v-if="allowLeaveWithoutHousehold" >
|
||||
<button @click="forceLeaveWithoutHousehold" class="btn btn-orange">
|
||||
<i class="fa fa-sign-out"></i>{{ $t('household_members_editor.household.leave_without_household') }}
|
||||
</button>
|
||||
</li>
|
||||
<li v-if="allowRemoveHousehold">
|
||||
<button @click="removeHousehold" class="btn">
|
||||
{{ $t('household_members_editor.household.change') }}
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div v-if="hasHouseholdSuggestion" class="householdSuggestions my-5">
|
||||
<h4 class="mb-3">
|
||||
{{ $t('household_members_editor.household_for_participants_accompanying_period') }} :
|
||||
</h4>
|
||||
<div class="accordion" id="householdSuggestions">
|
||||
<div class="accordion-item">
|
||||
<h2 class="accordion-header" id="heading_household_suggestions">
|
||||
<button v-if="!showHouseholdSuggestion"
|
||||
class="accordion-button collapsed"
|
||||
type="button"
|
||||
data-bs-toggle="collapse"
|
||||
aria-expanded="false"
|
||||
@click="toggleHouseholdSuggestion">
|
||||
{{ $tc('household_members_editor.show_household_suggestion', countHouseholdSuggestion) }}
|
||||
</button>
|
||||
<button v-if="showHouseholdSuggestion"
|
||||
class="accordion-button"
|
||||
type="button"
|
||||
data-bs-toggle="collapse"
|
||||
aria-expanded="true"
|
||||
@click="toggleHouseholdSuggestion">
|
||||
{{ $t('household_members_editor.hide_household_suggestion') }}
|
||||
</button>
|
||||
<!-- disabled bootstrap behaviour: data-bs-target="#collapse_household_suggestions" aria-controls="collapse_household_suggestions" -->
|
||||
</h2>
|
||||
<div class="accordion-collapse" id="collapse_household_suggestions"
|
||||
aria-labelledby="heading_household_suggestions" data-bs-parent="#householdSuggestions">
|
||||
<div v-if="showHouseholdSuggestion">
|
||||
<div class="flex-table householdSuggestionList">
|
||||
<div v-for="h in filterHouseholdSuggestionByAccompanyingPeriod" class="item-bloc">
|
||||
<household-render-box :household="h"></household-render-box>
|
||||
<ul class="record_actions">
|
||||
<li>
|
||||
<button class="btn btn-sm btn-choose" @click="selectHousehold(h)">
|
||||
{{ $t('household_members_editor.select_household') }}
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
:addressChangedCallback="addressChanged"
|
||||
></add-address>
|
||||
</li>
|
||||
<li v-if="hasHouseholdAddress">
|
||||
<button class="btn btn-remove"
|
||||
@click="removeHouseholdAddress">
|
||||
{{ $t('household_members_editor.household.remove_address') }}
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ul v-if="isModeNewAllowed || isModeLeaveAllowed || getModeSuggestions.length > 0" class="record_actions">
|
||||
<li>
|
||||
<button class="btn btn-sm btn-chill-beige" @click="resetMode">
|
||||
{{ $t('household_members_editor.household.reset_mode') }}
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
@ -185,35 +140,32 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
addAddress: {
|
||||
context: {
|
||||
target: {
|
||||
name: 'household_create',
|
||||
id: 0
|
||||
},
|
||||
edit: false,
|
||||
addressId: null
|
||||
},
|
||||
key: 'household_new',
|
||||
options: {
|
||||
useDate: {
|
||||
validFrom: true
|
||||
validFrom: false,
|
||||
validTo: false,
|
||||
},
|
||||
hideAddress: true,
|
||||
button: {
|
||||
text: {
|
||||
create: 'household_members_editor.household.or_create_new_address',
|
||||
edit: null,
|
||||
create: 'household_members_editor.household.set_address',
|
||||
edit: 'household_members_editor.household.update_address',
|
||||
}
|
||||
},
|
||||
title: {
|
||||
create: 'household_members_editor.household.create_new_address',
|
||||
edit: null,
|
||||
edit: 'household_members_editor.household.update_address_title',
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
...mapGetters([
|
||||
'isModeNewAllowed',
|
||||
'isModeLeaveAllowed',
|
||||
'getSuggestions',
|
||||
'hasHousehold',
|
||||
'isHouseholdNew',
|
||||
'hasHouseholdSuggestion',
|
||||
@ -223,68 +175,38 @@ export default {
|
||||
'countAddressSuggestion',
|
||||
'filterAddressesSuggestion',
|
||||
'hasHouseholdAddress',
|
||||
'isModeLeave',
|
||||
'getAddressContext',
|
||||
]),
|
||||
...mapState([
|
||||
'showHouseholdSuggestion',
|
||||
'showAddressSuggestion'
|
||||
'showAddressSuggestion',
|
||||
'mode',
|
||||
]),
|
||||
household() {
|
||||
return this.$store.state.household;
|
||||
},
|
||||
allowHouseholdCreate() {
|
||||
return this.$store.state.allowHouseholdCreate && !this.$store.getters.hasHousehold;
|
||||
},
|
||||
allowHouseholdSearch() {
|
||||
return false;
|
||||
return this.$store.state.allowHouseholdSearch && !this.$store.getters.hasHousehold;
|
||||
},
|
||||
allowLeaveWithoutHousehold() {
|
||||
return this.$store.state.allowLeaveWithoutHousehold && !this.$store.getters.hasHousehold;
|
||||
},
|
||||
allowRemoveHousehold() {
|
||||
return this.$store.getters.hasHousehold &&
|
||||
(
|
||||
this.allowHouseholdCreate || this.allowHouseholdSearch ||
|
||||
this.allowLeaveWithoutHousehold
|
||||
)
|
||||
;
|
||||
},
|
||||
allowChangeHousehold() {
|
||||
return this.allowHouseholdCreate || this.allowHouseholdSearch ||
|
||||
this.allowLeaveWithoutHousehold;
|
||||
},
|
||||
isForceLeaveWithoutHousehold() {
|
||||
return this.$store.state.forceLeaveWithoutHousehold;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
createHousehold() {
|
||||
setModeNew() {
|
||||
this.$store.dispatch('createHousehold');
|
||||
},
|
||||
forceLeaveWithoutHousehold() {
|
||||
setModeLeave() {
|
||||
this.$store.dispatch('forceLeaveWithoutHousehold');
|
||||
},
|
||||
toggleHouseholdSuggestion() {
|
||||
this.$store.commit('toggleHouseholdSuggestion');
|
||||
resetMode() {
|
||||
this.$store.commit('resetMode');
|
||||
},
|
||||
toggleAddressSuggestion() {
|
||||
this.$store.commit('toggleAddressSuggestion');
|
||||
addressChanged(payload) {
|
||||
console.log("addressChanged", payload);
|
||||
this.$store.dispatch('setHouseholdNewAddress', payload.address);
|
||||
},
|
||||
selectHousehold(h) {
|
||||
this.$store.dispatch('selectHousehold', h);
|
||||
this.toggleHouseholdSuggestion();
|
||||
},
|
||||
removeHousehold() {
|
||||
this.$store.dispatch('removeHousehold');
|
||||
},
|
||||
setHouseholdAddress(a) {
|
||||
let payload = this.$refs.addAddress.submitNewAddress();
|
||||
console.log('setHouseholdAddress', a);
|
||||
this.$store.commit('setHouseholdAddress', a);
|
||||
},
|
||||
setHouseholdCreatedAddress(payload) {
|
||||
console.log('setHouseholdAddress', payload);
|
||||
this.$store.dispatch('setHouseholdNewAddress', payload);
|
||||
},
|
||||
removeHouseholdAddress() {
|
||||
this.$store.commit('removeHouseholdAddress');
|
||||
@ -310,28 +232,4 @@ div.householdSuggestionList {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
div.householdAddressSuggestionList {
|
||||
display: flex;
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
& > li {}
|
||||
}
|
||||
.householdSuggestionList {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
& > .item {
|
||||
margin-bottom: 0.8rem;
|
||||
width: calc(50% - 1rem);
|
||||
border: 1px solid var(--chill-light-gray);
|
||||
padding: 0.5rem 0.5rem 0 0.5rem;
|
||||
ul.record_actions {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
</style>
|
||||
|
@ -7,16 +7,27 @@ const appMessages = {
|
||||
household: {
|
||||
no_household_choose_one: "Aucun ménage de destination. Choisissez un ménage. Les usagers concernés par la modification apparaitront ensuite.",
|
||||
new_household: "Nouveau ménage",
|
||||
create_household: "Créer un nouveau ménage de destination",
|
||||
create_household: "Créer",
|
||||
search_household: "Chercher un ménage",
|
||||
will_leave_any_household: "Ne rejoignent pas de ménage",
|
||||
will_leave_any_household: "Les usagers ne rejoignent pas de ménage",
|
||||
leave: "Quitter",
|
||||
will_leave_any_household_explanation: "Les usagers quitteront leur ménage actuel, et ne seront pas associés à un autre ménage. Par ailleurs, ils seront enregistrés comme étant sans adresse connue.",
|
||||
leave_without_household: "Sans nouveau ménage",
|
||||
set_address: "Indiquer une adresse",
|
||||
reset_mode: "Modifier la destination",
|
||||
remove_address: "Supprimer l'adresse",
|
||||
update_address: "Mettre à jour l'adresse",
|
||||
// remove ?
|
||||
/*
|
||||
where_live_the_household: "À quelle adresse habite ce ménage ?",
|
||||
household_live_to_this_address: "Sélectionner l'adresse",
|
||||
no_suggestions: "Aucune adresse à suggérer",
|
||||
delete_this_address: "Supprimer cette adresse",
|
||||
create_new_address: "Créer une nouvelle adresse",
|
||||
or_create_new_address: "Ou créer une nouvelle adresse",
|
||||
|
||||
*/
|
||||
// end remove ?
|
||||
},
|
||||
concerned: {
|
||||
title: "Nouveaux membres du ménage",
|
||||
@ -34,7 +45,7 @@ const appMessages = {
|
||||
is_not_holder: "N'est pas titulaire",
|
||||
remove_position: "Retirer des {position}",
|
||||
remove_concerned: "Ne plus transférer",
|
||||
household_part: "Ménage de destination",
|
||||
household_part: "Destination",
|
||||
suggestions: "Suggestions",
|
||||
hide_household_suggestion: "Masquer les suggestions",
|
||||
show_household_suggestion: 'Aucune suggestion | Afficher une suggestion | Afficher {count} suggestions',
|
||||
|
@ -29,6 +29,15 @@ const store = createStore({
|
||||
return 0;
|
||||
}),
|
||||
startDate: new Date(),
|
||||
/**
|
||||
* Indicates if the destination is:
|
||||
*
|
||||
* * "new" => a new household
|
||||
* * "existing" => an existing household
|
||||
* * "leave" => leave without household
|
||||
* * null if not set
|
||||
*/
|
||||
mode: window.household_members_editor_data.household === null ? null : "existing",
|
||||
allowHouseholdCreate: window.household_members_editor_data.allowHouseholdCreate,
|
||||
allowHouseholdSearch: window.household_members_editor_data.allowHouseholdSearch,
|
||||
allowLeaveWithoutHousehold: window.household_members_editor_data.allowLeaveWithoutHousehold,
|
||||
@ -41,11 +50,70 @@ const store = createStore({
|
||||
errors: []
|
||||
},
|
||||
getters: {
|
||||
/**
|
||||
* return true if this page allow to create a new household
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isModeNewAllowed(state) {
|
||||
return state.allowHouseholdCreate;
|
||||
},
|
||||
/**
|
||||
* return true if this page allow to "leave without household"
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isModeLeaveAllowed(state) {
|
||||
return state.allowLeaveWithoutHousehold;
|
||||
},
|
||||
/**
|
||||
* return true if the mode "leave" is selected
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isModeLeave(state) {
|
||||
return state.mode === "leave";
|
||||
},
|
||||
getSuggestions(state) {
|
||||
let suggestions = [];
|
||||
state.householdSuggestionByAccompanyingPeriod.forEach(h => {
|
||||
console.log(h);
|
||||
suggestions.push({household: h});
|
||||
});
|
||||
|
||||
return suggestions;
|
||||
},
|
||||
isHouseholdNew(state) {
|
||||
return state.mode === "new";
|
||||
/*
|
||||
if (state.household === null) {
|
||||
return false;
|
||||
}
|
||||
return !Number.isInteger(state.household.id);
|
||||
|
||||
*/
|
||||
},
|
||||
getAddressContext(state, getters) {
|
||||
if (!getters.hasHouseholdAddress) {
|
||||
return {
|
||||
edit: false,
|
||||
addressId: null,
|
||||
target: {
|
||||
name: state.household.type,
|
||||
id: state.household.id
|
||||
},
|
||||
suggestions: state.addressesSuggestion
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
edit: true,
|
||||
addressId: state.household.current_address.id,
|
||||
target: {
|
||||
name: state.household.type,
|
||||
id: state.household.id
|
||||
},
|
||||
};
|
||||
}
|
||||
},
|
||||
hasHouseholdAddress(state) {
|
||||
if (null === state.household) {
|
||||
@ -180,6 +248,11 @@ const store = createStore({
|
||||
},
|
||||
},
|
||||
mutations: {
|
||||
resetMode(state) {
|
||||
state.mode = null;
|
||||
state.household = null;
|
||||
state.forceLeaveWithoutHousehold = false;
|
||||
},
|
||||
addConcerned(state, person) {
|
||||
let persons = state.concerned.map(conc => conc.person.id);
|
||||
if (!persons.includes(person.id)) {
|
||||
@ -222,6 +295,7 @@ const store = createStore({
|
||||
current_address: null,
|
||||
current_members_id: []
|
||||
};
|
||||
state.mode = "new";
|
||||
state.forceLeaveWithoutHousehold = false;
|
||||
},
|
||||
removeHousehold(state) {
|
||||
@ -229,6 +303,7 @@ const store = createStore({
|
||||
state.forceLeaveWithoutHousehold = false;
|
||||
},
|
||||
setHouseholdAddress(state, address) {
|
||||
console.log('setHouseholdAddress commit', address);
|
||||
if (null === state.household) {
|
||||
console.error("no household");
|
||||
throw new Error("No household");
|
||||
@ -246,10 +321,12 @@ const store = createStore({
|
||||
},
|
||||
forceLeaveWithoutHousehold(state) {
|
||||
state.household = null;
|
||||
state.mode = "leave";
|
||||
state.forceLeaveWithoutHousehold = true;
|
||||
},
|
||||
selectHousehold(state, household) {
|
||||
state.household = household;
|
||||
state.mode = "existing";
|
||||
state.forceLeaveWithoutHousehold = false;
|
||||
},
|
||||
setHouseholdSuggestionByAccompanyingPeriod(state, households) {
|
||||
@ -320,18 +397,8 @@ const store = createStore({
|
||||
commit('createHousehold');
|
||||
dispatch('computeWarnings');
|
||||
},
|
||||
setHouseholdNewAddress({ commit }, payload) {
|
||||
let url = `/api/1.0/main/address/${payload.addressId}.json`;
|
||||
window.fetch(url).then(r => {
|
||||
if (r.ok) {
|
||||
return r.json();
|
||||
}
|
||||
throw new Error("error while fetch address");
|
||||
}).then(data => {
|
||||
commit('setHouseholdAddress', data);
|
||||
}).catch(e => {
|
||||
console.error(e);
|
||||
});
|
||||
setHouseholdNewAddress({ commit }, address) {
|
||||
commit('setHouseholdAddress', address);
|
||||
},
|
||||
forceLeaveWithoutHousehold({ commit, dispatch }) {
|
||||
commit('forceLeaveWithoutHousehold');
|
||||
|
@ -19,7 +19,7 @@
|
||||
"php": ">= 7.4",
|
||||
"champs-libres/wopi-bundle": "dev-master",
|
||||
"nyholm/psr7": "^1.4",
|
||||
"php-opencloud/openstack": "^3.2.1"
|
||||
"symfony/mime": "^4 || ^5"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
@ -9,9 +9,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\WopiBundle\Controller;
|
||||
|
||||
use ChampsLibres\WopiLib\Configuration\WopiConfigurationInterface;
|
||||
use ChampsLibres\WopiLib\Discovery\WopiDiscoveryInterface;
|
||||
use Chill\DocStoreBundle\Repository\StoredObjectRepository;
|
||||
use ChampsLibres\WopiLib\Contract\Service\Configuration\ConfigurationInterface;
|
||||
use ChampsLibres\WopiLib\Contract\Service\Discovery\DiscoveryInterface;
|
||||
use ChampsLibres\WopiLib\Contract\Service\DocumentManagerInterface;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\WopiBundle\Service\Controller\ResponderInterface;
|
||||
use Exception;
|
||||
use loophp\psr17\Psr17Interface;
|
||||
@ -23,11 +24,11 @@ use Symfony\Component\Security\Core\Security;
|
||||
|
||||
final class Test
|
||||
{
|
||||
private StoredObjectRepository $storedObjectRepository;
|
||||
private DiscoveryInterface $wopiDiscovery;
|
||||
|
||||
private WopiDiscoveryInterface $wopiDiscovery;
|
||||
private DocumentManagerInterface $documentManager;
|
||||
|
||||
private WopiConfigurationInterface $wopiConfiguration;
|
||||
private ConfigurationInterface $wopiConfiguration;
|
||||
|
||||
private ResponderInterface $responder;
|
||||
|
||||
@ -38,15 +39,15 @@ final class Test
|
||||
private RouterInterface $router;
|
||||
|
||||
public function __construct(
|
||||
StoredObjectRepository $storedObjectRepository,
|
||||
WopiConfigurationInterface $wopiConfiguration,
|
||||
WopiDiscoveryInterface $wopiDiscovery,
|
||||
ConfigurationInterface $wopiConfiguration,
|
||||
DiscoveryInterface $wopiDiscovery,
|
||||
DocumentManagerInterface $documentManager,
|
||||
ResponderInterface $responder,
|
||||
Security $security,
|
||||
Psr17Interface $psr17,
|
||||
RouterInterface $router
|
||||
) {
|
||||
$this->storedObjectRepository = $storedObjectRepository;
|
||||
$this->documentManager = $documentManager;
|
||||
$this->wopiConfiguration = $wopiConfiguration;
|
||||
$this->wopiDiscovery = $wopiDiscovery;
|
||||
$this->responder = $responder;
|
||||
@ -58,11 +59,11 @@ final class Test
|
||||
public function __invoke(string $fileId): Response
|
||||
{
|
||||
$configuration = $this->wopiConfiguration->jsonSerialize();
|
||||
|
||||
$storedObject = $this->storedObjectRepository->findOneBy(['filename' => $fileId]);
|
||||
/** @var StoredObject $storedObject */
|
||||
$storedObject = $this->documentManager->findByDocumentId($fileId);
|
||||
|
||||
if (null === $storedObject) {
|
||||
throw new NotFoundHttpException(sprintf('Unable to find object named %s', $fileId));
|
||||
throw new NotFoundHttpException(sprintf('Unable to find object %s', $fileId));
|
||||
}
|
||||
|
||||
if ([] === $discoverExtension = $this->wopiDiscovery->discoverMimeType($storedObject->getType())) {
|
||||
@ -83,7 +84,7 @@ final class Test
|
||||
->generate(
|
||||
'checkFileInfo',
|
||||
[
|
||||
'fileId' => $storedObject->getFilename(),
|
||||
'fileId' => $this->documentManager->getDocumentId($storedObject),
|
||||
],
|
||||
UrlGeneratorInterface::ABSOLUTE_URL
|
||||
),
|
||||
|
@ -10,8 +10,10 @@ declare(strict_types=1);
|
||||
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
|
||||
|
||||
use ChampsLibres\AsyncUploaderBundle\TempUrl\TempUrlGeneratorInterface;
|
||||
use ChampsLibres\WopiLib\Service\Contract\WopiInterface;
|
||||
use Chill\WopiBundle\Service\Wopi\ChillWopi;
|
||||
use ChampsLibres\WopiBundle\Service\Wopi as CLWopi;
|
||||
use ChampsLibres\WopiLib\Contract\Service\DocumentManagerInterface;
|
||||
use Chill\WopiBundle\Service\Wopi\ChillDocumentManager;
|
||||
|
||||
return static function (ContainerConfigurator $container) {
|
||||
$services = $container
|
||||
@ -30,8 +32,14 @@ return static function (ContainerConfigurator $container) {
|
||||
->tag('controller.service_arguments');
|
||||
|
||||
$services
|
||||
->alias(WopiInterface::class, ChillWopi::class);
|
||||
->set(ChillWopi::class)
|
||||
->decorate(CLWopi::class)
|
||||
->arg('$wopi', service('.inner'));
|
||||
|
||||
$services
|
||||
->alias(DocumentManagerInterface::class, ChillDocumentManager::class);
|
||||
|
||||
// TODO: Move this into the async bundle (low priority)
|
||||
$services
|
||||
->alias(TempUrlGeneratorInterface::class, 'async_uploader.temp_url_generator');
|
||||
};
|
||||
|
@ -0,0 +1,244 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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\WopiBundle\Service\Wopi;
|
||||
|
||||
use ChampsLibres\AsyncUploaderBundle\TempUrl\TempUrlGeneratorInterface;
|
||||
use ChampsLibres\WopiLib\Contract\Entity\Document;
|
||||
use ChampsLibres\WopiLib\Contract\Service\DocumentLockManagerInterface;
|
||||
use ChampsLibres\WopiLib\Contract\Service\DocumentManagerInterface;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\DocStoreBundle\Repository\StoredObjectRepository;
|
||||
use DateTimeInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Error;
|
||||
use loophp\psr17\Psr17Interface;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\Mime\MimeTypes;
|
||||
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
use Throwable;
|
||||
|
||||
final class ChillDocumentManager implements DocumentManagerInterface
|
||||
{
|
||||
private DocumentLockManagerInterface $documentLockManager;
|
||||
|
||||
private EntityManagerInterface $entityManager;
|
||||
|
||||
private HttpClientInterface $httpClient;
|
||||
|
||||
private Psr17Interface $psr17;
|
||||
|
||||
private RequestInterface $request;
|
||||
|
||||
private StoredObjectRepository $storedObjectRepository;
|
||||
|
||||
private TempUrlGeneratorInterface $tempUrlGenerator;
|
||||
|
||||
public function __construct(
|
||||
DocumentLockManagerInterface $documentLockManager,
|
||||
EntityManagerInterface $entityManager,
|
||||
HttpClientInterface $httpClient,
|
||||
Psr17Interface $psr17,
|
||||
StoredObjectRepository $storedObjectRepository,
|
||||
TempUrlGeneratorInterface $tempUrlGenerator,
|
||||
HttpMessageFactoryInterface $httpMessageFactory,
|
||||
RequestStack $requestStack
|
||||
) {
|
||||
$this->entityManager = $entityManager;
|
||||
$this->psr17 = $psr17;
|
||||
$this->storedObjectRepository = $storedObjectRepository;
|
||||
$this->documentLockManager = $documentLockManager;
|
||||
$this->tempUrlGenerator = $tempUrlGenerator;
|
||||
$this->httpClient = $httpClient;
|
||||
$this->request = $httpMessageFactory->createRequest($requestStack->getCurrentRequest());
|
||||
}
|
||||
|
||||
public function create(array $data): Document
|
||||
{
|
||||
/** @var StoredObject $document */
|
||||
$document = (new ObjectNormalizer())->denormalize([], StoredObject::class);
|
||||
|
||||
// Mime types / extension handling.
|
||||
$mimeTypes = new MimeTypes();
|
||||
$mimeTypes->getMimeTypes($data['extension']);
|
||||
$document->setType(reset($mimeTypes));
|
||||
|
||||
$document->setFilename($data['name']);
|
||||
|
||||
$this->entityManager->persist($document);
|
||||
$this->entityManager->flush($document);
|
||||
|
||||
// TODO : Ask proper mapping.
|
||||
// Available: basename, name, extension, content, size
|
||||
$this->setContent($document, $data['content']);
|
||||
|
||||
return $document;
|
||||
}
|
||||
|
||||
public function deleteLock(Document $document): void {
|
||||
$this->documentLockManager->deleteLock($document, $this->request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $documentFilename without extension !
|
||||
*/
|
||||
public function findByDocumentFilename(string $documentFilename): ?Document {
|
||||
return $this->storedObjectRepository->findOneBy(
|
||||
[
|
||||
'filename' => $documentFilename,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function findByDocumentId(string $documentId): ?Document {
|
||||
return $this->storedObjectRepository->findOneBy(
|
||||
[
|
||||
'uuid' => Uuid::fromString($documentId),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StoredObject $document
|
||||
*/
|
||||
public function getCreationDate(Document $document): DateTimeInterface
|
||||
{
|
||||
return $document->getCreationDate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StoredObject $document
|
||||
*/
|
||||
public function getLastModifiedDate(Document $document): DateTimeInterface
|
||||
{
|
||||
// TODO: Add column 'LastModifiedDate' in StoredObject entity
|
||||
return $document->getCreationDate();
|
||||
}
|
||||
|
||||
public function getLock(Document $document): string {
|
||||
return $this->documentLockManager->getLock($document, $this->request);
|
||||
}
|
||||
|
||||
public function getVersion(Document $document): string {
|
||||
// TODO ?
|
||||
return '0';
|
||||
}
|
||||
|
||||
public function hasLock(Document $document): bool {
|
||||
return $this->documentLockManager->hasLock($document, $this->request);
|
||||
}
|
||||
|
||||
public function lock(Document $document, string $lock): void {
|
||||
$this->documentLockManager->setLock($document, $lock, $this->request);
|
||||
}
|
||||
|
||||
public function remove(Document $document): void {
|
||||
$entityIsDeleted = false;
|
||||
|
||||
try {
|
||||
$this->entityManager->remove($document);
|
||||
$entityIsDeleted = true;
|
||||
} catch (Throwable $e) {
|
||||
$entityIsDeleted = false;
|
||||
}
|
||||
|
||||
if ($entityIsDeleted === true) {
|
||||
$this->deleteContent($document);
|
||||
}
|
||||
}
|
||||
|
||||
public function write(Document $document, array $properties = []): void
|
||||
{
|
||||
$this->setContent($document, $properties['content']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StoredObject $document
|
||||
*
|
||||
* @return string The document filename with its extension.
|
||||
*/
|
||||
public function getBasename(Document $document): string {
|
||||
$exts = (new MimeTypes())->getExtensions($document->getType());
|
||||
|
||||
if ([] === $exts) {
|
||||
throw new Error('Unknown mimetype for stored document.');
|
||||
}
|
||||
|
||||
return sprintf('%s.%s', $document->getFilename(), reset($exts));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StoredObject $document
|
||||
*/
|
||||
public function getDocumentId(Document $document): string {
|
||||
return (string) $document->getUuid();
|
||||
}
|
||||
|
||||
public function getSha256(Document $document): string {
|
||||
return base64_encode(hash('sha256', $this->getContent($document)));
|
||||
}
|
||||
|
||||
public function getSize(Document $document): int {
|
||||
return strlen($this->getContent());
|
||||
}
|
||||
|
||||
public function read(Document $document): StreamInterface {
|
||||
return $this
|
||||
->psr17
|
||||
->createStream($this->getContent($document));
|
||||
}
|
||||
|
||||
private function deleteContent(StoredObject $storedObject): void
|
||||
{
|
||||
/** @var StdClass $object */
|
||||
$object = $this->tempUrlGenerator->generate('DELETE', $storedObject->getFilename());
|
||||
|
||||
$response = $this->httpClient->request('DELETE', $object->url);
|
||||
|
||||
if (200 !== $response->getStatusCode())
|
||||
{
|
||||
throw new Error('Unable to delete stored object.');
|
||||
}
|
||||
}
|
||||
|
||||
private function getContent(StoredObject $storedObject): string
|
||||
{
|
||||
/** @var StdClass $object */
|
||||
$object = $this->tempUrlGenerator->generate('GET', $storedObject->getFilename());
|
||||
|
||||
$response = $this->httpClient->request('GET', $object->url);
|
||||
|
||||
if (200 !== $response->getStatusCode())
|
||||
{
|
||||
throw new Error('Unable to retrieve stored object.');
|
||||
}
|
||||
|
||||
return $response->getContent();
|
||||
}
|
||||
|
||||
private function setContent(StoredObject $storedObject, string $content): void
|
||||
{
|
||||
// TODO: Add strict typing in champs-libres/async-uploader-bundle
|
||||
/** @var StdClass $object */
|
||||
$object = $this->tempUrlGenerator->generate('PUT', $storedObject->getFilename());
|
||||
|
||||
$response = $this->httpClient->request('PUT', $object->url, ['body' => $content]);
|
||||
|
||||
if (201 !== $response->getStatusCode())
|
||||
{
|
||||
throw new Error('Unable to save stored object.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -9,13 +9,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\WopiBundle\Service\Wopi;
|
||||
|
||||
use ChampsLibres\AsyncUploaderBundle\TempUrl\TempUrlGeneratorInterface;
|
||||
use ChampsLibres\WopiLib\Discovery\WopiDiscoveryInterface;
|
||||
use ChampsLibres\WopiLib\Service\Contract\WopiInterface;
|
||||
use Chill\DocStoreBundle\Repository\StoredObjectRepository;
|
||||
use Exception;
|
||||
use ChampsLibres\WopiLib\Contract\Service\DocumentManagerInterface;
|
||||
use ChampsLibres\WopiLib\Contract\Service\WopiInterface;
|
||||
use loophp\psr17\Psr17Interface;
|
||||
use Psr\Http\Client\ClientInterface;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
|
||||
@ -23,32 +20,28 @@ use Symfony\Component\Security\Core\User\UserProviderInterface;
|
||||
|
||||
final class ChillWopi implements WopiInterface
|
||||
{
|
||||
private CacheItemPoolInterface $cache;
|
||||
|
||||
private DocumentManagerInterface $documentManager;
|
||||
|
||||
private Psr17Interface $psr17;
|
||||
|
||||
private WopiDiscoveryInterface $wopiDiscovery;
|
||||
|
||||
private StoredObjectRepository $storedObjectRepository;
|
||||
|
||||
private ClientInterface $httpClient;
|
||||
|
||||
private TempUrlGeneratorInterface $tempUrlGenerator;
|
||||
|
||||
private UserProviderInterface $userProvider;
|
||||
|
||||
private WopiInterface $wopi;
|
||||
|
||||
public function __construct(
|
||||
CacheItemPoolInterface $cache,
|
||||
DocumentManagerInterface $documentManager,
|
||||
Psr17Interface $psr17,
|
||||
WopiDiscoveryInterface $wopiDiscovery,
|
||||
StoredObjectRepository $storedObjectRepository,
|
||||
ClientInterface $httpClient,
|
||||
TempUrlGeneratorInterface $tempUrlGenerator,
|
||||
UserProviderInterface $userProvider
|
||||
UserProviderInterface $userProvider,
|
||||
WopiInterface $wopi
|
||||
) {
|
||||
$this->cache = $cache;
|
||||
$this->documentManager = $documentManager;
|
||||
$this->psr17 = $psr17;
|
||||
$this->wopiDiscovery = $wopiDiscovery;
|
||||
$this->storedObjectRepository = $storedObjectRepository;
|
||||
$this->httpClient = $httpClient;
|
||||
$this->tempUrlGenerator = $tempUrlGenerator;
|
||||
$this->userProvider = $userProvider;
|
||||
$this->wopi = $wopi;
|
||||
}
|
||||
|
||||
public function checkFileInfo(
|
||||
@ -64,17 +57,10 @@ final class ChillWopi implements WopiInterface
|
||||
->createResponse(401);
|
||||
}
|
||||
|
||||
$storedObject = $this->storedObjectRepository->findOneBy(['filename' => $fileId]);
|
||||
|
||||
if (null === $storedObject) {
|
||||
throw new Exception(sprintf('Unable to find object named %s', $fileId));
|
||||
}
|
||||
|
||||
$mimeType = $storedObject->getType();
|
||||
|
||||
if ([] === $this->wopiDiscovery->discoverMimeType($mimeType)) {
|
||||
throw new Exception(sprintf('Unable to find mime type %s', $mimeType));
|
||||
}
|
||||
// @ TODO : Replace this with a call to decorated object once authentication is done.
|
||||
$document = $this->documentManager->findByDocumentId($fileId);
|
||||
$userIdentifier = $user->getUsername();
|
||||
$userCacheKey = sprintf('wopi_putUserInfo_%s', $userIdentifier);
|
||||
|
||||
return $this
|
||||
->psr17
|
||||
@ -82,33 +68,38 @@ final class ChillWopi implements WopiInterface
|
||||
->withHeader('Content-Type', 'application/json')
|
||||
->withBody($this->psr17->createStream((string) json_encode(
|
||||
[
|
||||
'BaseFileName' => $storedObject->getFilename(),
|
||||
'OwnerId' => uniqid(),
|
||||
'Size' => 0,
|
||||
'UserId' => uniqid(),
|
||||
// 'Version' => 'v' . uniqid(),
|
||||
'BaseFileName' => $this->documentManager->getBasename($document),
|
||||
'OwnerId' => 'Symfony',
|
||||
'Size' => $this->documentManager->getSize($document),
|
||||
'UserId' => $userIdentifier,
|
||||
'ReadOnly' => false,
|
||||
'UserCanAttend' => true,
|
||||
'UserCanPresent' => true,
|
||||
'UserCanRename' => true,
|
||||
'UserCanWrite' => true,
|
||||
'UserCanNotWriteRelative' => true,
|
||||
'SupportsLocks' => false,
|
||||
'UserFriendlyName' => sprintf('User %s', $user->getUsername()),
|
||||
'UserExtraInfo' => [],
|
||||
'LastModifiedTime' => date('Y-m-d\TH:i:s.u\Z', $storedObject->getCreationDate()->getTimestamp()),
|
||||
'CloseButtonClosesWindow' => true,
|
||||
'EnableInsertRemoteImage' => true,
|
||||
'EnableShare' => false,
|
||||
'UserCanNotWriteRelative' => false,
|
||||
'SupportsUserInfo' => true,
|
||||
'SupportsDeleteFile' => true,
|
||||
'SupportsLocks' => true,
|
||||
'SupportsGetLock' => true,
|
||||
'SupportsExtendedLockLength' => true,
|
||||
'UserFriendlyName' => $userIdentifier,
|
||||
'SupportsUpdate' => true,
|
||||
'SupportsRename' => false,
|
||||
'SupportsRename' => true,
|
||||
'DisablePrint' => false,
|
||||
'DisableExport' => false,
|
||||
'DisableCopy' => false,
|
||||
'AllowExternalMarketplace' => true,
|
||||
'SupportedShareUrlTypes' => [
|
||||
'ReadOnly',
|
||||
],
|
||||
'SHA256' => $this->documentManager->getSha256($document),
|
||||
'UserInfo' => (string) $this->cache->getItem($userCacheKey)->get(),
|
||||
]
|
||||
)));
|
||||
}
|
||||
|
||||
public function deleteFile(string $fileId, ?string $accessToken, RequestInterface $request): ResponseInterface
|
||||
{
|
||||
return $this->getDebugResponse(__FUNCTION__, $request);
|
||||
return $this->wopi->deleteFile($fileId, $accessToken, $request);
|
||||
}
|
||||
|
||||
public function enumerateAncestors(
|
||||
@ -116,57 +107,17 @@ final class ChillWopi implements WopiInterface
|
||||
?string $accessToken,
|
||||
RequestInterface $request
|
||||
): ResponseInterface {
|
||||
return $this->getDebugResponse(__FUNCTION__, $request);
|
||||
return $this->wopi->enumerateAncestors($fileId, $accessToken, $request);
|
||||
}
|
||||
|
||||
public function getFile(string $fileId, ?string $accessToken, RequestInterface $request): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$user = $this->userProvider->loadUserByUsername($accessToken);
|
||||
} catch (UsernameNotFoundException $e) {
|
||||
return $this
|
||||
->psr17
|
||||
->createResponse(401);
|
||||
}
|
||||
|
||||
$storedObject = $this->storedObjectRepository->findOneBy(['filename' => $fileId]);
|
||||
|
||||
if (null === $storedObject) {
|
||||
return $this
|
||||
->psr17
|
||||
->createResponse(404);
|
||||
}
|
||||
|
||||
// TODO: Add strict typing in champs-libres/async-uploader-bundle
|
||||
/** @var StdClass $object */
|
||||
$object = $this->tempUrlGenerator->generate('GET', $storedObject->getFilename());
|
||||
|
||||
$response = $this->httpClient->sendRequest($this->psr17->createRequest('GET', $object->url));
|
||||
|
||||
if (200 !== $response->getStatusCode())
|
||||
{
|
||||
return $this
|
||||
->psr17
|
||||
->createResponse(500);
|
||||
}
|
||||
|
||||
return $this
|
||||
->psr17
|
||||
->createResponse()
|
||||
->withHeader(
|
||||
'Content-Type',
|
||||
'application/octet-stream',
|
||||
)
|
||||
->withHeader(
|
||||
'Content-Disposition',
|
||||
sprintf('attachment; filename=%s', $storedObject->getFilename())
|
||||
)
|
||||
->withBody($response->getBody());
|
||||
return $this->wopi->getFile($fileId, $accessToken, $request);
|
||||
}
|
||||
|
||||
public function getLock(string $fileId, ?string $accessToken, RequestInterface $request): ResponseInterface
|
||||
{
|
||||
return $this->getDebugResponse(__FUNCTION__, $request);
|
||||
return $this->wopi->getLock($fileId, $accessToken, $request);
|
||||
}
|
||||
|
||||
public function getShareUrl(
|
||||
@ -174,7 +125,7 @@ final class ChillWopi implements WopiInterface
|
||||
?string $accessToken,
|
||||
RequestInterface $request
|
||||
): ResponseInterface {
|
||||
return $this->getDebugResponse(__FUNCTION__, $request);
|
||||
return $this->wopi->getShareUrl($fileId, $accessToken, $request);
|
||||
}
|
||||
|
||||
public function lock(
|
||||
@ -183,7 +134,7 @@ final class ChillWopi implements WopiInterface
|
||||
string $xWopiLock,
|
||||
RequestInterface $request
|
||||
): ResponseInterface {
|
||||
return $this->getDebugResponse(__FUNCTION__, $request);
|
||||
return $this->wopi->lock($fileId, $accessToken, $xWopiLock, $request);
|
||||
}
|
||||
|
||||
public function putFile(
|
||||
@ -193,49 +144,17 @@ final class ChillWopi implements WopiInterface
|
||||
string $xWopiEditors,
|
||||
RequestInterface $request
|
||||
): ResponseInterface {
|
||||
try {
|
||||
$user = $this->userProvider->loadUserByUsername($accessToken);
|
||||
} catch (UsernameNotFoundException $e) {
|
||||
return $this
|
||||
->psr17
|
||||
->createResponse(401);
|
||||
}
|
||||
|
||||
$storedObject = $this->storedObjectRepository->findOneBy(['filename' => $fileId]);
|
||||
|
||||
if (null === $storedObject) {
|
||||
throw new Exception(sprintf('Unable to find object named %s', $fileId));
|
||||
}
|
||||
|
||||
// TODO: Add strict typing in champs-libres/async-uploader-bundle
|
||||
/** @var StdClass $object */
|
||||
$object = $this->tempUrlGenerator->generate('PUT', $storedObject->getFilename());
|
||||
|
||||
$response = $this->httpClient->sendRequest($this->psr17->createRequest('PUT', $object->url)->withBody($request->getBody()));
|
||||
|
||||
if (201 !== $response->getStatusCode())
|
||||
{
|
||||
return $this
|
||||
->psr17
|
||||
->createResponse(500);
|
||||
}
|
||||
|
||||
return $this
|
||||
->psr17
|
||||
->createResponse()
|
||||
->withHeader('Content-Type', 'application/json')
|
||||
->withAddedHeader('X-WOPI-Lock', $xWopiLock)
|
||||
->withBody($this->psr17->createStream((string) json_encode([])));
|
||||
return $this->wopi->putFile($fileId, $accessToken, $xWopiLock, $xWopiEditors, $request);
|
||||
}
|
||||
|
||||
public function putRelativeFile(string $fileId, string $accessToken, ?string $suggestedTarget, ?string $relativeTarget, bool $overwriteRelativeTarget, int $size, RequestInterface $request): ResponseInterface
|
||||
{
|
||||
return $this->getDebugResponse(__FUNCTION__, $request);
|
||||
return $this->wopi->putRelativeFile($fileId, $accessToken, $suggestedTarget, $relativeTarget, $overwriteRelativeTarget, $size, $request);
|
||||
}
|
||||
|
||||
public function putUserInfo(string $fileId, ?string $accessToken, RequestInterface $request): ResponseInterface
|
||||
{
|
||||
return $this->getDebugResponse(__FUNCTION__, $request);
|
||||
return $this->wopi->putUserInfo($fileId, $accessToken, $request);
|
||||
}
|
||||
|
||||
public function refreshLock(
|
||||
@ -244,7 +163,7 @@ final class ChillWopi implements WopiInterface
|
||||
string $xWopiLock,
|
||||
RequestInterface $request
|
||||
): ResponseInterface {
|
||||
return $this->getDebugResponse(__FUNCTION__, $request);
|
||||
return $this->wopi->refreshLock($fileId, $accessToken, $xWopiLock, $request);
|
||||
}
|
||||
|
||||
public function renameFile(
|
||||
@ -254,7 +173,7 @@ final class ChillWopi implements WopiInterface
|
||||
string $xWopiRequestedName,
|
||||
RequestInterface $request
|
||||
): ResponseInterface {
|
||||
return $this->getDebugResponse(__FUNCTION__, $request);
|
||||
return $this->wopi->renameFile($fileId, $accessToken, $xWopiLock, $xWopiRequestedName, $request);
|
||||
}
|
||||
|
||||
public function unlock(
|
||||
@ -263,7 +182,7 @@ final class ChillWopi implements WopiInterface
|
||||
string $xWopiLock,
|
||||
RequestInterface $request
|
||||
): ResponseInterface {
|
||||
return $this->getDebugResponse(__FUNCTION__, $request);
|
||||
return $this->wopi->unlock($fileId, $accessToken, $xWopiLock, $request);
|
||||
}
|
||||
|
||||
public function unlockAndRelock(
|
||||
@ -273,33 +192,6 @@ final class ChillWopi implements WopiInterface
|
||||
string $xWopiOldLock,
|
||||
RequestInterface $request
|
||||
): ResponseInterface {
|
||||
return $this->getDebugResponse(__FUNCTION__, $request);
|
||||
}
|
||||
|
||||
private function getDebugResponse(string $method, RequestInterface $request): ResponseInterface
|
||||
{
|
||||
$params = [];
|
||||
parse_str($request->getUri()->getQuery(), $params);
|
||||
|
||||
$data = (string) json_encode(array_merge(
|
||||
['method' => $method],
|
||||
$params,
|
||||
$request->getHeaders()
|
||||
));
|
||||
|
||||
return $this
|
||||
->psr17
|
||||
->createResponse()
|
||||
->withHeader('content', 'application/json')
|
||||
->withBody($this->psr17->createStream($data));
|
||||
}
|
||||
|
||||
private function getLockFilepath(string $fileId): string
|
||||
{
|
||||
return sprintf(
|
||||
'%s/%s.lock',
|
||||
$this->filesRepository,
|
||||
$fileId
|
||||
);
|
||||
return $this->wopi->unlockAndRelock($fileId, $accessToken, $xWopiLock, $xWopiOldLock, $request);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user