mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +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
|
end_of_line = LF
|
||||||
insert_final_newline = true
|
insert_final_newline = true
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
|
indent_size = 4
|
||||||
|
|
||||||
[*.{php,html,twig}]
|
[*.{php,html,twig}]
|
||||||
indent_style = space
|
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",
|
"league/csv": "^9.7.1",
|
||||||
"nyholm/psr7": "^1.4",
|
"nyholm/psr7": "^1.4",
|
||||||
"phpoffice/phpspreadsheet": "^1.16",
|
"phpoffice/phpspreadsheet": "^1.16",
|
||||||
|
"ramsey/uuid-doctrine": "^1.7",
|
||||||
"sensio/framework-extra-bundle": "^5.5",
|
"sensio/framework-extra-bundle": "^5.5",
|
||||||
"symfony/asset": "4.*",
|
"symfony/asset": "4.*",
|
||||||
"symfony/browser-kit": "^5.2",
|
"symfony/browser-kit": "^5.2",
|
||||||
@ -29,6 +30,7 @@
|
|||||||
"symfony/expression-language": "4.*",
|
"symfony/expression-language": "4.*",
|
||||||
"symfony/form": "4.*",
|
"symfony/form": "4.*",
|
||||||
"symfony/intl": "4.*",
|
"symfony/intl": "4.*",
|
||||||
|
"symfony/mime": "^4 || ^5",
|
||||||
"symfony/monolog-bundle": "^3.5",
|
"symfony/monolog-bundle": "^3.5",
|
||||||
"symfony/security-bundle": "4.*",
|
"symfony/security-bundle": "4.*",
|
||||||
"symfony/serializer": "^5.2",
|
"symfony/serializer": "^5.2",
|
||||||
|
@ -29,17 +29,19 @@ class ListenToActivityCreate
|
|||||||
$activityData = $request->query->get('activityData');
|
$activityData = $request->query->get('activityData');
|
||||||
if (array_key_exists('calendarId', $activityData)) {
|
if (array_key_exists('calendarId', $activityData)) {
|
||||||
$calendarId = $activityData['calendarId'];
|
$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' => [
|
'routeParameters' => [
|
||||||
'accompanying_period_id' => $period->getId(),
|
'accompanying_period_id' => $period->getId(),
|
||||||
]])
|
]])
|
||||||
->setExtras(['order' => 41]);
|
->setExtras(['order' => 35]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ class DocGeneratorTemplateController extends AbstractController
|
|||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
return $this->redirectToRoute('chill_wopi_file_edit', [
|
return $this->redirectToRoute('chill_wopi_file_edit', [
|
||||||
'fileId' => $genDocName,
|
'fileId' => $storedObject->getUuid(),
|
||||||
'returnPath' => $request->query->get('returnPath', "/")
|
'returnPath' => $request->query->get('returnPath', "/")
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,10 @@ namespace Chill\DocStoreBundle\Entity;
|
|||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use ChampsLibres\AsyncUploaderBundle\Model\AsyncFileInterface;
|
use ChampsLibres\AsyncUploaderBundle\Model\AsyncFileInterface;
|
||||||
use ChampsLibres\AsyncUploaderBundle\Validator\Constraints\AsyncFileExists;
|
use ChampsLibres\AsyncUploaderBundle\Validator\Constraints\AsyncFileExists;
|
||||||
|
use ChampsLibres\WopiLib\Contract\Entity\Document;
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
|
use Ramsey\Uuid\Uuid;
|
||||||
|
use Ramsey\Uuid\UuidInterface;
|
||||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
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"
|
* message="The file is not stored properly"
|
||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
class StoredObject implements AsyncFileInterface
|
class StoredObject implements AsyncFileInterface, Document
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @ORM\Id()
|
* @ORM\Id()
|
||||||
@ -47,6 +50,12 @@ class StoredObject implements AsyncFileInterface
|
|||||||
*/
|
*/
|
||||||
private array $iv = [];
|
private array $iv = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="uuid", unique=true)
|
||||||
|
* @Serializer\Groups({"read"})
|
||||||
|
*/
|
||||||
|
private UuidInterface $uuid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="datetime", name="creation_date")
|
* @ORM\Column(type="datetime", name="creation_date")
|
||||||
* @Serializer\Groups({"read"})
|
* @Serializer\Groups({"read"})
|
||||||
@ -68,6 +77,7 @@ class StoredObject implements AsyncFileInterface
|
|||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->creationDate = new \DateTime();
|
$this->creationDate = new \DateTime();
|
||||||
|
$this->uuid = Uuid::uuid4();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getId()
|
public function getId()
|
||||||
@ -155,5 +165,13 @@ class StoredObject implements AsyncFileInterface
|
|||||||
return $this;
|
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",
|
"description": "A Chill bundle to store documents",
|
||||||
"type": "symfony-bundle",
|
"type": "symfony-bundle",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": { "Chill\\DocStoreBundle\\" : "" }
|
"psr-4": {
|
||||||
|
"Chill\\DocStoreBundle\\": ""
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
"symfony/mime": "^4 || ^5"
|
||||||
},
|
},
|
||||||
"license": "AGPL-3.0"
|
"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;
|
namespace Chill\MainBundle\DependencyInjection;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Controller\AddressApiController;
|
||||||
use Chill\MainBundle\Controller\UserController;
|
use Chill\MainBundle\Controller\UserController;
|
||||||
use Chill\MainBundle\Doctrine\DQL\STContains;
|
use Chill\MainBundle\Doctrine\DQL\STContains;
|
||||||
use Chill\MainBundle\Doctrine\DQL\StrictWordSimilarityOPS;
|
use Chill\MainBundle\Doctrine\DQL\StrictWordSimilarityOPS;
|
||||||
@ -319,6 +320,7 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
|||||||
'apis' => [
|
'apis' => [
|
||||||
[
|
[
|
||||||
'class' => \Chill\MainBundle\Entity\Address::class,
|
'class' => \Chill\MainBundle\Entity\Address::class,
|
||||||
|
'controller' => AddressApiController::class,
|
||||||
'name' => 'address',
|
'name' => 'address',
|
||||||
'base_path' => '/api/1.0/main/address',
|
'base_path' => '/api/1.0/main/address',
|
||||||
'base_role' => 'ROLE_USER',
|
'base_role' => 'ROLE_USER',
|
||||||
|
@ -376,10 +376,22 @@ class Address
|
|||||||
public static function createFromAddress(Address $original) : Address
|
public static function createFromAddress(Address $original) : Address
|
||||||
{
|
{
|
||||||
return (new 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())
|
->setPostcode($original->getPostcode())
|
||||||
->setStreetAddress1($original->getStreetAddress1())
|
->setSteps($original->getSteps())
|
||||||
->setStreetAddress2($original->getStreetAddress2())
|
->setStreet($original->getStreet())
|
||||||
|
->setStreetNumber($original->getStreetNumber())
|
||||||
->setValidFrom($original->getValidFrom())
|
->setValidFrom($original->getValidFrom())
|
||||||
|
->setValidTo($original->getValidTo())
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -506,7 +518,7 @@ class Address
|
|||||||
return $this->validTo;
|
return $this->validTo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setValidTo(\DateTimeInterface $validTo): self
|
public function setValidTo(?\DateTimeInterface $validTo = null): self
|
||||||
{
|
{
|
||||||
$this->validTo = $validTo;
|
$this->validTo = $validTo;
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ namespace Chill\MainBundle\Repository;
|
|||||||
use Chill\MainBundle\Entity\Address;
|
use Chill\MainBundle\Entity\Address;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\ORM\EntityRepository;
|
use Doctrine\ORM\EntityRepository;
|
||||||
|
use Doctrine\ORM\QueryBuilder;
|
||||||
use Doctrine\Persistence\ObjectRepository;
|
use Doctrine\Persistence\ObjectRepository;
|
||||||
|
|
||||||
final class AddressRepository implements ObjectRepository
|
final class AddressRepository implements ObjectRepository
|
||||||
@ -47,4 +48,9 @@ final class AddressRepository implements ObjectRepository
|
|||||||
public function getClassName() {
|
public function getClassName() {
|
||||||
return Address::class;
|
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
|
* Endpoint chill_api_single_country__index
|
||||||
* method GET, get Country Object
|
* method GET, get Country Object
|
||||||
* @returns {Promise} a promise containing all Country object
|
* @returns {Promise} a promise containing all Country object
|
||||||
@ -14,7 +14,7 @@ const fetchCountries = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Endpoint chill_api_single_postal_code__index
|
* Endpoint chill_api_single_postal_code__index
|
||||||
* method GET, get Country Object
|
* method GET, get Country Object
|
||||||
* @returns {Promise} a promise containing all Postal Code objects filtered with country
|
* @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
|
* Endpoint chill_api_single_address_reference__index
|
||||||
* method GET, get AddressReference Object
|
* method GET, get AddressReference Object
|
||||||
* @returns {Promise} a promise containing all AddressReference objects filtered with postal code
|
* @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
|
* Endpoint chill_api_single_address_reference__index
|
||||||
* method GET, get AddressReference Object
|
* method GET, get AddressReference Object
|
||||||
* @returns {Promise} a promise containing all AddressReference objects filtered with postal code
|
* @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
|
* Endpoint chill_api_single_address__entity__create
|
||||||
* method POST, post Address Object
|
* method POST, post Address Object
|
||||||
* @returns {Promise}
|
* @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
|
* Endpoint chill_api_single_address__entity__create
|
||||||
* method PATCH, patch Address Instance
|
* method PATCH, patch Address Instance
|
||||||
*
|
*
|
||||||
@ -142,6 +162,7 @@ const getAddress = (id) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
duplicateAddress,
|
||||||
fetchCountries,
|
fetchCountries,
|
||||||
fetchCities,
|
fetchCities,
|
||||||
fetchReferenceAddresses,
|
fetchReferenceAddresses,
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
v-bind:defaultz="this.defaultz"
|
v-bind:defaultz="this.defaultz"
|
||||||
v-bind:entity="this.entity"
|
v-bind:entity="this.entity"
|
||||||
v-bind:flag="this.flag"
|
v-bind:flag="this.flag"
|
||||||
|
@pick-address="this.pickAddress"
|
||||||
ref="suggestAddress">
|
ref="suggestAddress">
|
||||||
</suggest-pane>
|
</suggest-pane>
|
||||||
</template>
|
</template>
|
||||||
@ -55,6 +56,7 @@
|
|||||||
v-bind:entity="this.entity"
|
v-bind:entity="this.entity"
|
||||||
v-bind:flag="this.flag"
|
v-bind:flag="this.flag"
|
||||||
v-bind:insideModal="false"
|
v-bind:insideModal="false"
|
||||||
|
@pick-address="this.pickAddress"
|
||||||
ref="suggestAddress">
|
ref="suggestAddress">
|
||||||
|
|
||||||
<template v-slot:before v-if="!bypassFirstStep">
|
<template v-slot:before v-if="!bypassFirstStep">
|
||||||
@ -217,7 +219,16 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Modal from 'ChillMainAssets/vuejs/_components/Modal';
|
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 { postAddressToPerson, postAddressToHousehold } from "ChillPersonAssets/vuejs/_api/AddAddress.js";
|
||||||
import ShowPane from './ShowPane.vue';
|
import ShowPane from './ShowPane.vue';
|
||||||
import SuggestPane from './SuggestPane.vue';
|
import SuggestPane from './SuggestPane.vue';
|
||||||
@ -234,6 +245,9 @@ export default {
|
|||||||
EditPane,
|
EditPane,
|
||||||
DatePane
|
DatePane
|
||||||
},
|
},
|
||||||
|
emits: {
|
||||||
|
pickAddress: null
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
flag: {
|
flag: {
|
||||||
@ -311,8 +325,10 @@ export default {
|
|||||||
return (this.validFrom || this.validTo) ? true : false;
|
return (this.validFrom || this.validTo) ? true : false;
|
||||||
},
|
},
|
||||||
hasSuggestions() {
|
hasSuggestions() {
|
||||||
// TODO
|
console.log(this.context.suggestions);
|
||||||
//return addressSuggestions.length > 0
|
if (typeof(this.context.suggestions) !== 'undefined') {
|
||||||
|
return this.context.suggestions.length > 0;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
displaySuggestions() {
|
displaySuggestions() {
|
||||||
@ -647,9 +663,12 @@ export default {
|
|||||||
this.flag.loading = false;
|
this.flag.loading = false;
|
||||||
this.flag.success = true;
|
this.flag.success = true;
|
||||||
resolve({
|
resolve({
|
||||||
|
address,
|
||||||
|
targetOrigin: this.context.target,
|
||||||
|
// for "legacy" use:
|
||||||
target: this.context.target.name,
|
target: this.context.target.name,
|
||||||
targetId: this.context.target.id,
|
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.loading = false;
|
||||||
this.flag.success = true;
|
this.flag.success = true;
|
||||||
return resolve({
|
return resolve({
|
||||||
|
address,
|
||||||
|
targetOrigin: this.context.target,
|
||||||
|
// for "legacy" use:
|
||||||
target: this.context.target.name,
|
target: this.context.target.name,
|
||||||
targetId: this.context.target.id,
|
targetId: this.context.target.id,
|
||||||
addressId: this.entity.address.address_id
|
addressId: this.entity.address.address_id
|
||||||
@ -705,6 +727,29 @@ export default {
|
|||||||
this.errorMsg.push(error);
|
this.errorMsg.push(error);
|
||||||
this.flag.loading = false;
|
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>
|
<h4 class="h3">{{ $t('address_suggestions') }}</h4>
|
||||||
|
|
||||||
<div class="flex-table AddressSuggestionList">
|
<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="float-button bottom">
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<div class="action">
|
<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">
|
<ul class="record_actions">
|
||||||
<li>
|
<li>
|
||||||
<button class="btn btn-sm btn-choose">
|
<button class="btn btn-sm btn-choose" @click="this.pickAddress(a)">
|
||||||
{{ $t('use_this_address') }}
|
{{ $t('use_this_address') }}
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
@ -25,9 +26,7 @@
|
|||||||
<ul class="list-content fa-ul">
|
<ul class="list-content fa-ul">
|
||||||
<li>
|
<li>
|
||||||
<i class="fa fa-li fa-map-marker"></i>
|
<i class="fa fa-li fa-map-marker"></i>
|
||||||
<!--
|
<address-render-box :address="a"></address-render-box>
|
||||||
<address-render-box></address-render-box>
|
|
||||||
-->
|
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
@ -68,9 +67,14 @@ export default {
|
|||||||
'flag',
|
'flag',
|
||||||
'entity',
|
'entity',
|
||||||
'errorMsg',
|
'errorMsg',
|
||||||
'insideModal'
|
'insideModal',
|
||||||
],
|
],
|
||||||
computed: {},
|
computed: {},
|
||||||
methods: {}
|
methods: {
|
||||||
|
pickAddress(address) {
|
||||||
|
console.log('pickAddress in suggest pane', address);
|
||||||
|
this.$emit('pickAddress', address);
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block table_entities_tbody %}
|
{% block table_entities_tbody %}
|
||||||
{% for entity in entities %}
|
{% for entity in entities %}
|
||||||
<tr>
|
<tr data-username="{{ entity.username|e('html_attr') }}">
|
||||||
<td>
|
<td>
|
||||||
{% if entity.isEnabled %}
|
{% if entity.isEnabled %}
|
||||||
<i class="fa fa-check chill-green"></i>
|
<i class="fa fa-check chill-green"></i>
|
||||||
|
@ -17,32 +17,31 @@
|
|||||||
*/
|
*/
|
||||||
namespace Chill\MainBundle\Test;
|
namespace Chill\MainBundle\Test;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare a client authenticated with a user
|
* Prepare a client authenticated with a user
|
||||||
*
|
|
||||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
|
||||||
*/
|
*/
|
||||||
trait PrepareClientTrait
|
trait PrepareClientTrait
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Create a new client with authentication information.
|
* Create a new client with authentication information.
|
||||||
*
|
*
|
||||||
* @param string $username the username (default 'center a_social')
|
* @param string $username the username (default 'center a_social')
|
||||||
* @param string $password the password (default 'password')
|
* @param string $password the password (default 'password')
|
||||||
* @return \Symfony\Component\BrowserKit\Client
|
* @return \Symfony\Component\BrowserKit\Client
|
||||||
* @throws \LogicException
|
* @throws \LogicException
|
||||||
*/
|
*/
|
||||||
public function getClientAuthenticated(
|
public function getClientAuthenticated(
|
||||||
$username = 'center a_social',
|
$username = 'center a_social',
|
||||||
$password = 'password'
|
$password = 'password'
|
||||||
) {
|
): KernelBrowser {
|
||||||
if (!$this instanceof WebTestCase) {
|
if (!$this instanceof WebTestCase) {
|
||||||
throw new \LogicException(sprintf("The current class does not "
|
throw new \LogicException(sprintf("The current class does not "
|
||||||
. "implements %s", WebTestCase::class));
|
. "implements %s", WebTestCase::class));
|
||||||
}
|
}
|
||||||
|
|
||||||
return static::createClient(array(), array(
|
return static::createClient(array(), array(
|
||||||
'PHP_AUTH_USER' => $username,
|
'PHP_AUTH_USER' => $username,
|
||||||
'PHP_AUTH_PW' => $password,
|
'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;
|
namespace Chill\MainBundle\Tests\Controller;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\User;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||||
|
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
|
||||||
|
|
||||||
class UserControllerTest extends WebTestCase
|
class UserControllerTest extends WebTestCase
|
||||||
{
|
{
|
||||||
private $client;
|
private $client;
|
||||||
|
|
||||||
|
private array $toDelete = [];
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
self::bootKernel();
|
self::bootKernel();
|
||||||
@ -22,18 +27,14 @@ class UserControllerTest extends WebTestCase
|
|||||||
public function testList()
|
public function testList()
|
||||||
{
|
{
|
||||||
// get the list
|
// 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(),
|
$this->assertEquals(200, $this->client->getResponse()->getStatusCode(),
|
||||||
"Unexpected HTTP status code for GET /admin/user/");
|
"Unexpected HTTP status code for GET /admin/main/user");
|
||||||
|
|
||||||
$link = $crawler->selectLink('Ajouter un nouvel utilisateur')->link();
|
|
||||||
$this->assertInstanceOf('Symfony\Component\DomCrawler\Link', $link);
|
|
||||||
$this->assertRegExp('|/fr/admin/user/new$|', $link->getUri());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNew()
|
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();
|
$username = 'Test_user'. uniqid();
|
||||||
$password = 'Password1234!';
|
$password = 'Password1234!';
|
||||||
@ -54,22 +55,15 @@ class UserControllerTest extends WebTestCase
|
|||||||
$this->assertGreaterThan(0, $crawler->filter('td:contains("Test_user")')->count(),
|
$this->assertGreaterThan(0, $crawler->filter('td:contains("Test_user")')->count(),
|
||||||
'Missing element td:contains("Test user")');
|
'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
|
//test the auth of the new client
|
||||||
$this->isPasswordValid($username, $password);
|
$this->isPasswordValid($username, $password);
|
||||||
|
|
||||||
return $update;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function isPasswordValid($username, $password)
|
protected function isPasswordValid($username, $password)
|
||||||
{
|
{
|
||||||
/* @var $passwordEncoder \Symfony\Component\Security\Core\Encoder\UserPasswordEncoder */
|
/* @var $passwordEncoder \Symfony\Component\Security\Core\Encoder\UserPasswordEncoder */
|
||||||
$passwordEncoder = self::$kernel->getContainer()
|
$passwordEncoder = self::$container
|
||||||
->get('security.password_encoder');
|
->get(UserPasswordEncoderInterface::class);
|
||||||
|
|
||||||
$user = self::$kernel->getContainer()
|
$user = self::$kernel->getContainer()
|
||||||
->get('doctrine.orm.entity_manager')
|
->get('doctrine.orm.entity_manager')
|
||||||
@ -81,46 +75,33 @@ class UserControllerTest extends WebTestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param \Symfony\Component\DomCrawler\Link $update
|
* @dataProvider dataGenerateUserId
|
||||||
* @depends testNew
|
|
||||||
*/
|
*/
|
||||||
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();
|
$username = 'Foo bar '.uniqid();
|
||||||
$form = $crawler->selectButton('Mettre à jour')->form(array(
|
$form = $crawler->selectButton('Enregistrer & fermer')->form(array(
|
||||||
'chill_mainbundle_user[username]' => $username,
|
'chill_mainbundle_user[username]' => $username,
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->client->submit($form);
|
$this->client->submit($form);
|
||||||
$crawler = $this->client->followRedirect();
|
$crawler = $this->client->followRedirect();
|
||||||
// Check the element contains an attribute with value equals "Foo"
|
// Check the element contains an attribute with value equals "Foo"
|
||||||
$this->assertGreaterThan(0, $crawler->filter('[value="'.$username.'"]')->count(),
|
$this->assertGreaterThan(0, $crawler->filter('[data-username="'.$username.'"]')->count(),
|
||||||
'Missing element [value="Foo bar"]');
|
'Missing element [data-username="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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param \Symfony\Component\DomCrawler\Link $updatePassword
|
* @dataProvider dataGenerateUserId
|
||||||
* @depends testUpdate
|
|
||||||
*/
|
*/
|
||||||
public function testUpdatePassword(array $params)
|
public function testUpdatePassword(int $userId, $username)
|
||||||
{
|
{
|
||||||
$link = $params['link'];
|
$crawler = $this->client->request('GET', "/fr/admin/user/$userId/edit_password");
|
||||||
$username = $params['username'];
|
|
||||||
$newPassword = '1234Password!';
|
$newPassword = '1234Password!';
|
||||||
|
|
||||||
$crawler = $this->client->click($link);
|
|
||||||
|
|
||||||
$form = $crawler->selectButton('Changer le mot de passe')->form(array(
|
$form = $crawler->selectButton('Changer le mot de passe')->form(array(
|
||||||
'chill_mainbundle_user_password[new_password][first]' => $newPassword,
|
'chill_mainbundle_user_password[new_password][first]' => $newPassword,
|
||||||
'chill_mainbundle_user_password[new_password][second]' => $newPassword,
|
'chill_mainbundle_user_password[new_password][second]' => $newPassword,
|
||||||
@ -130,10 +111,38 @@ class UserControllerTest extends WebTestCase
|
|||||||
|
|
||||||
$this->assertTrue($this->client->getResponse()->isRedirect(),
|
$this->assertTrue($this->client->getResponse()->isRedirect(),
|
||||||
"the response is a redirection");
|
"the response is a redirection");
|
||||||
$this->client->followRedirect();
|
|
||||||
|
|
||||||
$this->isPasswordValid($username, $newPassword);
|
$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:
|
401:
|
||||||
description: "Unauthorized"
|
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:
|
/1.0/main/address-reference.json:
|
||||||
get:
|
get:
|
||||||
tags:
|
tags:
|
||||||
|
@ -247,7 +247,6 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con
|
|||||||
if (\random_int(0, 10) > 3) {
|
if (\random_int(0, 10) > 3) {
|
||||||
// always add social scope:
|
// always add social scope:
|
||||||
$accompanyingPeriod->addScope($this->getReference('scope_social'));
|
$accompanyingPeriod->addScope($this->getReference('scope_social'));
|
||||||
var_dump(count($accompanyingPeriod->getScopes()));
|
|
||||||
|
|
||||||
$accompanyingPeriod->setAddressLocation($this->createAddress());
|
$accompanyingPeriod->setAddressLocation($this->createAddress());
|
||||||
$manager->persist($accompanyingPeriod->getAddressLocation());
|
$manager->persist($accompanyingPeriod->getAddressLocation());
|
||||||
|
@ -229,7 +229,7 @@ class Household
|
|||||||
))
|
))
|
||||||
->andWhere($expr->orX(
|
->andWhere($expr->orX(
|
||||||
$expr->isNull('endDate'),
|
$expr->isNull('endDate'),
|
||||||
$expr->gte('endDate', $date)
|
$expr->gt('endDate', $date)
|
||||||
));
|
));
|
||||||
|
|
||||||
return $criteria;
|
return $criteria;
|
||||||
@ -306,7 +306,7 @@ class Household
|
|||||||
)
|
)
|
||||||
->orWhere(
|
->orWhere(
|
||||||
$expr->andX(
|
$expr->andX(
|
||||||
$expr->lt('endDate', $date),
|
$expr->lte('endDate', $date),
|
||||||
$expr->neq('endDate', null)
|
$expr->neq('endDate', null)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -199,7 +199,7 @@ final class PersonACLAwareRepository implements PersonACLAwareRepositoryInterfac
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (NULL !== $birthdate) {
|
if (NULL !== $birthdate) {
|
||||||
$qb->andWhere($qb->expr()->eq('s.birthdate', ':birthdate'))
|
$qb->andWhere($qb->expr()->eq('p.birthdate', ':birthdate'))
|
||||||
->setParameter('birthdate', $birthdate);
|
->setParameter('birthdate', $birthdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ export default {
|
|||||||
this.toggleEditEvaluation();
|
this.toggleEditEvaluation();
|
||||||
},
|
},
|
||||||
buildEditLink(storedObject) {
|
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);
|
window.location.pathname + window.location.search + window.location.hash);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -2,171 +2,126 @@
|
|||||||
|
|
||||||
<h2 class="mt-4">{{ $t('household_members_editor.household_part') }}</h2>
|
<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="alert alert-info">{{ $t('household_members_editor.household.no_household_choose_one') }}</div>
|
||||||
<div class="item-bloc">
|
|
||||||
<household-render-box :household="household" :isAddressMultiline="true"></household-render-box>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="isHouseholdNew && !hasHouseholdAddress">
|
<div class="flex-table householdSuggestionList">
|
||||||
|
<div v-if="isModeNewAllowed" class="item-bloc">
|
||||||
<div v-if="hasAddressSuggestion" class="householdAddressSuggestion my-5">
|
<div>
|
||||||
<h4 class="mb-3">
|
<section>
|
||||||
{{ $t('household_members_editor.household.where_live_the_household') }}
|
<div class="item-row">
|
||||||
</h4>
|
<div class="item-col">
|
||||||
<div class="accordion" id="addressSuggestions">
|
<div class="h4">
|
||||||
<div class="accordion-item">
|
<i class="fa fa-home"></i> {{ $t('household_members_editor.household.new_household') }}
|
||||||
<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>
|
</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>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<ul class="record_actions">
|
<div v-else>
|
||||||
<li >
|
<div class="flex-table">
|
||||||
<add-address
|
<div class="item-bloc">
|
||||||
:context="addAddress.context"
|
<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"
|
:key="addAddress.key"
|
||||||
:options="addAddress.options"
|
:options="addAddress.options"
|
||||||
:result="addAddress.result"
|
:addressChangedCallback="addressChanged"
|
||||||
@addressChangedCallback="setHouseholdCreatedAddress"
|
></add-address>
|
||||||
ref="addAddress">
|
</li>
|
||||||
</add-address>
|
<li v-if="hasHouseholdAddress">
|
||||||
</li>
|
<button class="btn btn-remove"
|
||||||
</ul>
|
@click="removeHouseholdAddress">
|
||||||
</div>
|
{{ $t('household_members_editor.household.remove_address') }}
|
||||||
|
</button>
|
||||||
<div v-if="isHouseholdNew && hasHouseholdAddress">
|
</li>
|
||||||
<ul class="record_actions">
|
</ul>
|
||||||
<li >
|
</template>
|
||||||
<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>
|
|
||||||
</div>
|
</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>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -185,35 +140,32 @@ export default {
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
addAddress: {
|
addAddress: {
|
||||||
context: {
|
|
||||||
target: {
|
|
||||||
name: 'household_create',
|
|
||||||
id: 0
|
|
||||||
},
|
|
||||||
edit: false,
|
|
||||||
addressId: null
|
|
||||||
},
|
|
||||||
key: 'household_new',
|
key: 'household_new',
|
||||||
options: {
|
options: {
|
||||||
useDate: {
|
useDate: {
|
||||||
validFrom: true
|
validFrom: false,
|
||||||
|
validTo: false,
|
||||||
},
|
},
|
||||||
|
hideAddress: true,
|
||||||
button: {
|
button: {
|
||||||
text: {
|
text: {
|
||||||
create: 'household_members_editor.household.or_create_new_address',
|
create: 'household_members_editor.household.set_address',
|
||||||
edit: null,
|
edit: 'household_members_editor.household.update_address',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
title: {
|
title: {
|
||||||
create: 'household_members_editor.household.create_new_address',
|
create: 'household_members_editor.household.create_new_address',
|
||||||
edit: null,
|
edit: 'household_members_editor.household.update_address_title',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapGetters([
|
...mapGetters([
|
||||||
|
'isModeNewAllowed',
|
||||||
|
'isModeLeaveAllowed',
|
||||||
|
'getSuggestions',
|
||||||
'hasHousehold',
|
'hasHousehold',
|
||||||
'isHouseholdNew',
|
'isHouseholdNew',
|
||||||
'hasHouseholdSuggestion',
|
'hasHouseholdSuggestion',
|
||||||
@ -223,68 +175,38 @@ export default {
|
|||||||
'countAddressSuggestion',
|
'countAddressSuggestion',
|
||||||
'filterAddressesSuggestion',
|
'filterAddressesSuggestion',
|
||||||
'hasHouseholdAddress',
|
'hasHouseholdAddress',
|
||||||
|
'isModeLeave',
|
||||||
|
'getAddressContext',
|
||||||
]),
|
]),
|
||||||
...mapState([
|
...mapState([
|
||||||
'showHouseholdSuggestion',
|
'showHouseholdSuggestion',
|
||||||
'showAddressSuggestion'
|
'showAddressSuggestion',
|
||||||
|
'mode',
|
||||||
]),
|
]),
|
||||||
household() {
|
household() {
|
||||||
return this.$store.state.household;
|
return this.$store.state.household;
|
||||||
},
|
},
|
||||||
allowHouseholdCreate() {
|
|
||||||
return this.$store.state.allowHouseholdCreate && !this.$store.getters.hasHousehold;
|
|
||||||
},
|
|
||||||
allowHouseholdSearch() {
|
allowHouseholdSearch() {
|
||||||
return false;
|
return false;
|
||||||
return this.$store.state.allowHouseholdSearch && !this.$store.getters.hasHousehold;
|
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: {
|
methods: {
|
||||||
createHousehold() {
|
setModeNew() {
|
||||||
this.$store.dispatch('createHousehold');
|
this.$store.dispatch('createHousehold');
|
||||||
},
|
},
|
||||||
forceLeaveWithoutHousehold() {
|
setModeLeave() {
|
||||||
this.$store.dispatch('forceLeaveWithoutHousehold');
|
this.$store.dispatch('forceLeaveWithoutHousehold');
|
||||||
},
|
},
|
||||||
toggleHouseholdSuggestion() {
|
resetMode() {
|
||||||
this.$store.commit('toggleHouseholdSuggestion');
|
this.$store.commit('resetMode');
|
||||||
},
|
},
|
||||||
toggleAddressSuggestion() {
|
addressChanged(payload) {
|
||||||
this.$store.commit('toggleAddressSuggestion');
|
console.log("addressChanged", payload);
|
||||||
|
this.$store.dispatch('setHouseholdNewAddress', payload.address);
|
||||||
},
|
},
|
||||||
selectHousehold(h) {
|
selectHousehold(h) {
|
||||||
this.$store.dispatch('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() {
|
removeHouseholdAddress() {
|
||||||
this.$store.commit('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>
|
</style>
|
||||||
|
@ -7,16 +7,27 @@ const appMessages = {
|
|||||||
household: {
|
household: {
|
||||||
no_household_choose_one: "Aucun ménage de destination. Choisissez un ménage. Les usagers concernés par la modification apparaitront ensuite.",
|
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",
|
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",
|
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",
|
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 ?",
|
where_live_the_household: "À quelle adresse habite ce ménage ?",
|
||||||
household_live_to_this_address: "Sélectionner l'adresse",
|
household_live_to_this_address: "Sélectionner l'adresse",
|
||||||
no_suggestions: "Aucune adresse à suggérer",
|
no_suggestions: "Aucune adresse à suggérer",
|
||||||
delete_this_address: "Supprimer cette adresse",
|
delete_this_address: "Supprimer cette adresse",
|
||||||
create_new_address: "Créer une nouvelle adresse",
|
create_new_address: "Créer une nouvelle adresse",
|
||||||
or_create_new_address: "Ou créer une nouvelle adresse",
|
or_create_new_address: "Ou créer une nouvelle adresse",
|
||||||
|
|
||||||
|
*/
|
||||||
|
// end remove ?
|
||||||
},
|
},
|
||||||
concerned: {
|
concerned: {
|
||||||
title: "Nouveaux membres du ménage",
|
title: "Nouveaux membres du ménage",
|
||||||
@ -34,7 +45,7 @@ const appMessages = {
|
|||||||
is_not_holder: "N'est pas titulaire",
|
is_not_holder: "N'est pas titulaire",
|
||||||
remove_position: "Retirer des {position}",
|
remove_position: "Retirer des {position}",
|
||||||
remove_concerned: "Ne plus transférer",
|
remove_concerned: "Ne plus transférer",
|
||||||
household_part: "Ménage de destination",
|
household_part: "Destination",
|
||||||
suggestions: "Suggestions",
|
suggestions: "Suggestions",
|
||||||
hide_household_suggestion: "Masquer les suggestions",
|
hide_household_suggestion: "Masquer les suggestions",
|
||||||
show_household_suggestion: 'Aucune suggestion | Afficher une suggestion | Afficher {count} suggestions',
|
show_household_suggestion: 'Aucune suggestion | Afficher une suggestion | Afficher {count} suggestions',
|
||||||
|
@ -29,6 +29,15 @@ const store = createStore({
|
|||||||
return 0;
|
return 0;
|
||||||
}),
|
}),
|
||||||
startDate: new Date(),
|
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,
|
allowHouseholdCreate: window.household_members_editor_data.allowHouseholdCreate,
|
||||||
allowHouseholdSearch: window.household_members_editor_data.allowHouseholdSearch,
|
allowHouseholdSearch: window.household_members_editor_data.allowHouseholdSearch,
|
||||||
allowLeaveWithoutHousehold: window.household_members_editor_data.allowLeaveWithoutHousehold,
|
allowLeaveWithoutHousehold: window.household_members_editor_data.allowLeaveWithoutHousehold,
|
||||||
@ -41,11 +50,70 @@ const store = createStore({
|
|||||||
errors: []
|
errors: []
|
||||||
},
|
},
|
||||||
getters: {
|
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) {
|
isHouseholdNew(state) {
|
||||||
|
return state.mode === "new";
|
||||||
|
/*
|
||||||
if (state.household === null) {
|
if (state.household === null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return !Number.isInteger(state.household.id);
|
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) {
|
hasHouseholdAddress(state) {
|
||||||
if (null === state.household) {
|
if (null === state.household) {
|
||||||
@ -180,6 +248,11 @@ const store = createStore({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
|
resetMode(state) {
|
||||||
|
state.mode = null;
|
||||||
|
state.household = null;
|
||||||
|
state.forceLeaveWithoutHousehold = false;
|
||||||
|
},
|
||||||
addConcerned(state, person) {
|
addConcerned(state, person) {
|
||||||
let persons = state.concerned.map(conc => conc.person.id);
|
let persons = state.concerned.map(conc => conc.person.id);
|
||||||
if (!persons.includes(person.id)) {
|
if (!persons.includes(person.id)) {
|
||||||
@ -222,6 +295,7 @@ const store = createStore({
|
|||||||
current_address: null,
|
current_address: null,
|
||||||
current_members_id: []
|
current_members_id: []
|
||||||
};
|
};
|
||||||
|
state.mode = "new";
|
||||||
state.forceLeaveWithoutHousehold = false;
|
state.forceLeaveWithoutHousehold = false;
|
||||||
},
|
},
|
||||||
removeHousehold(state) {
|
removeHousehold(state) {
|
||||||
@ -229,6 +303,7 @@ const store = createStore({
|
|||||||
state.forceLeaveWithoutHousehold = false;
|
state.forceLeaveWithoutHousehold = false;
|
||||||
},
|
},
|
||||||
setHouseholdAddress(state, address) {
|
setHouseholdAddress(state, address) {
|
||||||
|
console.log('setHouseholdAddress commit', address);
|
||||||
if (null === state.household) {
|
if (null === state.household) {
|
||||||
console.error("no household");
|
console.error("no household");
|
||||||
throw new Error("No household");
|
throw new Error("No household");
|
||||||
@ -246,10 +321,12 @@ const store = createStore({
|
|||||||
},
|
},
|
||||||
forceLeaveWithoutHousehold(state) {
|
forceLeaveWithoutHousehold(state) {
|
||||||
state.household = null;
|
state.household = null;
|
||||||
|
state.mode = "leave";
|
||||||
state.forceLeaveWithoutHousehold = true;
|
state.forceLeaveWithoutHousehold = true;
|
||||||
},
|
},
|
||||||
selectHousehold(state, household) {
|
selectHousehold(state, household) {
|
||||||
state.household = household;
|
state.household = household;
|
||||||
|
state.mode = "existing";
|
||||||
state.forceLeaveWithoutHousehold = false;
|
state.forceLeaveWithoutHousehold = false;
|
||||||
},
|
},
|
||||||
setHouseholdSuggestionByAccompanyingPeriod(state, households) {
|
setHouseholdSuggestionByAccompanyingPeriod(state, households) {
|
||||||
@ -320,18 +397,8 @@ const store = createStore({
|
|||||||
commit('createHousehold');
|
commit('createHousehold');
|
||||||
dispatch('computeWarnings');
|
dispatch('computeWarnings');
|
||||||
},
|
},
|
||||||
setHouseholdNewAddress({ commit }, payload) {
|
setHouseholdNewAddress({ commit }, address) {
|
||||||
let url = `/api/1.0/main/address/${payload.addressId}.json`;
|
commit('setHouseholdAddress', address);
|
||||||
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);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
forceLeaveWithoutHousehold({ commit, dispatch }) {
|
forceLeaveWithoutHousehold({ commit, dispatch }) {
|
||||||
commit('forceLeaveWithoutHousehold');
|
commit('forceLeaveWithoutHousehold');
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
"php": ">= 7.4",
|
"php": ">= 7.4",
|
||||||
"champs-libres/wopi-bundle": "dev-master",
|
"champs-libres/wopi-bundle": "dev-master",
|
||||||
"nyholm/psr7": "^1.4",
|
"nyholm/psr7": "^1.4",
|
||||||
"php-opencloud/openstack": "^3.2.1"
|
"symfony/mime": "^4 || ^5"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
@ -9,9 +9,10 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\WopiBundle\Controller;
|
namespace Chill\WopiBundle\Controller;
|
||||||
|
|
||||||
use ChampsLibres\WopiLib\Configuration\WopiConfigurationInterface;
|
use ChampsLibres\WopiLib\Contract\Service\Configuration\ConfigurationInterface;
|
||||||
use ChampsLibres\WopiLib\Discovery\WopiDiscoveryInterface;
|
use ChampsLibres\WopiLib\Contract\Service\Discovery\DiscoveryInterface;
|
||||||
use Chill\DocStoreBundle\Repository\StoredObjectRepository;
|
use ChampsLibres\WopiLib\Contract\Service\DocumentManagerInterface;
|
||||||
|
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||||
use Chill\WopiBundle\Service\Controller\ResponderInterface;
|
use Chill\WopiBundle\Service\Controller\ResponderInterface;
|
||||||
use Exception;
|
use Exception;
|
||||||
use loophp\psr17\Psr17Interface;
|
use loophp\psr17\Psr17Interface;
|
||||||
@ -23,11 +24,11 @@ use Symfony\Component\Security\Core\Security;
|
|||||||
|
|
||||||
final class Test
|
final class Test
|
||||||
{
|
{
|
||||||
private StoredObjectRepository $storedObjectRepository;
|
private DiscoveryInterface $wopiDiscovery;
|
||||||
|
|
||||||
private WopiDiscoveryInterface $wopiDiscovery;
|
private DocumentManagerInterface $documentManager;
|
||||||
|
|
||||||
private WopiConfigurationInterface $wopiConfiguration;
|
private ConfigurationInterface $wopiConfiguration;
|
||||||
|
|
||||||
private ResponderInterface $responder;
|
private ResponderInterface $responder;
|
||||||
|
|
||||||
@ -38,15 +39,15 @@ final class Test
|
|||||||
private RouterInterface $router;
|
private RouterInterface $router;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
StoredObjectRepository $storedObjectRepository,
|
ConfigurationInterface $wopiConfiguration,
|
||||||
WopiConfigurationInterface $wopiConfiguration,
|
DiscoveryInterface $wopiDiscovery,
|
||||||
WopiDiscoveryInterface $wopiDiscovery,
|
DocumentManagerInterface $documentManager,
|
||||||
ResponderInterface $responder,
|
ResponderInterface $responder,
|
||||||
Security $security,
|
Security $security,
|
||||||
Psr17Interface $psr17,
|
Psr17Interface $psr17,
|
||||||
RouterInterface $router
|
RouterInterface $router
|
||||||
) {
|
) {
|
||||||
$this->storedObjectRepository = $storedObjectRepository;
|
$this->documentManager = $documentManager;
|
||||||
$this->wopiConfiguration = $wopiConfiguration;
|
$this->wopiConfiguration = $wopiConfiguration;
|
||||||
$this->wopiDiscovery = $wopiDiscovery;
|
$this->wopiDiscovery = $wopiDiscovery;
|
||||||
$this->responder = $responder;
|
$this->responder = $responder;
|
||||||
@ -58,11 +59,11 @@ final class Test
|
|||||||
public function __invoke(string $fileId): Response
|
public function __invoke(string $fileId): Response
|
||||||
{
|
{
|
||||||
$configuration = $this->wopiConfiguration->jsonSerialize();
|
$configuration = $this->wopiConfiguration->jsonSerialize();
|
||||||
|
/** @var StoredObject $storedObject */
|
||||||
$storedObject = $this->storedObjectRepository->findOneBy(['filename' => $fileId]);
|
$storedObject = $this->documentManager->findByDocumentId($fileId);
|
||||||
|
|
||||||
if (null === $storedObject) {
|
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())) {
|
if ([] === $discoverExtension = $this->wopiDiscovery->discoverMimeType($storedObject->getType())) {
|
||||||
@ -83,7 +84,7 @@ final class Test
|
|||||||
->generate(
|
->generate(
|
||||||
'checkFileInfo',
|
'checkFileInfo',
|
||||||
[
|
[
|
||||||
'fileId' => $storedObject->getFilename(),
|
'fileId' => $this->documentManager->getDocumentId($storedObject),
|
||||||
],
|
],
|
||||||
UrlGeneratorInterface::ABSOLUTE_URL
|
UrlGeneratorInterface::ABSOLUTE_URL
|
||||||
),
|
),
|
||||||
|
@ -10,8 +10,10 @@ declare(strict_types=1);
|
|||||||
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
|
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
|
||||||
|
|
||||||
use ChampsLibres\AsyncUploaderBundle\TempUrl\TempUrlGeneratorInterface;
|
use ChampsLibres\AsyncUploaderBundle\TempUrl\TempUrlGeneratorInterface;
|
||||||
use ChampsLibres\WopiLib\Service\Contract\WopiInterface;
|
|
||||||
use Chill\WopiBundle\Service\Wopi\ChillWopi;
|
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) {
|
return static function (ContainerConfigurator $container) {
|
||||||
$services = $container
|
$services = $container
|
||||||
@ -30,8 +32,14 @@ return static function (ContainerConfigurator $container) {
|
|||||||
->tag('controller.service_arguments');
|
->tag('controller.service_arguments');
|
||||||
|
|
||||||
$services
|
$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
|
$services
|
||||||
->alias(TempUrlGeneratorInterface::class, 'async_uploader.temp_url_generator');
|
->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;
|
namespace Chill\WopiBundle\Service\Wopi;
|
||||||
|
|
||||||
use ChampsLibres\AsyncUploaderBundle\TempUrl\TempUrlGeneratorInterface;
|
use ChampsLibres\WopiLib\Contract\Service\DocumentManagerInterface;
|
||||||
use ChampsLibres\WopiLib\Discovery\WopiDiscoveryInterface;
|
use ChampsLibres\WopiLib\Contract\Service\WopiInterface;
|
||||||
use ChampsLibres\WopiLib\Service\Contract\WopiInterface;
|
|
||||||
use Chill\DocStoreBundle\Repository\StoredObjectRepository;
|
|
||||||
use Exception;
|
|
||||||
use loophp\psr17\Psr17Interface;
|
use loophp\psr17\Psr17Interface;
|
||||||
use Psr\Http\Client\ClientInterface;
|
use Psr\Cache\CacheItemPoolInterface;
|
||||||
use Psr\Http\Message\RequestInterface;
|
use Psr\Http\Message\RequestInterface;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
|
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
|
||||||
@ -23,32 +20,28 @@ use Symfony\Component\Security\Core\User\UserProviderInterface;
|
|||||||
|
|
||||||
final class ChillWopi implements WopiInterface
|
final class ChillWopi implements WopiInterface
|
||||||
{
|
{
|
||||||
|
private CacheItemPoolInterface $cache;
|
||||||
|
|
||||||
|
private DocumentManagerInterface $documentManager;
|
||||||
|
|
||||||
private Psr17Interface $psr17;
|
private Psr17Interface $psr17;
|
||||||
|
|
||||||
private WopiDiscoveryInterface $wopiDiscovery;
|
|
||||||
|
|
||||||
private StoredObjectRepository $storedObjectRepository;
|
|
||||||
|
|
||||||
private ClientInterface $httpClient;
|
|
||||||
|
|
||||||
private TempUrlGeneratorInterface $tempUrlGenerator;
|
|
||||||
|
|
||||||
private UserProviderInterface $userProvider;
|
private UserProviderInterface $userProvider;
|
||||||
|
|
||||||
|
private WopiInterface $wopi;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
CacheItemPoolInterface $cache,
|
||||||
|
DocumentManagerInterface $documentManager,
|
||||||
Psr17Interface $psr17,
|
Psr17Interface $psr17,
|
||||||
WopiDiscoveryInterface $wopiDiscovery,
|
UserProviderInterface $userProvider,
|
||||||
StoredObjectRepository $storedObjectRepository,
|
WopiInterface $wopi
|
||||||
ClientInterface $httpClient,
|
|
||||||
TempUrlGeneratorInterface $tempUrlGenerator,
|
|
||||||
UserProviderInterface $userProvider
|
|
||||||
) {
|
) {
|
||||||
|
$this->cache = $cache;
|
||||||
|
$this->documentManager = $documentManager;
|
||||||
$this->psr17 = $psr17;
|
$this->psr17 = $psr17;
|
||||||
$this->wopiDiscovery = $wopiDiscovery;
|
|
||||||
$this->storedObjectRepository = $storedObjectRepository;
|
|
||||||
$this->httpClient = $httpClient;
|
|
||||||
$this->tempUrlGenerator = $tempUrlGenerator;
|
|
||||||
$this->userProvider = $userProvider;
|
$this->userProvider = $userProvider;
|
||||||
|
$this->wopi = $wopi;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function checkFileInfo(
|
public function checkFileInfo(
|
||||||
@ -64,17 +57,10 @@ final class ChillWopi implements WopiInterface
|
|||||||
->createResponse(401);
|
->createResponse(401);
|
||||||
}
|
}
|
||||||
|
|
||||||
$storedObject = $this->storedObjectRepository->findOneBy(['filename' => $fileId]);
|
// @ TODO : Replace this with a call to decorated object once authentication is done.
|
||||||
|
$document = $this->documentManager->findByDocumentId($fileId);
|
||||||
if (null === $storedObject) {
|
$userIdentifier = $user->getUsername();
|
||||||
throw new Exception(sprintf('Unable to find object named %s', $fileId));
|
$userCacheKey = sprintf('wopi_putUserInfo_%s', $userIdentifier);
|
||||||
}
|
|
||||||
|
|
||||||
$mimeType = $storedObject->getType();
|
|
||||||
|
|
||||||
if ([] === $this->wopiDiscovery->discoverMimeType($mimeType)) {
|
|
||||||
throw new Exception(sprintf('Unable to find mime type %s', $mimeType));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this
|
return $this
|
||||||
->psr17
|
->psr17
|
||||||
@ -82,33 +68,38 @@ final class ChillWopi implements WopiInterface
|
|||||||
->withHeader('Content-Type', 'application/json')
|
->withHeader('Content-Type', 'application/json')
|
||||||
->withBody($this->psr17->createStream((string) json_encode(
|
->withBody($this->psr17->createStream((string) json_encode(
|
||||||
[
|
[
|
||||||
'BaseFileName' => $storedObject->getFilename(),
|
'BaseFileName' => $this->documentManager->getBasename($document),
|
||||||
'OwnerId' => uniqid(),
|
'OwnerId' => 'Symfony',
|
||||||
'Size' => 0,
|
'Size' => $this->documentManager->getSize($document),
|
||||||
'UserId' => uniqid(),
|
'UserId' => $userIdentifier,
|
||||||
// 'Version' => 'v' . uniqid(),
|
|
||||||
'ReadOnly' => false,
|
'ReadOnly' => false,
|
||||||
|
'UserCanAttend' => true,
|
||||||
|
'UserCanPresent' => true,
|
||||||
|
'UserCanRename' => true,
|
||||||
'UserCanWrite' => true,
|
'UserCanWrite' => true,
|
||||||
'UserCanNotWriteRelative' => true,
|
'UserCanNotWriteRelative' => false,
|
||||||
'SupportsLocks' => false,
|
'SupportsUserInfo' => true,
|
||||||
'UserFriendlyName' => sprintf('User %s', $user->getUsername()),
|
'SupportsDeleteFile' => true,
|
||||||
'UserExtraInfo' => [],
|
'SupportsLocks' => true,
|
||||||
'LastModifiedTime' => date('Y-m-d\TH:i:s.u\Z', $storedObject->getCreationDate()->getTimestamp()),
|
'SupportsGetLock' => true,
|
||||||
'CloseButtonClosesWindow' => true,
|
'SupportsExtendedLockLength' => true,
|
||||||
'EnableInsertRemoteImage' => true,
|
'UserFriendlyName' => $userIdentifier,
|
||||||
'EnableShare' => false,
|
|
||||||
'SupportsUpdate' => true,
|
'SupportsUpdate' => true,
|
||||||
'SupportsRename' => false,
|
'SupportsRename' => true,
|
||||||
'DisablePrint' => false,
|
'DisablePrint' => false,
|
||||||
'DisableExport' => false,
|
'AllowExternalMarketplace' => true,
|
||||||
'DisableCopy' => false,
|
'SupportedShareUrlTypes' => [
|
||||||
|
'ReadOnly',
|
||||||
|
],
|
||||||
|
'SHA256' => $this->documentManager->getSha256($document),
|
||||||
|
'UserInfo' => (string) $this->cache->getItem($userCacheKey)->get(),
|
||||||
]
|
]
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteFile(string $fileId, ?string $accessToken, RequestInterface $request): ResponseInterface
|
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(
|
public function enumerateAncestors(
|
||||||
@ -116,57 +107,17 @@ final class ChillWopi implements WopiInterface
|
|||||||
?string $accessToken,
|
?string $accessToken,
|
||||||
RequestInterface $request
|
RequestInterface $request
|
||||||
): ResponseInterface {
|
): ResponseInterface {
|
||||||
return $this->getDebugResponse(__FUNCTION__, $request);
|
return $this->wopi->enumerateAncestors($fileId, $accessToken, $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFile(string $fileId, ?string $accessToken, RequestInterface $request): ResponseInterface
|
public function getFile(string $fileId, ?string $accessToken, RequestInterface $request): ResponseInterface
|
||||||
{
|
{
|
||||||
try {
|
return $this->wopi->getFile($fileId, $accessToken, $request);
|
||||||
$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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLock(string $fileId, ?string $accessToken, RequestInterface $request): ResponseInterface
|
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(
|
public function getShareUrl(
|
||||||
@ -174,7 +125,7 @@ final class ChillWopi implements WopiInterface
|
|||||||
?string $accessToken,
|
?string $accessToken,
|
||||||
RequestInterface $request
|
RequestInterface $request
|
||||||
): ResponseInterface {
|
): ResponseInterface {
|
||||||
return $this->getDebugResponse(__FUNCTION__, $request);
|
return $this->wopi->getShareUrl($fileId, $accessToken, $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function lock(
|
public function lock(
|
||||||
@ -183,7 +134,7 @@ final class ChillWopi implements WopiInterface
|
|||||||
string $xWopiLock,
|
string $xWopiLock,
|
||||||
RequestInterface $request
|
RequestInterface $request
|
||||||
): ResponseInterface {
|
): ResponseInterface {
|
||||||
return $this->getDebugResponse(__FUNCTION__, $request);
|
return $this->wopi->lock($fileId, $accessToken, $xWopiLock, $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function putFile(
|
public function putFile(
|
||||||
@ -193,49 +144,17 @@ final class ChillWopi implements WopiInterface
|
|||||||
string $xWopiEditors,
|
string $xWopiEditors,
|
||||||
RequestInterface $request
|
RequestInterface $request
|
||||||
): ResponseInterface {
|
): ResponseInterface {
|
||||||
try {
|
return $this->wopi->putFile($fileId, $accessToken, $xWopiLock, $xWopiEditors, $request);
|
||||||
$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([])));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function putRelativeFile(string $fileId, string $accessToken, ?string $suggestedTarget, ?string $relativeTarget, bool $overwriteRelativeTarget, int $size, RequestInterface $request): ResponseInterface
|
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
|
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(
|
public function refreshLock(
|
||||||
@ -244,7 +163,7 @@ final class ChillWopi implements WopiInterface
|
|||||||
string $xWopiLock,
|
string $xWopiLock,
|
||||||
RequestInterface $request
|
RequestInterface $request
|
||||||
): ResponseInterface {
|
): ResponseInterface {
|
||||||
return $this->getDebugResponse(__FUNCTION__, $request);
|
return $this->wopi->refreshLock($fileId, $accessToken, $xWopiLock, $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renameFile(
|
public function renameFile(
|
||||||
@ -254,7 +173,7 @@ final class ChillWopi implements WopiInterface
|
|||||||
string $xWopiRequestedName,
|
string $xWopiRequestedName,
|
||||||
RequestInterface $request
|
RequestInterface $request
|
||||||
): ResponseInterface {
|
): ResponseInterface {
|
||||||
return $this->getDebugResponse(__FUNCTION__, $request);
|
return $this->wopi->renameFile($fileId, $accessToken, $xWopiLock, $xWopiRequestedName, $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function unlock(
|
public function unlock(
|
||||||
@ -263,7 +182,7 @@ final class ChillWopi implements WopiInterface
|
|||||||
string $xWopiLock,
|
string $xWopiLock,
|
||||||
RequestInterface $request
|
RequestInterface $request
|
||||||
): ResponseInterface {
|
): ResponseInterface {
|
||||||
return $this->getDebugResponse(__FUNCTION__, $request);
|
return $this->wopi->unlock($fileId, $accessToken, $xWopiLock, $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function unlockAndRelock(
|
public function unlockAndRelock(
|
||||||
@ -273,33 +192,6 @@ final class ChillWopi implements WopiInterface
|
|||||||
string $xWopiOldLock,
|
string $xWopiOldLock,
|
||||||
RequestInterface $request
|
RequestInterface $request
|
||||||
): ResponseInterface {
|
): ResponseInterface {
|
||||||
return $this->getDebugResponse(__FUNCTION__, $request);
|
return $this->wopi->unlockAndRelock($fileId, $accessToken, $xWopiLock, $xWopiOldLock, $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
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user