Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3b7eac3
chore(psalm): Migrate spaces to tabs
mejo- May 20, 2025
7f0f056
test(psalm): Bump error level to 4
mejo- May 26, 2025
deed7a9
fix(PageInfo): Allow null `fullWidth`
mejo- May 26, 2025
45d6559
fix(CollectiveStorage): Fix return type and add missing import
mejo- May 26, 2025
17b30e9
fix(ExpireManager): Remove dead logic
mejo- May 26, 2025
a526189
fix(ExpireManager): Do not expire labeled versions
mejo- May 26, 2025
de924e2
fix(ExpireManager): Add missing return types
mejo- May 26, 2025
5111991
fix(ExpireManager): Remove accidentally removed condition
mejo- May 26, 2025
e66c649
fix(VersionsBackend): Fix type for CollectiveVersion argument
mejo- May 26, 2025
eaed2db
fix(CollectiveShare): Adjust return types and remove dead code
mejo- May 26, 2025
c4cac94
fix(psalm): Update stubs for circles app
mejo- May 26, 2025
2bb4897
chore(psalm): Migrate spaces to tabs
mejo- May 26, 2025
1142ed6
fix(MountProvider): Remove nulls from returned array in getMountsForUser
mejo- May 26, 2025
d5582f8
fix: Don't call `getUID()` on null
mejo- May 26, 2025
a9d01d5
fix(PageController): always pass index to copy/move function
mejo- May 26, 2025
1a6d283
fix(CollectiveUserSettings): Fix return types
mejo- May 26, 2025
cfdcf7b
fix(DB): Replace deprecated `QueryBuilder->execute()` with `executeQu…
mejo- May 26, 2025
d8189c0
fix(FileIndexer): Make psalm happy by using a local variable for index
mejo- May 26, 2025
1703911
fix(DB): Fix return codes
mejo- May 26, 2025
b44d400
fix(Listeners): Handle empty userId
mejo- May 26, 2025
3826a17
fix(PageInfo): Always pass int to `setSize`
mejo- May 26, 2025
938c4d6
fix(Migration): Fix return type
mejo- May 26, 2025
737c39a
fix(CollectiveFolderManager): Several typing fixes
mejo- May 26, 2025
3d9bf05
fix(CollectiveFolderManager): Ignore inShare from cli
mejo- May 26, 2025
913b2d2
fix(CircleHelper): Make psalm ignore false positives
mejo- May 26, 2025
b27da7e
fix(TemplateService): Fix typing for parentId
mejo- May 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/Controller/CollectiveController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OCA\Collectives\Db\Collective;
use OCA\Collectives\Fs\NodeHelper;
use OCA\Collectives\Service\CollectiveService;
use OCA\Collectives\Service\NotFoundException;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\DataResponse;
Expand All @@ -38,8 +39,15 @@ public function __construct(
parent::__construct($AppName, $request);
}

/**
* @throws NotFoundException
*/
private function getUserId(): string {
return $this->userSession->getUser()->getUID();
$user = $this->userSession->getUser();
if ($user === null) {
throw new NotFoundException('Session user not found');
}
return $user->getUID();
}

private function getUserLang(): string {
Expand Down
10 changes: 9 additions & 1 deletion lib/Controller/CollectiveUserSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Closure;

use OCA\Collectives\Service\CollectiveUserSettingsService;
use OCA\Collectives\Service\NotFoundException;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\DataResponse;
Expand All @@ -32,8 +33,15 @@ public function __construct(
parent::__construct($AppName, $request);
}

/**
* @throws NotFoundException
*/
private function getUserId(): string {
return $this->userSession->getUser()->getUID();
$user = $this->userSession->getUser();
if ($user === null) {
throw new NotFoundException('Session user not found');
}
return $user->getUID();
}

private function prepareResponse(Closure $callback) : DataResponse {
Expand Down
12 changes: 11 additions & 1 deletion lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use OCA\Collectives\Service\AttachmentService;
use OCA\Collectives\Service\CollectiveService;
use OCA\Collectives\Service\NotFoundException;
use OCA\Collectives\Service\PageService;
use OCA\Collectives\Service\SearchService;
use OCP\AppFramework\Controller;
Expand All @@ -36,8 +37,15 @@ public function __construct(
parent::__construct($appName, $request);
}

/**
* @throws NotFoundException
*/
private function getUserId(): string {
return $this->userSession->getUser()->getUID();
$user = $this->userSession->getUser();
if ($user === null) {
throw new NotFoundException('Session user not found');
}
return $user->getUID();
}

#[NoAdminRequired]
Expand Down Expand Up @@ -103,6 +111,7 @@ public function contentSearch(int $collectiveId, string $searchString): DataResp

#[NoAdminRequired]
public function moveOrCopy(int $collectiveId, int $id, ?int $parentId = null, ?string $title = null, ?int $index = 0, bool $copy = false): DataResponse {
$index = $index ?? 0;
return $this->handleErrorResponse(function () use ($collectiveId, $id, $parentId, $title, $index, $copy): array {
$userId = $this->getUserId();
$pageInfo = $copy
Expand All @@ -116,6 +125,7 @@ public function moveOrCopy(int $collectiveId, int $id, ?int $parentId = null, ?s

#[NoAdminRequired]
public function moveOrCopyToCollective(int $collectiveId, int $id, int $newCollectiveId, ?int $parentId = null, ?int $index = 0, bool $copy = false): DataResponse {
$index = $index ?? 0;
return $this->handleErrorResponse(function () use ($collectiveId, $id, $newCollectiveId, $parentId, $index, $copy): array {
$userId = $this->getUserId();
if ($copy) {
Expand Down
10 changes: 9 additions & 1 deletion lib/Controller/PageTrashController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace OCA\Collectives\Controller;

use OCA\Collectives\Service\NotFoundException;
use OCA\Collectives\Service\PageService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
Expand All @@ -33,8 +34,15 @@ public function __construct(
$this->userSession = $userSession;
}

/**
* @throws NotFoundException
*/
private function getUserId(): string {
return $this->userSession->getUser()->getUID();
$user = $this->userSession->getUser();
if ($user === null) {
throw new NotFoundException('Session user not found');
}
return $user->getUID();
}

#[NoAdminRequired]
Expand Down
1 change: 1 addition & 0 deletions lib/Controller/PublicPageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public function touch(int $id): DataResponse {
#[PublicPage]
#[AnonRateLimit(limit: 10, period: 10)]
public function moveOrCopy(int $id, ?int $parentId, ?string $title = null, ?int $index = 0, bool $copy = false): DataResponse {
$index = $index ?? 0;
return $this->handleErrorResponse(function () use ($id, $parentId, $title, $index, $copy): array {
$this->checkEditPermissions();
$owner = $this->getCollectiveShare()->getOwner();
Expand Down
10 changes: 9 additions & 1 deletion lib/Controller/SessionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace OCA\Collectives\Controller;

use Closure;
use OCA\Collectives\Service\NotFoundException;
use OCA\Collectives\Service\SessionService;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\DataResponse;
Expand All @@ -31,8 +32,15 @@ public function __construct(
parent::__construct($appName, $request);
}

/**
* @throws NotFoundException
*/
private function getUserId(): string {
return $this->userSession->getUser()->getUID();
$user = $this->userSession->getUser();
if ($user === null) {
throw new NotFoundException('Session user not found');
}
return $user->getUID();
}

private function prepareResponse(Closure $callback) : DataResponse {
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function getUserSetting(string $key): DataResponse {
}

#[NoAdminRequired]
public function setUserSetting(string $key, ?string $value): DataResponse {
public function setUserSetting(string $key, string $value): DataResponse {
return $this->prepareResponse(function () use ($key, $value): ?string {
$this->validateSetUserSetting($key, $value);
$this->config->setUserValue($this->userId, 'collectives', $key, $value);
Expand Down
10 changes: 9 additions & 1 deletion lib/Controller/ShareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use OCA\Collectives\Service\CollectiveService;
use OCA\Collectives\Service\CollectiveShareService;
use OCA\Collectives\Service\NotFoundException;
use OCA\Collectives\Service\PageService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
Expand All @@ -36,8 +37,15 @@ public function __construct(
parent::__construct($AppName, $request);
}

/**
* @throws NotFoundException
*/
private function getUserId(): string {
return $this->userSession->getUser()->getUID();
$user = $this->userSession->getUser();
if ($user === null) {
throw new NotFoundException('Session user not found');
}
return $user->getUID();
}

private function prepareResponse(Closure $callback) : DataResponse {
Expand Down
10 changes: 9 additions & 1 deletion lib/Controller/TemplateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace OCA\Collectives\Controller;

use OCA\Collectives\Service\NotFoundException;
use OCA\Collectives\Service\TemplateService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
Expand All @@ -30,8 +31,15 @@ public function __construct(
parent::__construct($appName, $request);
}

/**
* @throws NotFoundException
*/
private function getUserId(): string {
return $this->userSession->getUser()->getUID();
$user = $this->userSession->getUser();
if ($user === null) {
throw new NotFoundException('Session user not found');
}
return $user->getUID();
}

#[NoAdminRequired]
Expand Down
10 changes: 9 additions & 1 deletion lib/Controller/TrashController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace OCA\Collectives\Controller;

use OCA\Collectives\Service\CollectiveService;
use OCA\Collectives\Service\NotFoundException;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\DataResponse;
Expand All @@ -30,8 +31,15 @@ public function __construct(
parent::__construct($AppName, $request);
}

/**
* @throws NotFoundException
*/
private function getUserId(): string {
return $this->userSession->getUser()->getUID();
$user = $this->userSession->getUser();
if ($user === null) {
throw new NotFoundException('Session user not found');
}
return $user->getUID();
}

#[NoAdminRequired]
Expand Down
8 changes: 4 additions & 4 deletions lib/Db/Collective.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ class Collective extends Entity implements JsonSerializable {
protected bool $userShowMembers = Collective::defaultShowMembers;
protected bool $userShowRecentPages = Collective::defaultShowRecentPages;
protected array $userFavoritePages = [];
protected ?bool $canLeave = null;
protected bool $canLeave = false;

public function getCircleId(): ?string {
public function getCircleId(): string {
return $this->getCircleUniqueId();
}

Expand Down Expand Up @@ -200,11 +200,11 @@ public function getUserFavoritePages(): array {
return $this->userFavoritePages;
}

public function getCanLeave(): ?bool {
public function getCanLeave(): bool {
return $this->canLeave;
}

public function setCanLeave(?bool $canLeave): void {
public function setCanLeave(bool $canLeave): void {
$this->canLeave = $canLeave;
}

Expand Down
7 changes: 3 additions & 4 deletions lib/Db/CollectiveMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@
use OCA\Collectives\Service\NotFoundException;
use OCA\Collectives\Service\NotPermittedException;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;

/**
* @method Collective insert(Entity $collective)
* @method Collective delete(Entity $collective)
* @method Collective insert(Collective $collective)
* @method Collective delete(Collective $collective)
* @method Collective findEntity(IQueryBuilder $query)
* @method Collective update(Entity $collective)
* @method Collective update(Collective $collective)
* @template-extends QBMapper<Collective>
*/
class CollectiveMapper extends QBMapper {
Expand Down
4 changes: 4 additions & 0 deletions lib/Db/CollectiveShareMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public function __construct(IDBConnection $db) {
parent::__construct($db, 'collectives_shares', CollectiveShare::class);
}

/**
* @return CollectiveShare[]
*/
public function findByCollectiveId(int $collectiveId): array {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
Expand All @@ -39,6 +42,7 @@ public function findByCollectiveId(int $collectiveId): array {
}

/**
* @return CollectiveShare[]
* @throws Exception
*/
public function findByCollectiveIdAndUser(int $collectiveId, string $userId): array {
Expand Down
4 changes: 2 additions & 2 deletions lib/Db/CollectiveUserSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CollectiveUserSettings extends Entity implements JsonSerializable {
protected ?int $collectiveId = null;
protected ?string $userId = null;
protected int $pageOrder = Collective::defaultPageOrder;
protected ?string $settings = '{}';
protected string $settings = '{}';

/**
* @throws NotPermittedException
Expand All @@ -52,7 +52,7 @@ private static function checkSetting(string $setting): void {
* @throws NotPermittedException
* @throws JsonException
*/
public function getSetting(string $setting) {
public function getSetting(string $setting): mixed {
self::checkSetting($setting);
return json_decode($this->settings, true, 512, JSON_THROW_ON_ERROR)[$setting] ?? null;
}
Expand Down
5 changes: 1 addition & 4 deletions lib/Db/CollectiveUserSettingsMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,9 @@ public function __construct(IDBConnection $db) {
* Provide our own implementation of `insertOrUpdate` as the one from QBMapper throws
* `REASON_NOT_NULL_CONSTRAINT_VIOLATION` for existing entities.
*
* TODO: Migrate to using `CollectiveUserSettings` in type hints once we drop PHP7.3.
*
* @return CollectiveUserSettings
* @throws Exception
*/
public function insertOrUpdate(Entity $entity): Entity {
public function insertOrUpdate(CollectiveUserSettings|Entity $entity): CollectiveUserSettings {
if ($entity->getId() === null) {
return $this->insert($entity);
}
Expand Down
11 changes: 5 additions & 6 deletions lib/Db/PageMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,21 @@
namespace OCA\Collectives\Db;

use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;

/**
* @method Page insert(Entity $page)
* @method Page update(Entity $page)
* @method Page delete(Entity $page)
* @method Page insert(Page $page)
* @method Page update(Page $page)
* @method Page delete(Page $page)
* @method Page findEntity(IQueryBuilder $query)
* @template-extends QBMapper<Page>
*/
class PageMapper extends QBMapper {
public function __construct(IDBConnection $db, ?string $entityClass = null) {
parent::__construct($db, 'collectives_pages', $entityClass);
public function __construct(IDBConnection $db) {
parent::__construct($db, 'collectives_pages', Page::class);
}

public function updateOrInsert(Page $page): Page {
Expand Down
8 changes: 5 additions & 3 deletions lib/Listeners/BeforeTemplateRenderedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use OCA\Collectives\AppInfo\Application;
use OCA\Collectives\Fs\UserFolderHelper;
use OCA\Collectives\Service\NotFoundException;
use OCA\Collectives\Service\NotPermittedException;
use OCA\Text\Event\LoadEditor;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
Expand Down Expand Up @@ -44,9 +45,10 @@ public function handle(Event $event): void {
Util::addStyle('collectives', 'collectives');

// Get Collectives user folder for users
$userId = $this->userSession->getUser()
? $this->userSession->getUser()->getUID()
: null;
$userId = $this->userSession->getUser()?->getUID();
if ($userId === null) {
throw new NotFoundException('Session user not found');
}
$userFolder = $this->userFolderHelper->getUserFolderSetting($userId);
}

Expand Down
4 changes: 4 additions & 0 deletions lib/Listeners/TextMentionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public function handle(Event $event): void {
return;
}

if (!$this->userId) {
return;
}

$collective = $this->collectiveService->getCollective($mountPoint->getFolderId(), $this->userId);
$pageInfo = $this->pageService->findByFile($mountPoint->getFolderId(), $event->getFile(), $this->userId);

Expand Down
1 change: 1 addition & 0 deletions lib/Migration/MigrateTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ private function getFolderTemplateFiles(Folder $folder, bool $recursive = false)
*/
private function getTemplateFolder(Folder $collectiveFolder): Folder {
try {
/** @var Folder $templateFolder */
$templateFolder = $collectiveFolder->get(self::TEMPLATE_FOLDER);
} catch (FilesNotFoundException) {
// Create missing template folder
Expand Down
Loading
Loading