Resolve merge with master

This commit is contained in:
2024-12-11 10:46:06 +01:00
667 changed files with 37245 additions and 7119 deletions

View File

@@ -12,8 +12,12 @@ declare(strict_types=1);
namespace Chill\ActivityBundle\DataFixtures\ORM;
use Chill\ActivityBundle\Entity\Activity;
use Chill\ActivityBundle\Entity\ActivityReason;
use Chill\ActivityBundle\Entity\ActivityType;
use Chill\MainBundle\DataFixtures\ORM\LoadScopes;
use Chill\MainBundle\DataFixtures\ORM\LoadUsers;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Entity\Person;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
@@ -32,12 +36,12 @@ class LoadActivity extends AbstractFixture implements OrderedFixtureInterface
$this->faker = FakerFactory::create('fr_FR');
}
public function getOrder()
public function getOrder(): int
{
return 16400;
}
public function load(ObjectManager $manager)
public function load(ObjectManager $manager): void
{
$persons = $this->em
->getRepository(Person::class)
@@ -84,49 +88,41 @@ class LoadActivity extends AbstractFixture implements OrderedFixtureInterface
/**
* Return a random activityReason.
*
* @return \Chill\ActivityBundle\Entity\ActivityReason
*/
private function getRandomActivityReason()
private function getRandomActivityReason(): ActivityReason
{
$reasonRef = LoadActivityReason::$references[array_rand(LoadActivityReason::$references)];
return $this->getReference($reasonRef);
return $this->getReference($reasonRef, ActivityReason::class);
}
/**
* Return a random activityType.
*
* @return \Chill\ActivityBundle\Entity\ActivityType
*/
private function getRandomActivityType()
private function getRandomActivityType(): ActivityType
{
$typeRef = LoadActivityType::$references[array_rand(LoadActivityType::$references)];
return $this->getReference($typeRef);
return $this->getReference($typeRef, ActivityType::class);
}
/**
* Return a random scope.
*
* @return \Chill\MainBundle\Entity\Scope
*/
private function getRandomScope()
private function getRandomScope(): Scope
{
$scopeRef = LoadScopes::$references[array_rand(LoadScopes::$references)];
return $this->getReference($scopeRef);
return $this->getReference($scopeRef, Scope::class);
}
/**
* Return a random user.
*
* @return \Chill\MainBundle\Entity\User
*/
private function getRandomUser()
private function getRandomUser(): User
{
$userRef = array_rand(LoadUsers::$refs);
return $this->getReference($userRef);
return $this->getReference($userRef, User::class);
}
}

View File

@@ -38,7 +38,7 @@ class LoadActivityNotifications extends AbstractFixture implements DependentFixt
],
];
public function getDependencies()
public function getDependencies(): array
{
return [
LoadActivity::class,

View File

@@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Chill\ActivityBundle\DataFixtures\ORM;
use Chill\ActivityBundle\Entity\ActivityReason;
use Chill\ActivityBundle\Entity\ActivityReasonCategory;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Persistence\ObjectManager;
@@ -23,12 +24,12 @@ class LoadActivityReason extends AbstractFixture implements OrderedFixtureInterf
{
public static $references = [];
public function getOrder()
public function getOrder(): int
{
return 16300;
}
public function load(ObjectManager $manager)
public function load(ObjectManager $manager): void
{
$reasons = [
[
@@ -56,7 +57,7 @@ class LoadActivityReason extends AbstractFixture implements OrderedFixtureInterf
$activityReason = (new ActivityReason())
->setName($r['name'])
->setActive(true)
->setCategory($this->getReference($r['category']));
->setCategory($this->getReference($r['category'], ActivityReasonCategory::class));
$manager->persist($activityReason);
$reference = 'activity_reason_'.$r['name']['en'];
$this->addReference($reference, $activityReason);

View File

@@ -21,12 +21,12 @@ use Doctrine\Persistence\ObjectManager;
*/
class LoadActivityReasonCategory extends AbstractFixture implements OrderedFixtureInterface
{
public function getOrder()
public function getOrder(): int
{
return 16200;
}
public function load(ObjectManager $manager)
public function load(ObjectManager $manager): void
{
$categs = [
['name' => ['fr' => 'Logement', 'en' => 'Housing', 'nl' => 'Woning']],

View File

@@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Chill\ActivityBundle\DataFixtures\ORM;
use Chill\ActivityBundle\Entity\ActivityType;
use Chill\ActivityBundle\Entity\ActivityTypeCategory;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Persistence\ObjectManager;
@@ -23,12 +24,12 @@ class LoadActivityType extends Fixture implements OrderedFixtureInterface
{
public static $references = [];
public function getOrder()
public function getOrder(): int
{
return 16100;
}
public function load(ObjectManager $manager)
public function load(ObjectManager $manager): void
{
$types = [
// Exange
@@ -57,7 +58,7 @@ class LoadActivityType extends Fixture implements OrderedFixtureInterface
echo 'Creating activity type : '.$t['name']['fr'].' (cat:'.$t['category']." \n";
$activityType = (new ActivityType())
->setName($t['name'])
->setCategory($this->getReference('activity_type_cat_'.$t['category']))
->setCategory($this->getReference('activity_type_cat_'.$t['category'], ActivityTypeCategory::class))
->setSocialIssuesVisible(1)
->setSocialActionsVisible(1);
$manager->persist($activityType);

View File

@@ -23,12 +23,12 @@ class LoadActivityTypeCategory extends Fixture implements OrderedFixtureInterfac
{
public static $references = [];
public function getOrder()
public function getOrder(): int
{
return 16050;
}
public function load(ObjectManager $manager)
public function load(ObjectManager $manager): void
{
$categories = [
[

View File

@@ -15,7 +15,9 @@ use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter;
use Chill\ActivityBundle\Security\Authorization\ActivityVoter;
use Chill\MainBundle\DataFixtures\ORM\LoadPermissionsGroup;
use Chill\MainBundle\DataFixtures\ORM\LoadScopes;
use Chill\MainBundle\Entity\PermissionsGroup;
use Chill\MainBundle\Entity\RoleScope;
use Chill\MainBundle\Entity\Scope;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Persistence\ObjectManager;
@@ -26,18 +28,18 @@ use Doctrine\Persistence\ObjectManager;
*/
class LoadActivitytACL extends AbstractFixture implements OrderedFixtureInterface
{
public function getOrder()
public function getOrder(): int
{
return 16000;
}
public function load(ObjectManager $manager)
public function load(ObjectManager $manager): void
{
foreach (LoadPermissionsGroup::$refs as $permissionsGroupRef) {
$permissionsGroup = $this->getReference($permissionsGroupRef);
$permissionsGroup = $this->getReference($permissionsGroupRef, PermissionsGroup::class);
foreach (LoadScopes::$references as $scopeRef) {
$scope = $this->getReference($scopeRef);
$scope = $this->getReference($scopeRef, Scope::class);
// create permission group
switch ($permissionsGroup->getName()) {
case 'social':

View File

@@ -107,7 +107,7 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac
private ?Person $person = null;
/**
* @var Collection<int, \Chill\PersonBundle\Entity\Person>
* @var Collection<int, Person>
*/
#[Groups(['read', 'docgen:read'])]
#[ORM\ManyToMany(targetEntity: Person::class)]
@@ -132,7 +132,7 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac
private string $sentReceived = '';
/**
* @var Collection<int, \Chill\PersonBundle\Entity\SocialWork\SocialAction>
* @var Collection<int, SocialAction>
*/
#[Groups(['read', 'docgen:read'])]
#[ORM\ManyToMany(targetEntity: SocialAction::class)]

View File

@@ -32,8 +32,8 @@ class ActivityReason
#[ORM\GeneratedValue(strategy: 'AUTO')]
private ?int $id = null;
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::JSON)]
private array $name;
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::JSON, options: ['default' => '{}', 'jsonb' => true])]
private array $name = [];
/**
* Get active.

View File

@@ -31,11 +31,9 @@ class ActivityReasonCategory implements \Stringable
#[ORM\GeneratedValue(strategy: 'AUTO')]
private ?int $id = null;
/**
* @var string
*/
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::JSON)]
private $name;
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::JSON, options: ['default' => '{}', 'jsonb' => true])]
private array $name = [];
/**
* Array of ActivityReason.
@@ -127,11 +125,9 @@ class ActivityReasonCategory implements \Stringable
/**
* Set name.
*
* @param array $name
*
* @return ActivityReasonCategory
*/
public function setName($name)
public function setName(array $name)
{
$this->name = $name;

View File

@@ -12,6 +12,8 @@ declare(strict_types=1);
namespace Chill\ActivityBundle\Repository;
use Chill\ActivityBundle\Entity\Activity;
use Chill\DocStoreBundle\Entity\StoredObject;
use Chill\DocStoreBundle\Repository\AssociatedEntityToStoredObjectInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Person;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
@@ -23,7 +25,7 @@ use Doctrine\Persistence\ManagerRegistry;
* @method Activity[] findAll()
* @method Activity[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class ActivityRepository extends ServiceEntityRepository
class ActivityRepository extends ServiceEntityRepository implements AssociatedEntityToStoredObjectInterface
{
public function __construct(ManagerRegistry $registry)
{
@@ -97,4 +99,16 @@ class ActivityRepository extends ServiceEntityRepository
return $qb->getQuery()->getResult();
}
public function findAssociatedEntityToStoredObject(StoredObject $storedObject): ?Activity
{
$qb = $this->createQueryBuilder('a');
$query = $qb
->leftJoin('a.documents', 'ad')
->where('ad.id = :storedObjectId')
->setParameter('storedObjectId', $storedObject->getId())
->getQuery();
return $query->getOneOrNullResult();
}
}

View File

@@ -0,0 +1,54 @@
<?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\ActivityBundle\Security\Authorization;
use Chill\ActivityBundle\Entity\Activity;
use Chill\ActivityBundle\Repository\ActivityRepository;
use Chill\DocStoreBundle\Repository\AssociatedEntityToStoredObjectInterface;
use Chill\DocStoreBundle\Security\Authorization\StoredObjectRoleEnum;
use Chill\DocStoreBundle\Security\Authorization\StoredObjectVoter\AbstractStoredObjectVoter;
use Chill\MainBundle\Workflow\Helper\WorkflowRelatedEntityPermissionHelper;
use Symfony\Component\Security\Core\Security;
class ActivityStoredObjectVoter extends AbstractStoredObjectVoter
{
public function __construct(
private readonly ActivityRepository $repository,
Security $security,
WorkflowRelatedEntityPermissionHelper $workflowDocumentService,
) {
parent::__construct($security, $workflowDocumentService);
}
protected function getRepository(): AssociatedEntityToStoredObjectInterface
{
return $this->repository;
}
protected function getClass(): string
{
return Activity::class;
}
protected function attributeToRole(StoredObjectRoleEnum $attribute): string
{
return match ($attribute) {
StoredObjectRoleEnum::EDIT => ActivityVoter::UPDATE,
StoredObjectRoleEnum::SEE => ActivityVoter::SEE_DETAILS,
};
}
protected function canBeAssociatedWithWorkflow(): bool
{
return false;
}
}

View File

@@ -0,0 +1,41 @@
<?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\Activity;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20240918142723 extends AbstractMigration
{
public function getDescription(): string
{
return 'Fix not null and default values for activityreason, activityreasoncategory, comments on activity';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE activity ALTER privatecomment_comments SET NOT NULL');
$this->addSql('ALTER TABLE activityreason ALTER name SET DEFAULT \'{}\'');
$this->addSql('ALTER TABLE activityreason ALTER name SET NOT NULL');
$this->addSql('ALTER INDEX idx_654a2fcd12469de2 RENAME TO IDX_AF82522312469DE2');
$this->addSql('ALTER TABLE activityreasoncategory ALTER name SET DEFAULT \'{}\'');
$this->addSql('ALTER TABLE activityreasoncategory ALTER name SET NOT NULL');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE activityreason ALTER name DROP DEFAULT');
$this->addSql('ALTER TABLE activityreason ALTER name DROP NOT NULL');
$this->addSql('ALTER TABLE activityreasoncategory ALTER name DROP DEFAULT');
$this->addSql('ALTER TABLE activityreasoncategory ALTER name DROP NOT NULL');
}
}

View File

@@ -0,0 +1,46 @@
<?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\Activity;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20241202173942 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add a unique constraint on the storedobject linked to an activity';
}
public function up(Schema $schema): void
{
$this->addSql(
'WITH duplicate_activities AS (
SELECT storedobject_id, array_agg(activity_id ORDER BY activity_id DESC) AS activities
FROM activity_storedobject
GROUP BY storedobject_id
HAVING count(*) > 1
)
DELETE FROM activity_storedobject
WHERE activity_id IN (
SELECT unnest(activities[2:]) -- Keep the highest ID, delete the rest
FROM duplicate_activities
);'
);
$this->addSql('CREATE UNIQUE INDEX unique_storedobject_id ON activity_storedobject (storedobject_id)');
}
public function down(Schema $schema): void
{
$this->addSql('DROP INDEX IF EXISTS unique_storedobject_id');
}
}