Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
use OCP\Share\IManager;
use OCP\Share\IProviderFactory;
use OCP\Share\IShare;
use OCP\Snowflake\IGenerator;
use OCP\Util;
use Override;
use Psr\Log\LoggerInterface;
Expand All @@ -70,7 +69,6 @@ public function __construct(
private readonly IFilenameValidator $filenameValidator,
private readonly IProviderFactory $shareProviderFactory,
private readonly SetupManager $setupManager,
private readonly IGenerator $snowflakeGenerator,
private readonly ExternalShareMapper $externalShareMapper,
) {
}
Expand Down Expand Up @@ -145,7 +143,7 @@ public function shareReceived(ICloudFederationShare $share): string {
}

$externalShare = new ExternalShare();
$externalShare->setId($this->snowflakeGenerator->nextId());
$externalShare->setId();
$externalShare->setRemote($remote);
$externalShare->setRemoteId($remoteId);
$externalShare->setShareToken($token);
Expand Down Expand Up @@ -177,9 +175,9 @@ public function shareReceived(ICloudFederationShare $share): string {
->setType('remote_share')
->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/'), $ownerDisplayName])
->setAffectedUser($shareWith)
->setObject('remote_share', $externalShare->getId(), $name);
->setObject('remote_share', (string)$externalShare->getId(), $name);
Server::get(IActivityManager::class)->publish($event);
$this->notifyAboutNewShare($shareWith, $externalShare->getId(), $ownerFederatedId, $sharedByFederatedId, $name, $ownerDisplayName);
$this->notifyAboutNewShare($shareWith, (string)$externalShare->getId(), $ownerFederatedId, $sharedByFederatedId, $name, $ownerDisplayName);

// If auto-accept is enabled, accept the share
if ($this->federatedShareProvider->isFederatedTrustedShareAutoAccept() && $trustedServers?->isTrustedServer($remote) === true) {
Expand All @@ -193,9 +191,9 @@ public function shareReceived(ICloudFederationShare $share): string {
->setType('remote_share')
->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/'), $ownerDisplayName])
->setAffectedUser($user->getUID())
->setObject('remote_share', $externalShare->getId(), $name);
->setObject('remote_share', (string)$externalShare->getId(), $name);
Server::get(IActivityManager::class)->publish($event);
$this->notifyAboutNewShare($user->getUID(), $externalShare->getId(), $ownerFederatedId, $sharedByFederatedId, $name, $ownerDisplayName);
$this->notifyAboutNewShare($user->getUID(), (string)$externalShare->getId(), $ownerFederatedId, $sharedByFederatedId, $name, $ownerDisplayName);

// If auto-accept is enabled, accept the share
if ($this->federatedShareProvider->isFederatedTrustedShareAutoAccept() && $trustedServers?->isTrustedServer($remote) === true) {
Expand All @@ -204,7 +202,7 @@ public function shareReceived(ICloudFederationShare $share): string {
}
}

return $externalShare->getId();
return (string)$externalShare->getId();
} catch (\Exception $e) {
$this->logger->error('Server can not add remote share.', [
'app' => 'files_sharing',
Expand Down Expand Up @@ -466,7 +464,7 @@ private function unshare(string $id, array $notification): array {
$notification = $this->notificationManager->createNotification();
$notification->setApp('files_sharing')
->setUser($share->getUser())
->setObject('remote_share', $share->getId());
->setObject('remote_share', (string)$share->getId());
$this->notificationManager->markProcessed($notification);

$event = $this->activityManager->generateEvent();
Expand Down
15 changes: 3 additions & 12 deletions apps/files_sharing/lib/External/ExternalShare.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@

use OC\Files\Filesystem;
use OCA\Files_Sharing\ResponseDefinitions;
use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\SnowflakeAwareEntity;
use OCP\DB\Types;
use OCP\IGroup;
use OCP\IUser;
use OCP\Share\IShare;

/**
* @method string getId()
* @method void setId(string $id)
* @method string getParent()
* @method void setParent(string $parent)
* @method int|null getShareType()
Expand All @@ -46,7 +44,7 @@
*
* @psalm-import-type Files_SharingRemoteShare from ResponseDefinitions
*/
class ExternalShare extends Entity implements \JsonSerializable {
class ExternalShare extends SnowflakeAwareEntity implements \JsonSerializable {
protected string $parent = '-1';
protected ?int $shareType = null;
protected ?string $remote = null;
Expand Down Expand Up @@ -96,7 +94,7 @@ public function setShareWith(IUser|IGroup $shareWith): void {
public function jsonSerialize(): array {
$parent = $this->getParent();
return [
'id' => $this->getId(),
'id' => (string)$this->getId(),
'parent' => $parent,
'share_type' => $this->getShareType() ?? IShare::TYPE_USER, // unfortunately nullable on the DB level, but never null.
'remote' => $this->getRemote(),
Expand All @@ -107,13 +105,6 @@ public function jsonSerialize(): array {
'user' => $this->getUser(),
'mountpoint' => $this->getMountpoint(),
'accepted' => $this->getAccepted(),

// Added later on
'file_id' => null,
'mimetype' => null,
'permissions' => null,
'mtime' => null,
'type' => null,
];
}

Expand Down
8 changes: 3 additions & 5 deletions apps/files_sharing/lib/External/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
use OCP\Notification\IManager;
use OCP\OCS\IDiscoveryService;
use OCP\Share\IShare;
use OCP\Snowflake\IGenerator;
use Psr\Log\LoggerInterface;

class Manager {
Expand All @@ -57,7 +56,6 @@ public function __construct(
private SetupManager $setupManager,
private ICertificateManager $certificateManager,
private ExternalShareMapper $externalShareMapper,
private IGenerator $snowflakeGenerator,
) {
$this->user = $userSession->getUser();
}
Expand Down Expand Up @@ -186,7 +184,7 @@ private function updateSubShare(ExternalShare $externalShare, IUser $user, ?stri
$subShare = $this->externalShareMapper->getUserShare($externalShare, $user);
} catch (DoesNotExistException) {
$subShare = new ExternalShare();
$subShare->setId($this->snowflakeGenerator->nextId());
$subShare->setId();
$subShare->setRemote($externalShare->getRemote());
$subShare->setPassword($externalShare->getPassword());
$subShare->setName($externalShare->getName());
Expand All @@ -195,7 +193,7 @@ private function updateSubShare(ExternalShare $externalShare, IUser $user, ?stri
$subShare->setMountpoint($mountPoint ?? $externalShare->getMountpoint());
$subShare->setAccepted($accepted);
$subShare->setRemoteId($externalShare->getRemoteId());
$subShare->setParent($externalShare->getId());
$subShare->setParent((string)$externalShare->getId());
$subShare->setShareType($externalShare->getShareType());
$subShare->setShareToken($externalShare->getShareToken());
$this->externalShareMapper->insert($subShare);
Expand Down Expand Up @@ -317,7 +315,7 @@ public function processNotification(ExternalShare $remoteShare, ?IUser $user = n
$filter = $this->notificationManager->createNotification();
$filter->setApp('files_sharing')
->setUser($user->getUID())
->setObject('remote_share', $remoteShare->getId());
->setObject('remote_share', (string)$remoteShare->getId());
$this->notificationManager->markProcessed($filter);
}

Expand Down
10 changes: 5 additions & 5 deletions apps/files_sharing/lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,21 @@
*
* @psalm-type Files_SharingRemoteShare = array{
* accepted: int,
* file_id: int|null,
* id: string,
* mimetype: string|null,
* mountpoint: string,
* mtime: int|null,
* name: string,
* owner: string,
* parent: string|null,
* permissions: int|null,
* remote: string,
* remote_id: string,
* share_token: string,
* share_type: int,
* type: string|null,
* user: string,
* file_id?: int,
* mimetype?: string,
* permissions?: int,
* mtime?: int,
* type?: string,
* }
*
* @psalm-type Files_SharingSharee = array{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use OCP\Federation\ICloudIdManager;
use OCP\IDBConnection;
use OCP\Server;
use OCP\Snowflake\IGenerator;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -64,7 +63,7 @@ protected function setUp(): void {

if (isset($storage['share_token'])) {
$externalShare = new ExternalShare();
$externalShare->setId(Server::get(IGenerator::class)->nextId());
$externalShare->setId();
$externalShare->setShareToken($storage['share_token']);
$externalShare->setRemote($storage['remote']);
$externalShare->setName('irrelevant');
Expand Down
18 changes: 8 additions & 10 deletions apps/files_sharing/tests/External/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
use OCP\OCS\IDiscoveryService;
use OCP\Server;
use OCP\Share\IShare;
use OCP\Snowflake\IGenerator;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\Traits\UserTrait;
Expand Down Expand Up @@ -170,7 +169,6 @@ private function createManagerForUser(IUser $user): Manager&MockObject {
$this->setupManager,
$this->certificateManager,
$this->externalShareMapper,
Server::get(IGenerator::class),
]
)->onlyMethods(['tryOCMEndPoint'])->getMock();
}
Expand All @@ -190,7 +188,7 @@ private function clearMounts(): void {

public function testAddUserShare(): void {
$userShare = new ExternalShare();
$userShare->setId(Server::get(IGenerator::class)->nextId());
$userShare->setId();
$userShare->setRemote('http://localhost');
$userShare->setShareToken('token1');
$userShare->setPassword('');
Expand All @@ -205,7 +203,7 @@ public function testAddUserShare(): void {

public function testAddGroupShare(): void {
$groupShare = new ExternalShare();
$groupShare->setId(Server::get(IGenerator::class)->nextId());
$groupShare->setId();
$groupShare->setRemote('http://localhost');
$groupShare->setOwner('foobar');
$groupShare->setShareType(IShare::TYPE_GROUP);
Expand Down Expand Up @@ -237,10 +235,10 @@ public function doTestAddShare(ExternalShare $shareData1, IUser|IGroup $userOrGr

$shareData2 = $shareData1->clone();
$shareData2->setShareToken('token2');
$shareData2->setId(\OCP\Server::get(IGenerator::class)->nextId());
$shareData2->setId();
$shareData3 = $shareData1->clone();
$shareData3->setShareToken('token3');
$shareData3->setId(\OCP\Server::get(IGenerator::class)->nextId());
$shareData3->setId();

$this->setupMounts();
$this->assertNotMount('SharedFolder');
Expand Down Expand Up @@ -440,7 +438,7 @@ private function createTestUserShare(string $userId = 'user1'): ExternalShare {
$user = $this->createMock(IUser::class);
$user->expects($this->any())->method('getUID')->willReturn($userId);
$share = new ExternalShare();
$share->setId(Server::get(IGenerator::class)->nextId());
$share->setId();
$share->setRemote('http://localhost');
$share->setShareToken('token1');
$share->setPassword('');
Expand All @@ -460,7 +458,7 @@ private function createTestUserShare(string $userId = 'user1'): ExternalShare {
*/
private function createTestGroupShare(string $groupId = 'group1'): array {
$share = new ExternalShare();
$share->setId(Server::get(IGenerator::class)->nextId());
$share->setId();
$share->setRemote('http://localhost');
$share->setShareToken('token1');
$share->setPassword('');
Expand Down Expand Up @@ -646,7 +644,7 @@ public function testDeleteUserShares(): void {
// user 2 shares
$manager2 = $this->createManagerForUser($user2);
$share = new ExternalShare();
$share->setId(Server::get(IGenerator::class)->nextId());
$share->setId();
$share->setRemote('http://localhost');
$share->setShareToken('token1');
$share->setPassword('');
Expand Down Expand Up @@ -696,7 +694,7 @@ public function testDeleteGroupShares(): void {
$manager2 = $this->createManagerForUser($user);

$share = new ExternalShare();
$share->setId(Server::get(IGenerator::class)->nextId());
$share->setId();
$share->setRemote('http://localhost');
$share->setShareToken('token1');
$share->setPassword('');
Expand Down
2 changes: 1 addition & 1 deletion apps/files_versions/lib/Db/VersionEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct() {

public function jsonSerialize(): array {
return [
'id' => $this->id,
'id' => $this->getId(),
'file_id' => $this->fileId,
'timestamp' => $this->timestamp,
'size' => $this->size,
Expand Down
5 changes: 2 additions & 3 deletions core/BackgroundJobs/MovePreviewJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\Snowflake\IGenerator;
use Override;
use Psr\Log\LoggerInterface;

Expand All @@ -45,7 +44,6 @@ public function __construct(
private readonly IMimeTypeDetector $mimeTypeDetector,
private readonly IMimeTypeLoader $mimeTypeLoader,
private readonly LoggerInterface $logger,
private readonly IGenerator $generator,
IAppDataFactory $appDataFactory,
) {
parent::__construct($time);
Expand Down Expand Up @@ -138,7 +136,7 @@ private function processPreviews(int $fileId, bool $flatPath): void {
$path = $fileId . '/' . $previewFile->getName();
/** @var SimpleFile $previewFile */
$preview = Preview::fromPath($path, $this->mimeTypeDetector);
$preview->setId($this->generator->nextId());
$preview->setId();
if (!$preview) {
$this->logger->error('Unable to import old preview at path.');
continue;
Expand Down Expand Up @@ -172,6 +170,7 @@ private function processPreviews(int $fileId, bool $flatPath): void {
$preview->setStorageId($result[0]['storage']);
$preview->setEtag($result[0]['etag']);
$preview->setSourceMimeType($this->mimeTypeLoader->getMimetypeById((int)$result[0]['mimetype']));
$preview->setId();
try {
$preview = $this->previewMapper->insert($preview);
} catch (Exception) {
Expand Down
18 changes: 9 additions & 9 deletions core/Command/SnowflakeDecodeId.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
*/
namespace OC\Core\Command;

use OCP\Snowflake\IDecoder;
use OCP\Snowflake\ISnowflakeDecoder;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class SnowflakeDecodeId extends Base {
public function __construct(
private readonly IDecoder $decoder,
private readonly ISnowflakeDecoder $decoder,
) {
parent::__construct();
}
Expand All @@ -36,13 +36,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$rows = [
['Snowflake ID', $snowflakeId],
['Seconds', $data['seconds']],
['Milliseconds', $data['milliseconds']],
['Created from CLI', $data['isCli'] ? 'yes' : 'no'],
['Server ID', $data['serverId']],
['Sequence ID', $data['sequenceId']],
['Creation timestamp', $data['createdAt']->format('U.v')],
['Creation date', $data['createdAt']->format('Y-m-d H:i:s.v')],
['Seconds', $data->getSeconds()],
['Milliseconds', $data->getMilliseconds()],
['Created from CLI', $data->isCli() ? 'yes' : 'no'],
['Server ID', $data->getServerId()],
['Sequence ID', $data->getSequenceId()],
['Creation timestamp', $data->getCreatedAt()->format('U.v')],
['Creation date', $data->getCreatedAt()->format('Y-m-d H:i:s.v')],
];

$table = new Table($output);
Expand Down
10 changes: 6 additions & 4 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
'OCP\\AppFramework\\Db\\IMapperException' => $baseDir . '/lib/public/AppFramework/Db/IMapperException.php',
'OCP\\AppFramework\\Db\\MultipleObjectsReturnedException' => $baseDir . '/lib/public/AppFramework/Db/MultipleObjectsReturnedException.php',
'OCP\\AppFramework\\Db\\QBMapper' => $baseDir . '/lib/public/AppFramework/Db/QBMapper.php',
'OCP\\AppFramework\\Db\\SnowflakeAwareEntity' => $baseDir . '/lib/public/AppFramework/Db/SnowflakeAwareEntity.php',
'OCP\\AppFramework\\Db\\TTransactional' => $baseDir . '/lib/public/AppFramework/Db/TTransactional.php',
'OCP\\AppFramework\\Http' => $baseDir . '/lib/public/AppFramework/Http.php',
'OCP\\AppFramework\\Http\\Attribute\\ARateLimit' => $baseDir . '/lib/public/AppFramework/Http/Attribute/ARateLimit.php',
Expand Down Expand Up @@ -830,8 +831,9 @@
'OCP\\Share_Backend' => $baseDir . '/lib/public/Share_Backend.php',
'OCP\\Share_Backend_Collection' => $baseDir . '/lib/public/Share_Backend_Collection.php',
'OCP\\Share_Backend_File_Dependent' => $baseDir . '/lib/public/Share_Backend_File_Dependent.php',
'OCP\\Snowflake\\IDecoder' => $baseDir . '/lib/public/Snowflake/IDecoder.php',
'OCP\\Snowflake\\IGenerator' => $baseDir . '/lib/public/Snowflake/IGenerator.php',
'OCP\\Snowflake\\ISnowflakeDecoder' => $baseDir . '/lib/public/Snowflake/ISnowflakeDecoder.php',
'OCP\\Snowflake\\ISnowflakeGenerator' => $baseDir . '/lib/public/Snowflake/ISnowflakeGenerator.php',
'OCP\\Snowflake\\Snowflake' => $baseDir . '/lib/public/Snowflake/Snowflake.php',
'OCP\\SpeechToText\\Events\\AbstractTranscriptionEvent' => $baseDir . '/lib/public/SpeechToText/Events/AbstractTranscriptionEvent.php',
'OCP\\SpeechToText\\Events\\TranscriptionFailedEvent' => $baseDir . '/lib/public/SpeechToText/Events/TranscriptionFailedEvent.php',
'OCP\\SpeechToText\\Events\\TranscriptionSuccessfulEvent' => $baseDir . '/lib/public/SpeechToText/Events/TranscriptionSuccessfulEvent.php',
Expand Down Expand Up @@ -2125,10 +2127,10 @@
'OC\\Share\\Helper' => $baseDir . '/lib/private/Share/Helper.php',
'OC\\Share\\Share' => $baseDir . '/lib/private/Share/Share.php',
'OC\\Snowflake\\APCuSequence' => $baseDir . '/lib/private/Snowflake/APCuSequence.php',
'OC\\Snowflake\\Decoder' => $baseDir . '/lib/private/Snowflake/Decoder.php',
'OC\\Snowflake\\FileSequence' => $baseDir . '/lib/private/Snowflake/FileSequence.php',
'OC\\Snowflake\\Generator' => $baseDir . '/lib/private/Snowflake/Generator.php',
'OC\\Snowflake\\ISequence' => $baseDir . '/lib/private/Snowflake/ISequence.php',
'OC\\Snowflake\\SnowflakeDecoder' => $baseDir . '/lib/private/Snowflake/SnowflakeDecoder.php',
'OC\\Snowflake\\SnowflakeGenerator' => $baseDir . '/lib/private/Snowflake/SnowflakeGenerator.php',
'OC\\SpeechToText\\SpeechToTextManager' => $baseDir . '/lib/private/SpeechToText/SpeechToTextManager.php',
'OC\\SpeechToText\\TranscriptionJob' => $baseDir . '/lib/private/SpeechToText/TranscriptionJob.php',
'OC\\StreamImage' => $baseDir . '/lib/private/StreamImage.php',
Expand Down
Loading
Loading