fix cs + read remote calendar based on user access

This commit is contained in:
2022-05-09 13:36:59 +02:00
parent 811798e23f
commit 8abce5ab85
17 changed files with 189 additions and 115 deletions

View File

@@ -361,13 +361,6 @@ class User implements AdvancedUserInterface
return $this;
}
public function unsetAttribute($key): self
{
unset($this->attributes[$key]);
return $this;
}
public function setCurrentLocation(?Location $currentLocation): User
{
$this->currentLocation = $currentLocation;
@@ -494,4 +487,11 @@ class User implements AdvancedUserInterface
return $this;
}
public function unsetAttribute($key): self
{
unset($this->attributes[$key]);
return $this;
}
}

View File

@@ -44,6 +44,16 @@ final class UserRepository implements ObjectRepository
return $this->countBy(['enabled' => true]);
}
public function countByNotHavingAttribute(string $key): int
{
$rsm = new ResultSetMapping();
$rsm->addScalarResult('count', 'count');
$sql = 'SELECT count(*) FROM users u WHERE NOT attributes ?? :key OR attributes IS NULL AND enabled IS TRUE';
return $this->entityManager->createNativeQuery($sql, $rsm)->setParameter(':key', $key)->getSingleScalarResult();
}
public function countByUsernameOrEmail(string $pattern): int
{
$qb = $this->queryByUsernameOrEmail($pattern);
@@ -85,6 +95,29 @@ final class UserRepository implements ObjectRepository
return $this->findBy(['enabled' => true], $orderBy, $limit, $offset);
}
/**
* Find users which does not have a key on attribute column.
*
* @return array|User[]
*/
public function findByNotHavingAttribute(string $key, ?int $limit = null, ?int $offset = null): array
{
$rsm = new ResultSetMappingBuilder($this->entityManager);
$rsm->addRootEntityFromClassMetadata(User::class, 'u');
$sql = 'SELECT ' . $rsm->generateSelectClause() . ' FROM users u WHERE NOT attributes ?? :key OR attributes IS NULL AND enabled IS TRUE';
if (null !== $limit) {
$sql .= " LIMIT {$limit}";
}
if (null !== $offset) {
$sql .= " OFFSET {$offset}";
}
return $this->entityManager->createNativeQuery($sql, $rsm)->setParameter(':key', $key)->getResult();
}
public function findByUsernameOrEmail(string $pattern)
{
$qb = $this->queryByUsernameOrEmail($pattern);
@@ -159,39 +192,6 @@ final class UserRepository implements ObjectRepository
return $qb->getQuery()->getResult();
}
/**
* Find users which does not have a key on attribute column
*
* @return array|User[]
*/
public function findByNotHavingAttribute(string $key, ?int $limit = null, ?int $offset = null): array
{
$rsm = new ResultSetMappingBuilder($this->entityManager);
$rsm->addRootEntityFromClassMetadata(User::class, 'u');
$sql = "SELECT ".$rsm->generateSelectClause()." FROM users u WHERE NOT attributes ?? :key OR attributes IS NULL AND enabled IS TRUE";
if (null !== $limit) {
$sql .= " LIMIT $limit";
}
if (null !== $offset) {
$sql .= " OFFSET $offset";
}
return $this->entityManager->createNativeQuery($sql, $rsm)->setParameter(':key', $key)->getResult();
}
public function countByNotHavingAttribute(string $key): int
{
$rsm = new ResultSetMapping();
$rsm->addScalarResult('count', 'count');
$sql = "SELECT count(*) FROM users u WHERE NOT attributes ?? :key OR attributes IS NULL AND enabled IS TRUE";
return $this->entityManager->createNativeQuery($sql, $rsm)->setParameter(':key', $key)->getSingleScalarResult();
}
public function getClassName()
{
return User::class;

View File

@@ -1,5 +1,12 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\Migrations\Main;
@@ -9,6 +16,11 @@ use Doctrine\Migrations\AbstractMigration;
final class Version20220506223243 extends AbstractMigration
{
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE users ALTER attributes DROP NOT NULL');
}
public function getDescription(): string
{
return 'Force user attribute to be an array';
@@ -20,9 +32,4 @@ final class Version20220506223243 extends AbstractMigration
$this->addSql('ALTER TABLE users ALTER attributes SET NOT NULL');
$this->addSql('ALTER TABLE users ALTER attributes SET DEFAULT \'{}\'::jsonb');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE users ALTER attributes DROP NOT NULL');
}
}