mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-04-01 18:43:42 +00:00
Compare commits
13 Commits
v4.14.1
...
508-lock-s
| Author | SHA1 | Date | |
|---|---|---|---|
|
76d3612d33
|
|||
|
277e4fa490
|
|||
|
fe11780ad5
|
|||
|
c1e5346ef9
|
|||
| 297628d06f | |||
| 3bc12a5469 | |||
| 300547ad14 | |||
| dcccbb36f4 | |||
| d1fe1be0f8 | |||
| 6654bea48f | |||
|
eb2dfc8591
|
|||
| b5a22508ff | |||
| f12bc2f35f |
8
.changes/unreleased/DX-20260324-153805.yaml
Normal file
8
.changes/unreleased/DX-20260324-153805.yaml
Normal file
@@ -0,0 +1,8 @@
|
||||
kind: DX
|
||||
body: 'Changie: add a field for adding a release note tag when creating an entry in changie.'
|
||||
time: 2026-03-24T15:38:05.320350835+01:00
|
||||
custom:
|
||||
IRN: "No"
|
||||
Issue: ""
|
||||
MR: ""
|
||||
SchemaChange: No schema change
|
||||
7
.changes/unreleased/Feature-20260324-164018.yaml
Normal file
7
.changes/unreleased/Feature-20260324-164018.yaml
Normal file
@@ -0,0 +1,7 @@
|
||||
kind: Feature
|
||||
body: Add a field "externalId" on center, to ease the synchronisation of centers with external tools
|
||||
time: 2026-03-24T16:40:18.159561269+01:00
|
||||
custom:
|
||||
Issue: "507"
|
||||
MR: "977"
|
||||
SchemaChange: Add columns or tables
|
||||
3
.changes/v4.14.2.md
Normal file
3
.changes/v4.14.2.md
Normal file
@@ -0,0 +1,3 @@
|
||||
## v4.14.2 - 2026-03-18
|
||||
### Fixed
|
||||
* Fix link inside notification email
|
||||
@@ -7,7 +7,7 @@ versionFormat: '## {{.Version}} - {{.Time.Format "2006-01-02"}}'
|
||||
kindFormat: '### {{.Kind}}'
|
||||
# Note: it is possible to add a `.custom.Long` text manually into the yaml file produced by `changie new`. This will add a long description.
|
||||
changeFormat: >-
|
||||
* {{ if not (eq .Custom.Issue "") }}([#{{ .Custom.Issue }}](https://gitlab.com/Chill-Projet/chill-bundles/-/issues/{{ .Custom.Issue }})) {{ end }}{{ if not (eq .Custom.MR "") }}([!{{ .Custom.MR }}](https://gitlab.com/Chill-Projet/chill-bundles/-/merge_requests/{{ .Custom.MR }})) {{ end }}{{ .Body }} {{ if and .Custom.SchemaChange (ne .Custom.SchemaChange "No schema change") }}
|
||||
* {{ if not (eq .Custom.Issue "") }}([#{{ .Custom.Issue }}](https://gitlab.com/Chill-Projet/chill-bundles/-/issues/{{ .Custom.Issue }})) {{ end }}{{ if not (eq .Custom.MR "") }}([!{{ .Custom.MR }}](https://gitlab.com/Chill-Projet/chill-bundles/-/merge_requests/{{ .Custom.MR }})) {{ end }}{{ .Body }} {{ if (eq .Custom.IRN "Yes") }}(RN){{ end }} {{ if and .Custom.SchemaChange (ne .Custom.SchemaChange "No schema change") }}
|
||||
|
||||
**Schema Change**: {{ .Custom.SchemaChange }}
|
||||
{{- end -}}
|
||||
@@ -36,6 +36,14 @@ custom:
|
||||
type: int
|
||||
minInt: 1
|
||||
|
||||
- key: IRN
|
||||
label: Is this interesting for release notes ?
|
||||
optional: false
|
||||
type: enum
|
||||
enumOptions:
|
||||
- "No"
|
||||
- "Yes"
|
||||
|
||||
body:
|
||||
# allow multiline messages
|
||||
block: true
|
||||
|
||||
@@ -6,6 +6,10 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html),
|
||||
and is generated by [Changie](https://github.com/miniscruff/changie).
|
||||
|
||||
|
||||
## v4.14.2 - 2026-03-18
|
||||
### Fixed
|
||||
* Fix link inside notification email
|
||||
|
||||
## v4.14.1 - 2026-03-16
|
||||
### Security
|
||||
* ([#506](https://gitlab.com/Chill-Projet/chill-bundles/-/issues/506)) ([!972](https://gitlab.com/Chill-Projet/chill-bundles/-/merge_requests/972)) Fix permission in list of activities in person context
|
||||
|
||||
@@ -97,6 +97,12 @@ class StoredObject implements Document, TrackCreationInterface
|
||||
#[ORM\OneToMany(mappedBy: 'storedObject', targetEntity: StoredObjectVersion::class, cascade: ['persist'], orphanRemoval: true)]
|
||||
private Collection&Selectable $versions;
|
||||
|
||||
/**
|
||||
* @var Collection<int, StoredObjectLock>
|
||||
*/
|
||||
#[ORM\OneToMany(mappedBy: 'storedObject', targetEntity: StoredObjectLock::class, cascade: ['persist', 'remove', 'refresh', 'merge'])]
|
||||
private Collection $locks;
|
||||
|
||||
/**
|
||||
* @param StoredObject::STATUS_* $status
|
||||
*/
|
||||
@@ -107,6 +113,41 @@ class StoredObject implements Document, TrackCreationInterface
|
||||
$this->uuid = Uuid::uuid4();
|
||||
$this->versions = new ArrayCollection();
|
||||
$this->prefix = self::generatePrefix();
|
||||
$this->locks = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal use @see{StoredObjectLock::__construct}
|
||||
*/
|
||||
public function addLock(StoredObjectLock $lock): void
|
||||
{
|
||||
if (!$this->locks->contains($lock)) {
|
||||
$this->locks->add($lock);
|
||||
}
|
||||
}
|
||||
|
||||
public function removeLock(StoredObjectLock $lock): void
|
||||
{
|
||||
$this->locks->removeElement($lock);
|
||||
}
|
||||
|
||||
public function isLockedAt(\DateTimeImmutable $at): bool
|
||||
{
|
||||
foreach ($this->locks as $lock) {
|
||||
if ($lock->isActiveAt($at)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, StoredObjectLock>
|
||||
*/
|
||||
public function getLocks(): Collection
|
||||
{
|
||||
return $this->locks;
|
||||
}
|
||||
|
||||
public function addGenerationTrial(): self
|
||||
|
||||
132
src/Bundle/ChillDocStoreBundle/Entity/StoredObjectLock.php
Normal file
132
src/Bundle/ChillDocStoreBundle/Entity/StoredObjectLock.php
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\DocStoreBundle\Entity;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Ramsey\Uuid\UuidInterface;
|
||||
|
||||
#[ORM\Entity]
|
||||
#[ORM\Table(name: 'stored_object_lock', schema: 'chill_doc')]
|
||||
class StoredObjectLock
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(type: 'uuid', unique: true)]
|
||||
private UuidInterface $uuid;
|
||||
|
||||
/**
|
||||
* @var Collection<int, User>
|
||||
*/
|
||||
#[ORM\ManyToMany(targetEntity: User::class)]
|
||||
#[ORM\JoinTable(name: 'stored_object_lock_user', schema: 'chill_doc')]
|
||||
#[ORM\JoinColumn(referencedColumnName: 'uuid', nullable: false)]
|
||||
private Collection $users;
|
||||
|
||||
/**
|
||||
* @param list<User> $users
|
||||
*/
|
||||
public function __construct(
|
||||
#[ORM\ManyToOne(targetEntity: StoredObject::class, inversedBy: 'locks')]
|
||||
private StoredObject $storedObject,
|
||||
#[ORM\Column(type: 'string', length: 10, nullable: false, enumType: StoredObjectLockMethodEnum::class)]
|
||||
private StoredObjectLockMethodEnum $method,
|
||||
#[ORM\Column(type: 'datetimetz_immutable', nullable: false)]
|
||||
private \DateTimeImmutable $createdAt,
|
||||
#[ORM\Column(type: 'text', nullable: false, options: ['default' => ''])]
|
||||
private string $token = '',
|
||||
#[ORM\Column(type: 'datetimetz_immutable', nullable: true)]
|
||||
private ?\DateTimeImmutable $expireAt = null,
|
||||
array $users = [],
|
||||
) {
|
||||
$this->uuid = Uuid::uuid7();
|
||||
$this->users = new ArrayCollection();
|
||||
$this->storedObject->addLock($this);
|
||||
|
||||
foreach ($users as $user) {
|
||||
$this->addUser($user);
|
||||
}
|
||||
}
|
||||
|
||||
public function addUser(User $user): void
|
||||
{
|
||||
if (!$this->users->contains($user)) {
|
||||
$this->users->add($user);
|
||||
}
|
||||
}
|
||||
|
||||
public function removeUser(User $user): void
|
||||
{
|
||||
$this->users->removeElement($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, User>
|
||||
*/
|
||||
public function getUsers(): Collection
|
||||
{
|
||||
return $this->users;
|
||||
}
|
||||
|
||||
public function setToken(string $token): void
|
||||
{
|
||||
$this->token = $token;
|
||||
}
|
||||
|
||||
public function setExpireAt(?\DateTimeImmutable $expireAt): void
|
||||
{
|
||||
$this->expireAt = $expireAt;
|
||||
}
|
||||
|
||||
public function getUuid(): UuidInterface
|
||||
{
|
||||
return $this->uuid;
|
||||
}
|
||||
|
||||
public function getStoredObject(): StoredObject
|
||||
{
|
||||
return $this->storedObject;
|
||||
}
|
||||
|
||||
public function getMethod(): StoredObjectLockMethodEnum
|
||||
{
|
||||
return $this->method;
|
||||
}
|
||||
|
||||
public function getToken(): string
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
public function getCreatedAt(): \DateTimeImmutable
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
public function getExpireAt(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->expireAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the lock must be considered as active.
|
||||
*
|
||||
* A StoredObjectLock is active if there isn't any expiration date, or
|
||||
* if the expiration date and time is before the given time.
|
||||
*/
|
||||
public function isActiveAt(\DateTimeImmutable $at): bool
|
||||
{
|
||||
return null === $this->getExpireAt() || $at < $this->getExpireAt();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\DocStoreBundle\Entity;
|
||||
|
||||
enum StoredObjectLockMethodEnum: string
|
||||
{
|
||||
case WEBDAV = 'webdav';
|
||||
case WOPI = 'wopi';
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\DocStoreBundle\Tests\Entity;
|
||||
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\DocStoreBundle\Entity\StoredObjectLock;
|
||||
use Chill\DocStoreBundle\Entity\StoredObjectLockMethodEnum;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @covers \Chill\DocStoreBundle\Entity\StoredObjectLock
|
||||
*/
|
||||
class StoredObjectLockTest extends TestCase
|
||||
{
|
||||
public function testIsActiveAtWithNoExpiration(): void
|
||||
{
|
||||
$storedObject = new StoredObject();
|
||||
$now = new \DateTimeImmutable();
|
||||
$lock = new StoredObjectLock(
|
||||
$storedObject,
|
||||
StoredObjectLockMethodEnum::WOPI,
|
||||
$now,
|
||||
'token',
|
||||
null
|
||||
);
|
||||
|
||||
self::assertTrue($lock->isActiveAt($now));
|
||||
self::assertTrue($lock->isActiveAt($now->modify('+1 year')));
|
||||
}
|
||||
|
||||
public function testIsActiveAtWithFutureExpiration(): void
|
||||
{
|
||||
$storedObject = new StoredObject();
|
||||
$now = new \DateTimeImmutable();
|
||||
$expireAt = $now->modify('+1 hour');
|
||||
$lock = new StoredObjectLock(
|
||||
$storedObject,
|
||||
StoredObjectLockMethodEnum::WOPI,
|
||||
$now,
|
||||
'token',
|
||||
$expireAt
|
||||
);
|
||||
|
||||
self::assertTrue($lock->isActiveAt($now));
|
||||
self::assertTrue($lock->isActiveAt($now->modify('+30 minutes')));
|
||||
}
|
||||
|
||||
public function testIsActiveAtWithPastExpiration(): void
|
||||
{
|
||||
$storedObject = new StoredObject();
|
||||
$now = new \DateTimeImmutable();
|
||||
$expireAt = $now->modify('-1 hour');
|
||||
$lock = new StoredObjectLock(
|
||||
$storedObject,
|
||||
StoredObjectLockMethodEnum::WOPI,
|
||||
$now->modify('-2 hours'),
|
||||
'token',
|
||||
$expireAt
|
||||
);
|
||||
|
||||
self::assertFalse($lock->isActiveAt($now));
|
||||
self::assertFalse($lock->isActiveAt($expireAt));
|
||||
self::assertFalse($lock->isActiveAt($expireAt->modify('+1 second')));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\Migrations\DocStore;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20260331122339 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Add locks for stored objects';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('CREATE TABLE chill_doc.stored_object_lock (
|
||||
uuid UUID NOT NULL, method VARCHAR(10) NOT NULL,
|
||||
token TEXT DEFAULT \'\' NOT NULL, createdAt TIMESTAMP(0) WITH TIME ZONE NOT NULL,
|
||||
expireAt TIMESTAMP(0) WITH TIME ZONE DEFAULT NULL, storedObject_id INT DEFAULT NULL,
|
||||
PRIMARY KEY(uuid))');
|
||||
$this->addSql('CREATE INDEX IDX_E66CB6516C99C13A ON chill_doc.stored_object_lock (storedObject_id)');
|
||||
$this->addSql('COMMENT ON COLUMN chill_doc.stored_object_lock.uuid IS \'(DC2Type:uuid)\'');
|
||||
$this->addSql('COMMENT ON COLUMN chill_doc.stored_object_lock.createdAt IS \'(DC2Type:datetimetz_immutable)\'');
|
||||
$this->addSql('COMMENT ON COLUMN chill_doc.stored_object_lock.expireAt IS \'(DC2Type:datetimetz_immutable)\'');
|
||||
$this->addSql('ALTER TABLE chill_doc.stored_object_lock ADD CONSTRAINT FK_E66CB6516C99C13A FOREIGN KEY (storedObject_id) REFERENCES chill_doc.stored_object (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||
$this->addSql('CREATE TABLE chill_doc.stored_object_lock_user (storedobjectlock_uuid UUID NOT NULL, user_id INT NOT NULL, PRIMARY KEY(storedobjectlock_uuid, user_id))');
|
||||
$this->addSql('CREATE INDEX IDX_A4353741F52905D0 ON chill_doc.stored_object_lock_user (storedobjectlock_uuid)');
|
||||
$this->addSql('CREATE INDEX IDX_A4353741A76ED395 ON chill_doc.stored_object_lock_user (user_id)');
|
||||
$this->addSql('COMMENT ON COLUMN chill_doc.stored_object_lock_user.storedobjectlock_uuid IS \'(DC2Type:uuid)\'');
|
||||
$this->addSql('ALTER TABLE chill_doc.stored_object_lock_user ADD CONSTRAINT FK_A4353741F52905D0 FOREIGN KEY (storedobjectlock_uuid) REFERENCES chill_doc.stored_object_lock (uuid) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||
$this->addSql('ALTER TABLE chill_doc.stored_object_lock_user ADD CONSTRAINT FK_A4353741A76ED395 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE chill_doc.stored_object_lock_user DROP CONSTRAINT FK_A4353741F52905D0');
|
||||
$this->addSql('ALTER TABLE chill_doc.stored_object_lock_user DROP CONSTRAINT FK_A4353741A76ED395');
|
||||
$this->addSql('DROP TABLE chill_doc.stored_object_lock_user');
|
||||
$this->addSql('ALTER TABLE chill_doc.stored_object_lock DROP CONSTRAINT FK_E66CB6516C99C13A');
|
||||
$this->addSql('DROP TABLE chill_doc.stored_object_lock');
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,9 @@ class Center implements HasCenterInterface, \Stringable
|
||||
#[ORM\ManyToMany(targetEntity: Regroupment::class, mappedBy: 'centers')]
|
||||
private Collection $regroupments;
|
||||
|
||||
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::TEXT, options: ['default' => ''])]
|
||||
private string $externalId = '';
|
||||
|
||||
/**
|
||||
* Center constructor.
|
||||
*/
|
||||
@@ -124,4 +127,19 @@ class Center implements HasCenterInterface, \Stringable
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getExternalId(): string
|
||||
{
|
||||
return $this->externalId;
|
||||
}
|
||||
|
||||
public function setExternalId(string $externalId): void
|
||||
{
|
||||
$this->externalId = $externalId;
|
||||
}
|
||||
|
||||
public function hasExternalId(): bool
|
||||
{
|
||||
return '' !== $this->externalId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,6 +101,9 @@ class NotificationMailer
|
||||
if (null === $addressee->getEmail()) {
|
||||
continue;
|
||||
}
|
||||
if ($notification->getSender() === $addressee) {
|
||||
continue;
|
||||
}
|
||||
$this->processNotificationForAddressee($notification, $addressee);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,11 @@ final readonly class CenterRepository implements CenterRepositoryInterface
|
||||
return $this->repository->find($id, $lockMode, $lockVersion);
|
||||
}
|
||||
|
||||
public function findOneByExternalId(string $externalId): ?Center
|
||||
{
|
||||
return $this->repository->findOneBy(['externalId' => $externalId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Center[]
|
||||
*/
|
||||
|
||||
@@ -24,4 +24,6 @@ interface CenterRepositoryInterface extends ObjectRepository
|
||||
* @return Center[]
|
||||
*/
|
||||
public function findActive(): array;
|
||||
|
||||
public function findOneByExternalId(string $externalId): ?Center;
|
||||
}
|
||||
|
||||
@@ -14,9 +14,8 @@ namespace Chill\MainBundle\Repository;
|
||||
use Chill\MainBundle\Entity\GroupCenter;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
|
||||
final readonly class GroupCenterRepository implements ObjectRepository
|
||||
final readonly class GroupCenterRepository implements GroupCenterRepositoryInterface
|
||||
{
|
||||
private EntityRepository $repository;
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Repository;
|
||||
|
||||
use Chill\MainBundle\Entity\GroupCenter;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
|
||||
/**
|
||||
* @extends ObjectRepository<GroupCenter>
|
||||
*/
|
||||
interface GroupCenterRepositoryInterface extends ObjectRepository
|
||||
{
|
||||
public function find($id, $lockMode = null, $lockVersion = null): ?GroupCenter;
|
||||
|
||||
/**
|
||||
* @return GroupCenter[]
|
||||
*/
|
||||
public function findAll(): array;
|
||||
|
||||
/**
|
||||
* @param mixed|null $limit
|
||||
* @param mixed|null $offset
|
||||
*
|
||||
* @return GroupCenter[]
|
||||
*/
|
||||
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array;
|
||||
|
||||
public function findOneBy(array $criteria, ?array $orderBy = null): ?GroupCenter;
|
||||
|
||||
public function getClassName();
|
||||
}
|
||||
@@ -13,7 +13,12 @@
|
||||
> {{ line }}
|
||||
{% endfor %}
|
||||
|
||||
{% if dest.isUser %}
|
||||
[Vous pouvez visualiser la notification et y répondre ici.]({{ absolute_url(path('chill_main_notification_show', {'_locale': dest.locale, 'id': notification.id }, false)) }})
|
||||
{% else %}
|
||||
[Vous pouvez visualiser la notification et y répondre ici.]({{ absolute_url(path('chill_main_notification_grant_access_by_access_key', {'_locale': dest.locale, 'id': notification.id, 'accessKey': notification.accessKey }, false)) }})
|
||||
{% endif %}
|
||||
|
||||
|
||||
-----
|
||||
|
||||
|
||||
@@ -12,7 +12,11 @@ Titre de la notification: {{ notification.title }}
|
||||
> {{ line|raw }}
|
||||
{% endfor %}
|
||||
|
||||
Vous pouvez visualiser la notification et y répondre ici: {{ absolute_url(path('chill_main_notification_show', {'_locale': dest.locale, 'id': notification.id }, false)) }}.
|
||||
{% if dest.isUser %}
|
||||
[Vous pouvez visualiser la notification et y répondre ici.]({{ absolute_url(path('chill_main_notification_show', {'_locale': dest.locale, 'id': notification.id }, false)) }})
|
||||
{% else %}
|
||||
[Vous pouvez visualiser la notification et y répondre ici.]({{ absolute_url(path('chill_main_notification_grant_access_by_access_key', {'_locale': dest.locale, 'id': notification.id, 'accessKey': notification.accessKey }, false)) }})
|
||||
{% endif %}
|
||||
|
||||
--
|
||||
Le logiciel Chill
|
||||
|
||||
30
src/Bundle/ChillMainBundle/Test/RandomUserTrait.php
Normal file
30
src/Bundle/ChillMainBundle/Test/RandomUserTrait.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Test;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
trait RandomUserTrait
|
||||
{
|
||||
public function getRandomUser(EntityManagerInterface $em): User
|
||||
{
|
||||
$userRepository = $em->getRepository(User::class);
|
||||
$count = $userRepository->count([]);
|
||||
$random = mt_rand(0, $count - 1);
|
||||
|
||||
return $em->createQuery('SELECT u FROM '.User::class.' u ')
|
||||
->setMaxResults(1)
|
||||
->setFirstResult($random)
|
||||
->getSingleResult();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\Migrations\Main;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20260324144420 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Add an external id for centers';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE public.centers ADD externalId TEXT DEFAULT \'\' NOT NULL');
|
||||
$this->addSql('CREATE UNIQUE INDEX centers_external_id_unique ON public.centers (externalId) WHERE externalId <> \'\'');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('DROP INDEX public.centers_external_id_unique');
|
||||
$this->addSql('ALTER TABLE public.centers DROP externalId');
|
||||
}
|
||||
}
|
||||
@@ -13,10 +13,19 @@ namespace Chill\WopiBundle\Service\Wopi;
|
||||
|
||||
use ChampsLibres\WopiLib\Contract\Entity\Document;
|
||||
use ChampsLibres\WopiLib\Contract\Service\DocumentLockManagerInterface;
|
||||
use Chill\MainBundle\Redis\ChillRedis;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\DocStoreBundle\Entity\StoredObjectLock;
|
||||
use Chill\DocStoreBundle\Entity\StoredObjectLockMethodEnum;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Symfony\Component\Clock\ClockInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpKernel\Event\TerminateEvent;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
class ChillDocumentLockManager implements DocumentLockManagerInterface
|
||||
final class ChillDocumentLockManager implements DocumentLockManagerInterface, EventSubscriberInterface
|
||||
{
|
||||
private const LOCK_DURATION = 60 * 30;
|
||||
|
||||
@@ -25,26 +34,43 @@ class ChillDocumentLockManager implements DocumentLockManagerInterface
|
||||
*/
|
||||
private const LOCK_GRACEFUL_DURATION_TIME = 3;
|
||||
|
||||
private bool $mustFlush = false;
|
||||
|
||||
public function __construct(
|
||||
private readonly ChillRedis $redis,
|
||||
private readonly Security $security,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly ClockInterface $clock,
|
||||
private readonly int $ttlAfterDeleteSeconds = self::LOCK_GRACEFUL_DURATION_TIME,
|
||||
) {}
|
||||
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
return [TerminateEvent::class => 'onKernelTerminate'];
|
||||
}
|
||||
|
||||
public function deleteLock(Document $document, RequestInterface $request): bool
|
||||
{
|
||||
if (0 === $this->redis->exists($this->getCacheId($document))) {
|
||||
return true;
|
||||
Assert::isInstanceOf($document, StoredObject::class);
|
||||
|
||||
foreach ($document->getLocks() as $lock) {
|
||||
if ($lock->isActiveAt($this->clock->now())) {
|
||||
$lock->setExpireAt($this->clock->now()->add(new \DateInterval('PT'.$this->ttlAfterDeleteSeconds.'S')));
|
||||
$this->mustFlush = true;
|
||||
}
|
||||
}
|
||||
|
||||
// some queries (ex.: putFile) may be executed on the same time than the unlock, so
|
||||
// we add a delay before unlocking the file, instead of deleting it immediatly
|
||||
return $this->redis->expire($this->getCacheId($document), $this->ttlAfterDeleteSeconds);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public function getLock(Document $document, RequestInterface $request): string
|
||||
{
|
||||
if (false !== $value = $this->redis->get($this->getCacheId($document))) {
|
||||
return $value;
|
||||
Assert::isInstanceOf($document, StoredObject::class);
|
||||
|
||||
foreach ($document->getLocks() as $lock) {
|
||||
if ($lock->isActiveAt($this->clock->now())) {
|
||||
return $lock->getToken();
|
||||
}
|
||||
}
|
||||
|
||||
throw new \RuntimeException('wopi key does not exists');
|
||||
@@ -52,28 +78,61 @@ class ChillDocumentLockManager implements DocumentLockManagerInterface
|
||||
|
||||
public function hasLock(Document $document, RequestInterface $request): bool
|
||||
{
|
||||
$r = $this->redis->exists($this->getCacheId($document));
|
||||
Assert::isInstanceOf($document, StoredObject::class);
|
||||
|
||||
if (is_bool($r)) {
|
||||
return $r;
|
||||
}
|
||||
if (is_int($r)) {
|
||||
return $r > 0;
|
||||
foreach ($document->getLocks() as $lock) {
|
||||
if ($lock->isActiveAt($this->clock->now())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
throw new \RuntimeException('data type not supported');
|
||||
return false;
|
||||
}
|
||||
|
||||
public function onKernelTerminate(TerminateEvent $event): void
|
||||
{
|
||||
if ($this->mustFlush) {
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
}
|
||||
|
||||
public function setLock(Document $document, string $lockId, RequestInterface $request): bool
|
||||
{
|
||||
$key = $this->getCacheId($document);
|
||||
$this->redis->setex($key, self::LOCK_DURATION, $lockId);
|
||||
Assert::isInstanceOf($document, StoredObject::class);
|
||||
$user = $this->security->getUser();
|
||||
|
||||
if ($document->isLockedAt($this->clock->now())) {
|
||||
foreach ($document->getLocks() as $lock) {
|
||||
if ($lock->isActiveAt($this->clock->now())) {
|
||||
$lock->setToken($lockId);
|
||||
$lock->setExpireAt($this->clock->now()->add(new \DateInterval('PT'.self::LOCK_DURATION.'S')));
|
||||
if ($user instanceof User) {
|
||||
$lock->addUser($user);
|
||||
}
|
||||
|
||||
$this->mustFlush = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// there is no lock yet, we must create one
|
||||
$lock = new StoredObjectLock(
|
||||
$document,
|
||||
method: StoredObjectLockMethodEnum::WOPI,
|
||||
createdAt: $this->clock->now(),
|
||||
token: $lockId,
|
||||
expireAt: $this->clock->now()->add(new \DateInterval('PT'.self::LOCK_DURATION.'S')),
|
||||
);
|
||||
|
||||
if ($user instanceof User) {
|
||||
$lock->addUser($user);
|
||||
}
|
||||
|
||||
$this->entityManager->persist($lock);
|
||||
$this->mustFlush = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function getCacheId(Document $document): string
|
||||
{
|
||||
return sprintf('wopi_lib_lock_%s', $document->getWopiDocId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,11 +12,15 @@ declare(strict_types=1);
|
||||
namespace Chill\WopiBundle\Tests\Service\Wopi;
|
||||
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\MainBundle\Redis\ChillRedis;
|
||||
use Chill\MainBundle\Test\RandomUserTrait;
|
||||
use Chill\WopiBundle\Service\Wopi\ChillDocumentLockManager;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Clock\MockClock;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@@ -27,14 +31,31 @@ final class ChillDocumentLockManagerTest extends KernelTestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
use RandomUserTrait;
|
||||
|
||||
private MockClock $clock;
|
||||
|
||||
/**
|
||||
* @var ObjectProphecy<Security>
|
||||
*/
|
||||
private ObjectProphecy $security;
|
||||
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
$this->em = self::getContainer()->get('doctrine.orm.entity_manager');
|
||||
$this->security = $this->prophesize(Security::class);
|
||||
$this->clock = new MockClock();
|
||||
}
|
||||
|
||||
public function testRelock()
|
||||
{
|
||||
$user = $this->getRandomUser($this->em);
|
||||
$this->security->getUser()->willReturn($user);
|
||||
$manager = $this->makeManager(1);
|
||||
|
||||
$document = new StoredObject();
|
||||
$request = $this->prophesize(RequestInterface::class);
|
||||
|
||||
@@ -50,15 +71,22 @@ final class ChillDocumentLockManagerTest extends KernelTestCase
|
||||
|
||||
$this->assertTrue($manager->deleteLock($document, $request->reveal()));
|
||||
|
||||
sleep(3); // wait for redis to remove the key
|
||||
$this->clock->sleep(10);
|
||||
|
||||
$this->assertFalse($manager->hasLock($document, $request->reveal()));
|
||||
$this->em->remove($document);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
public function testSingleLock()
|
||||
{
|
||||
$user = $this->getRandomUser($this->em);
|
||||
$this->security->getUser()->willReturn($user);
|
||||
$manager = $this->makeManager(1);
|
||||
$document = new StoredObject();
|
||||
$this->em->persist($document);
|
||||
$this->em->flush();
|
||||
|
||||
$request = $this->prophesize(RequestInterface::class);
|
||||
|
||||
$this->assertFalse($manager->hasLock($document, $request->reveal()));
|
||||
@@ -69,15 +97,16 @@ final class ChillDocumentLockManagerTest extends KernelTestCase
|
||||
|
||||
$this->assertTrue($manager->deleteLock($document, $request->reveal()));
|
||||
|
||||
sleep(3); // wait for redis to remove the key
|
||||
$this->clock->sleep(10);
|
||||
|
||||
$this->assertFalse($manager->hasLock($document, $request->reveal()));
|
||||
|
||||
$this->em->remove($document);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
private function makeManager(int $ttlAfterDeleteSeconds = -1): ChillDocumentLockManager
|
||||
{
|
||||
$redis = self::getContainer()->get(ChillRedis::class);
|
||||
|
||||
return new ChillDocumentLockManager($redis, $ttlAfterDeleteSeconds);
|
||||
return new ChillDocumentLockManager($this->security->reveal(), $this->em, $this->clock, $ttlAfterDeleteSeconds);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user