Skip to content
Merged
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
3 changes: 2 additions & 1 deletion apps/dav/lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(
}

/**
* @return array{dav: array{chunking: string, public_shares_chunking: bool, search_supports_creation_time: bool, search_supports_upload_time: bool, bulkupload?: string, absence-supported?: bool, absence-replacement?: bool}}
* @return array{dav: array{chunking: string, public_shares_chunking: bool, search_supports_creation_time: bool, search_supports_upload_time: bool, search_supports_last_activity: bool, bulkupload?: string, absence-supported?: bool, absence-replacement?: bool}}
*/
public function getCapabilities() {
$capabilities = [
Expand All @@ -27,6 +27,7 @@ public function getCapabilities() {
'public_shares_chunking' => true,
'search_supports_creation_time' => true,
'search_supports_upload_time' => true,
'search_supports_last_activity' => true,
]
];
if ($this->config->getSystemValueBool('bulkupload.enabled', true)) {
Expand Down
5 changes: 5 additions & 0 deletions apps/dav/lib/Connector/Sabre/FilesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class FilesPlugin extends ServerPlugin {
public const METADATA_ETAG_PROPERTYNAME = '{http://nextcloud.org/ns}metadata_etag';
public const UPLOAD_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}upload_time';
public const CREATION_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}creation_time';
public const LAST_ACTIVITY_PROPERTYNAME = '{http://nextcloud.org/ns}last_activity';
public const SHARE_NOTE = '{http://nextcloud.org/ns}note';
public const SHARE_HIDE_DOWNLOAD_PROPERTYNAME = '{http://nextcloud.org/ns}hide-download';
public const SUBFOLDER_COUNT_PROPERTYNAME = '{http://nextcloud.org/ns}contained-folder-count';
Expand Down Expand Up @@ -444,6 +445,10 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node)
return $node->getFileInfo()->getCreationTime();
});

$propFind->handle(self::LAST_ACTIVITY_PROPERTYNAME, function () use ($node) {
return $node->getFileInfo()->getLastActivity();
});

foreach ($node->getFileInfo()->getMetadata() as $metadataKey => $metadataValue) {
$propFind->handle(self::FILE_METADATA_PREFIX . $metadataKey, $metadataValue);
}
Expand Down
5 changes: 5 additions & 0 deletions apps/dav/lib/Files/FileSearchBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public function getPropertyDefinitionsForScope(string $href, ?string $path): arr
new SearchPropertyDefinition('{DAV:}getlastmodified', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME),
new SearchPropertyDefinition('{DAV:}creationdate', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME),
new SearchPropertyDefinition('{http://nextcloud.org/ns}upload_time', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME),
new SearchPropertyDefinition('{http://nextcloud.org/ns}last_activity', true, false, true, SearchPropertyDefinition::DATATYPE_DATETIME),
new SearchPropertyDefinition(FilesPlugin::SIZE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
new SearchPropertyDefinition(TagsPlugin::FAVORITE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_BOOLEAN),
new SearchPropertyDefinition(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, true, true, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
Expand Down Expand Up @@ -304,6 +305,8 @@ private function getSearchResultProperty(SearchResult $result, SearchPropertyDef
return $node->getNode()->getCreationTime();
case '{http://nextcloud.org/ns}upload_time':
return $node->getNode()->getUploadTime();
case '{http://nextcloud.org/ns}last_activity':
return $node->getNode()->getLastActivity();
case FilesPlugin::SIZE_PROPERTYNAME:
return $node->getSize();
case FilesPlugin::INTERNAL_FILEID_PROPERTYNAME:
Expand Down Expand Up @@ -332,6 +335,8 @@ private function transformQuery(Query $query, ?SearchBinaryOperator $scopeOperat
$direction = $order->order === Order::ASC ? ISearchOrder::DIRECTION_ASCENDING : ISearchOrder::DIRECTION_DESCENDING;
if (str_starts_with($order->property->name, FilesPlugin::FILE_METADATA_PREFIX)) {
return new SearchOrder($direction, substr($order->property->name, strlen(FilesPlugin::FILE_METADATA_PREFIX)), IMetadataQuery::EXTRA);
} elseif ($order->property->name === FilesPlugin::LAST_ACTIVITY_PROPERTYNAME) {
return new SearchOrder($direction, 'last_activity');
} else {
return new SearchOrder($direction, $this->mapPropertyNameToColumn($order->property));
}
Expand Down
6 changes: 5 additions & 1 deletion apps/dav/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"chunking",
"public_shares_chunking",
"search_supports_creation_time",
"search_supports_upload_time"
"search_supports_upload_time",
"search_supports_last_activity"
],
"properties": {
"chunking": {
Expand All @@ -47,6 +48,9 @@
"search_supports_upload_time": {
"type": "boolean"
},
"search_supports_last_activity": {
"type": "boolean"
},
"bulkupload": {
"type": "string"
},
Expand Down
3 changes: 3 additions & 0 deletions apps/dav/tests/unit/CapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function testGetCapabilities(): void {
'public_shares_chunking' => true,
'search_supports_creation_time' => true,
'search_supports_upload_time' => true,
'search_supports_last_activity' => true,
],
];
$this->assertSame($expected, $capabilities->getCapabilities());
Expand All @@ -55,6 +56,7 @@ public function testGetCapabilitiesWithBulkUpload(): void {
'public_shares_chunking' => true,
'search_supports_creation_time' => true,
'search_supports_upload_time' => true,
'search_supports_last_activity' => true,
'bulkupload' => '1.0',
],
];
Expand All @@ -78,6 +80,7 @@ public function testGetCapabilitiesWithAbsence(): void {
'public_shares_chunking' => true,
'search_supports_creation_time' => true,
'search_supports_upload_time' => true,
'search_supports_last_activity' => true,
'absence-supported' => true,
'absence-replacement' => true,
],
Expand Down
8 changes: 8 additions & 0 deletions apps/files/lib/ConfigLexicon.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
class ConfigLexicon implements ILexicon {
public const OVERWRITES_HOME_FOLDERS = 'overwrites_home_folders';
public const RECENT_LIMIT = 'recent_limit';

public function getStrictness(): Strictness {
return Strictness::IGNORE;
Expand All @@ -37,6 +38,13 @@ public function getAppConfigs(): array {
lazy: false,
note: 'It will be populated with app IDs of mount providers that overwrite home folders. Currently, only files_external and groupfolders.',
),
new Entry(
self::RECENT_LIMIT,
ValueType::INT,
defaultRaw: 100,
definition: 'Maximum number of files to display on recent files view',
lazy: false,
),
];
}

Expand Down
4 changes: 4 additions & 0 deletions apps/files/lib/Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use OC\Files\FilenameValidator;
use OC\Files\Filesystem;
use OCA\Files\AppInfo\Application;
use OCA\Files\ConfigLexicon;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\Files\Event\LoadSearchPlugins;
use OCA\Files\Event\LoadSidebar;
Expand All @@ -25,6 +26,7 @@
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Services\IInitialState;
use OCP\Authentication\TwoFactorAuth\IRegistry;
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent as ResourcesLoadAdditionalScriptsEvent;
Expand Down Expand Up @@ -62,6 +64,7 @@ public function __construct(
private ViewConfig $viewConfig,
private FilenameValidator $filenameValidator,
private IRegistry $twoFactorRegistry,
private IAppConfig $appConfig,
) {
parent::__construct($appName, $request);
}
Expand Down Expand Up @@ -174,6 +177,7 @@ public function index($dir = '', $view = '', $fileid = null) {
$this->initialState->provideInitialState('storageStats', $storageInfo);
$this->initialState->provideInitialState('config', $this->userConfig->getConfigs());
$this->initialState->provideInitialState('viewConfigs', $this->viewConfig->getConfigs());
$this->initialState->provideInitialState('recent_limit', $this->appConfig->getAppValueInt(ConfigLexicon::RECENT_LIMIT, 100));

// File sorting user config
$filesSortingConfig = json_decode($this->config->getUserValue($userId, 'files', 'files_sorting_configs', '{}'), true);
Expand Down
4 changes: 3 additions & 1 deletion apps/files/src/services/Recent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import type { FileStat, ResponseDataDetailed, SearchResult } from 'webdav'

import { getCurrentUser } from '@nextcloud/auth'
import { Folder, Permission, davGetRecentSearch, davRootPath, davRemoteURL, davResultToNode } from '@nextcloud/files'
import { loadState } from '@nextcloud/initial-state'
import { CancelablePromise } from 'cancelable-promise'
import { useUserConfigStore } from '../store/userconfig.ts'
import { getPinia } from '../store/index.ts'
import { client } from './WebdavClient.ts'
import { getBaseUrl } from '@nextcloud/router'

const lastTwoWeeksTimestamp = Math.round((Date.now() / 1000) - (60 * 60 * 24 * 14))
const recentLimit = loadState<number>('files', 'recent_limit', 100)

/**
* Helper to map a WebDAV result to a Nextcloud node
Expand Down Expand Up @@ -48,7 +50,7 @@ export const getContents = (path = '/'): CancelablePromise<ContentsWithRoot> =>
const contentsResponse = await client.search('/', {
signal: controller.signal,
details: true,
data: davGetRecentSearch(lastTwoWeeksTimestamp),
data: davGetRecentSearch(lastTwoWeeksTimestamp, recentLimit),
}) as ResponseDataDetailed<SearchResult>

const contents = contentsResponse.data.results
Expand Down
8 changes: 6 additions & 2 deletions apps/files/tests/Controller/ViewControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Services\IInitialState;
use OCP\Authentication\TwoFactorAuth\IRegistry;
use OCP\Diagnostics\IEventLogger;
Expand Down Expand Up @@ -48,6 +49,7 @@
class ViewControllerTest extends TestCase {
private ContainerInterface&MockObject $container;
private IAppManager&MockObject $appManager;
private IAppConfig&MockObject $appConfig;
private ICacheFactory&MockObject $cacheFactory;
private IConfig&MockObject $config;
private IEventDispatcher $eventDispatcher;
Expand All @@ -71,6 +73,7 @@ class ViewControllerTest extends TestCase {
protected function setUp(): void {
parent::setUp();
$this->appManager = $this->createMock(IAppManager::class);
$this->appConfig = $this->createMock(IAppConfig::class);
$this->config = $this->createMock(IConfig::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->initialState = $this->createMock(IInitialState::class);
Expand Down Expand Up @@ -142,6 +145,7 @@ protected function setUp(): void {
$this->viewConfig,
$filenameValidator,
$this->twoFactorRegistry,
$this->appConfig,
])
->onlyMethods([
'getStorageInfo',
Expand Down Expand Up @@ -298,11 +302,11 @@ public function testTwoFactorAuthEnabled(): void {
'backup_codes' => true,
]);

$invokedCountProvideInitialState = $this->exactly(9);
$invokedCountProvideInitialState = $this->exactly(10);
$this->initialState->expects($invokedCountProvideInitialState)
->method('provideInitialState')
->willReturnCallback(function ($key, $data) use ($invokedCountProvideInitialState): void {
if ($invokedCountProvideInitialState->numberOfInvocations() === 9) {
if ($invokedCountProvideInitialState->numberOfInvocations() === 10) {
$this->assertEquals('isTwoFactorEnabled', $key);
$this->assertTrue($data);
}
Expand Down
4 changes: 4 additions & 0 deletions apps/files_trashbin/lib/Trash/TrashItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ public function getUploadTime(): int {
return $this->fileInfo->getUploadTime();
}

public function getLastActivity(): int {
return $this->fileInfo->getLastActivity();
}

public function getParentId(): int {
return $this->fileInfo->getParentId();
}
Expand Down
4 changes: 2 additions & 2 deletions dist/files-init.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-init.js.map

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion lib/private/Files/Cache/QuerySearchHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ public function searchInCaches(ISearchQuery $searchQuery, array $caches): array

$requestedFields = $this->searchBuilder->extractRequestedFields($searchQuery->getSearchOperation());

$joinExtendedCache = in_array('creation_time', $requestedFields) || in_array('upload_time', $requestedFields);
$orderFields = array_map(fn ($order) => $order->getField(), $searchQuery->getOrder());

$joinExtendedCache = in_array('creation_time', $requestedFields)
|| in_array('upload_time', $requestedFields)
|| in_array('last_activity', $orderFields);

$query = $builder->selectFileCache('file', $joinExtendedCache);

Expand Down
4 changes: 4 additions & 0 deletions lib/private/Files/Cache/SearchBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@ public function addSearchOrdersToQuery(IQueryBuilder $query, array $orders, ?IMe
if ($field === 'mtime') {
$field = $query->func()->add($field, $query->createNamedParameter(0));
}

if ($field === 'last_activity') {
$field = $query->func()->greatest('file.mtime', $query->createFunction('COALESCE(fe.upload_time, 0)'));
}
}
$query->addOrderBy($field, $order->getDirection());
}
Expand Down
4 changes: 4 additions & 0 deletions lib/private/Files/FileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ public function getUploadTime(): int {
return (int)$this->data['upload_time'];
}

public function getLastActivity(): int {
return max($this->getUploadTime(), $this->getMTime());
}

public function getParentId(): int {
return $this->data['parent'] ?? -1;
}
Expand Down
7 changes: 7 additions & 0 deletions lib/private/Files/Node/LazyFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,13 @@ public function getUploadTime(): int {
return $this->__call(__FUNCTION__, func_get_args());
}

/**
* @inheritDoc
*/
public function getLastActivity(): int {
return $this->__call(__FUNCTION__, func_get_args());
}

public function getRelativePath($path) {
return PathHelper::getRelativePath($this->getPath(), $path);
}
Expand Down
4 changes: 4 additions & 0 deletions lib/private/Files/Node/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,10 @@ public function getUploadTime(): int {
return $this->getFileInfo()->getUploadTime();
}

public function getLastActivity(): int {
return $this->getFileInfo()->getLastActivity();
}

public function getParentId(): int {
return $this->fileInfo->getParentId();
}
Expand Down
2 changes: 2 additions & 0 deletions lib/private/Files/Search/SearchOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ private function sortFileInfoNoDirection(FileInfo $a, FileInfo $b): int {
return $a->getId() <=> $b->getId();
case 'permissions':
return $a->getPermissions() <=> $b->getPermissions();
case 'last_activity':
return $a->getLastActivity() <=> $b->getLastActivity();
default:
return 0;
}
Expand Down
10 changes: 10 additions & 0 deletions lib/public/Files/FileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,16 @@ public function getCreationTime(): int;
*/
public function getUploadTime(): int;

/**
* Get the last activity date as unix timestamp
*
* Last activity is the more recent of the upload time and the modification time
*
* @return int
* @since 32.0.7
*/
public function getLastActivity(): int;

/**
* Get the fileid or the parent folder
* or -1 if this item has no parent folder (because it is the root)
Expand Down
6 changes: 5 additions & 1 deletion openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,8 @@
"chunking",
"public_shares_chunking",
"search_supports_creation_time",
"search_supports_upload_time"
"search_supports_upload_time",
"search_supports_last_activity"
],
"properties": {
"chunking": {
Expand All @@ -1501,6 +1502,9 @@
"search_supports_upload_time": {
"type": "boolean"
},
"search_supports_last_activity": {
"type": "boolean"
},
"bulkupload": {
"type": "string"
},
Expand Down
Loading