aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin/lib/Trash
diff options
context:
space:
mode:
authorChristopher Ng <chrng8@gmail.com>2024-04-11 17:39:59 -0700
committerChristopher Ng <chrng8@gmail.com>2024-04-23 16:20:41 -0700
commitcaed644c03c3bbaff59135705f47be392402401c (patch)
tree96c0528f15839ed58a32d3c7549352feac52a408 /apps/files_trashbin/lib/Trash
parentb41834fb8d53e2a7d81247046731f398a80dcb1b (diff)
downloadnextcloud-server-caed644c03c3bbaff59135705f47be392402401c.tar.gz
nextcloud-server-caed644c03c3bbaff59135705f47be392402401c.zip
chore(trashbin): Add method to get deleted by from trash item
Signed-off-by: Christopher Ng <chrng8@gmail.com>
Diffstat (limited to 'apps/files_trashbin/lib/Trash')
-rw-r--r--apps/files_trashbin/lib/Trash/ITrashItem.php5
-rw-r--r--apps/files_trashbin/lib/Trash/LegacyTrashBackend.php15
-rw-r--r--apps/files_trashbin/lib/Trash/TrashItem.php37
3 files changed, 26 insertions, 31 deletions
diff --git a/apps/files_trashbin/lib/Trash/ITrashItem.php b/apps/files_trashbin/lib/Trash/ITrashItem.php
index 0f9c8144a59..bcce5c6876e 100644
--- a/apps/files_trashbin/lib/Trash/ITrashItem.php
+++ b/apps/files_trashbin/lib/Trash/ITrashItem.php
@@ -77,5 +77,10 @@ interface ITrashItem extends FileInfo {
*/
public function getUser(): IUser;
+ /**
+ * @since 30.0.0
+ */
+ public function getDeletedBy(): ?IUser;
+
public function getTitle(): string;
}
diff --git a/apps/files_trashbin/lib/Trash/LegacyTrashBackend.php b/apps/files_trashbin/lib/Trash/LegacyTrashBackend.php
index a608dc08331..fa71d386794 100644
--- a/apps/files_trashbin/lib/Trash/LegacyTrashBackend.php
+++ b/apps/files_trashbin/lib/Trash/LegacyTrashBackend.php
@@ -33,16 +33,16 @@ use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\Files\Storage\IStorage;
use OCP\IUser;
+use OCP\IUserManager;
class LegacyTrashBackend implements ITrashBackend {
/** @var array */
private $deletedFiles = [];
- /** @var IRootFolder */
- private $rootFolder;
-
- public function __construct(IRootFolder $rootFolder) {
- $this->rootFolder = $rootFolder;
+ public function __construct(
+ private IRootFolder $rootFolder,
+ private IUserManager $userManager,
+ ) {
}
/**
@@ -59,6 +59,8 @@ class LegacyTrashBackend implements ITrashBackend {
if (!$originalLocation) {
$originalLocation = $file->getName();
}
+ /** @psalm-suppress UndefinedInterfaceMethod */
+ $deletedBy = $this->userManager->get($file['deletedBy']) ?? $parent?->getDeletedBy();
$trashFilename = Trashbin::getTrashFilename($file->getName(), $file->getMtime());
return new TrashItem(
$this,
@@ -66,7 +68,8 @@ class LegacyTrashBackend implements ITrashBackend {
$file->getMTime(),
$parentTrashPath . '/' . ($isRoot ? $trashFilename : $file->getName()),
$file,
- $user
+ $user,
+ $deletedBy,
);
}, $items);
}
diff --git a/apps/files_trashbin/lib/Trash/TrashItem.php b/apps/files_trashbin/lib/Trash/TrashItem.php
index 5c9775c6876..79b9b67d278 100644
--- a/apps/files_trashbin/lib/Trash/TrashItem.php
+++ b/apps/files_trashbin/lib/Trash/TrashItem.php
@@ -27,33 +27,16 @@ use OCP\Files\FileInfo;
use OCP\IUser;
class TrashItem implements ITrashItem {
- /** @var ITrashBackend */
- private $backend;
- /** @var string */
- private $orignalLocation;
- /** @var int */
- private $deletedTime;
- /** @var string */
- private $trashPath;
- /** @var FileInfo */
- private $fileInfo;
- /** @var IUser */
- private $user;
public function __construct(
- ITrashBackend $backend,
- string $originalLocation,
- int $deletedTime,
- string $trashPath,
- FileInfo $fileInfo,
- IUser $user
+ private ITrashBackend $backend,
+ private string $originalLocation,
+ private int $deletedTime,
+ private string $trashPath,
+ private FileInfo $fileInfo,
+ private IUser $user,
+ private ?IUser $deletedBy,
) {
- $this->backend = $backend;
- $this->orignalLocation = $originalLocation;
- $this->deletedTime = $deletedTime;
- $this->trashPath = $trashPath;
- $this->fileInfo = $fileInfo;
- $this->user = $user;
}
public function getTrashBackend(): ITrashBackend {
@@ -61,7 +44,7 @@ class TrashItem implements ITrashItem {
}
public function getOriginalLocation(): string {
- return $this->orignalLocation;
+ return $this->originalLocation;
}
public function getDeletedTime(): int {
@@ -192,6 +175,10 @@ class TrashItem implements ITrashItem {
return $this->fileInfo->getParentId();
}
+ public function getDeletedBy(): ?IUser {
+ return $this->deletedBy;
+ }
+
/**
* @inheritDoc
* @return array<string, int|string|bool|float|string[]|int[]>