Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5.1k
[stable26] Check share status when touching versions#43739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
c5c4c2a231e27cee7c57737df1b7c70b869File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -27,6 +27,7 @@ | ||
| namespace OCA\Files_Versions\Versions; | ||
| use OC\Files\View; | ||
| use OCA\DAV\Connector\Sabre\Exception\Forbidden; | ||
| use OCA\Files_Sharing\SharedStorage; | ||
| use OCA\Files_Versions\Db\VersionEntity; | ||
| use OCA\Files_Versions\Db\VersionsMapper; | ||
| @@ -41,23 +42,27 @@ | ||
| use OCP\Files\Storage\IStorage; | ||
| use OCP\IUser; | ||
| use OCP\IUserManager; | ||
| use OCP\IUserSession; | ||
| class LegacyVersionsBackend implements IVersionBackend, INameableVersionBackend, IDeletableVersionBackend { | ||
| private IRootFolder $rootFolder; | ||
| private IUserManager $userManager; | ||
| private VersionsMapper $versionsMapper; | ||
| private IMimeTypeLoader $mimeTypeLoader; | ||
| private IUserSession $userSession; | ||
| public function __construct( | ||
| IRootFolder $rootFolder, | ||
| IUserManager $userManager, | ||
| VersionsMapper $versionsMapper, | ||
| IMimeTypeLoader $mimeTypeLoader | ||
| IMimeTypeLoader $mimeTypeLoader, | ||
| IUserSession $userSession, | ||
| ) { | ||
| $this->rootFolder = $rootFolder; | ||
| $this->userManager = $userManager; | ||
| $this->versionsMapper = $versionsMapper; | ||
| $this->mimeTypeLoader = $mimeTypeLoader; | ||
| $this->userSession = $userSession; | ||
| } | ||
| public function useBackendForStorage(IStorage $storage): bool { | ||
| @@ -171,6 +176,10 @@ public function createVersion(IUser $user, FileInfo $file) { | ||
| } | ||
| public function rollback(IVersion $version) { | ||
| if (!$this->currentUserHasPermissions($version, \OCP\Constants::PERMISSION_UPDATE)) { | ||
Uh oh!There was an error while loading. Please reload this page. | ||
| throw new Forbidden('You cannot restore this version because you do not have update permissions on the source file.'); | ||
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| return Storage::rollback($version->getVersionPath(), $version->getRevisionId(), $version->getUser()); | ||
| } | ||
| @@ -202,6 +211,10 @@ public function getVersionFile(IUser $user, FileInfo $sourceFile, $revision): Fi | ||
| } | ||
| public function setVersionLabel(IVersion $version, string $label): void { | ||
| if (!$this->currentUserHasPermissions($version, \OCP\Constants::PERMISSION_UPDATE)) { | ||
Uh oh!There was an error while loading. Please reload this page. | ||
| throw new Forbidden('You cannot label this version because you do not have update permissions on the source file.'); | ||
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| $versionEntity = $this->versionsMapper->findVersionForFileId( | ||
| $version->getSourceFile()->getId(), | ||
| $version->getTimestamp(), | ||
| @@ -214,11 +227,34 @@ public function setVersionLabel(IVersion $version, string $label): void { | ||
| } | ||
| public function deleteVersion(IVersion $version): void { | ||
| if (!$this->currentUserHasPermissions($version, \OCP\Constants::PERMISSION_DELETE)) { | ||
Uh oh!There was an error while loading. Please reload this page. | ||
| throw new Forbidden('You cannot delete this version because you do not have delete permissions on the source file.'); | ||
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| Storage::deleteRevision($version->getVersionPath(), $version->getRevisionId()); | ||
| $versionEntity = $this->versionsMapper->findVersionForFileId( | ||
| $version->getSourceFile()->getId(), | ||
| $version->getTimestamp(), | ||
| ); | ||
| $this->versionsMapper->delete($versionEntity); | ||
| } | ||
| private function currentUserHasPermissions(IVersion $version, int $permissions): bool { | ||
| $sourceFile = $version->getSourceFile(); | ||
| $currentUserId = $this->userSession->getUser()?->getUID(); | ||
| if ($currentUserId === null) { | ||
| throw new NotFoundException("No user logged in"); | ||
| } | ||
| if ($sourceFile->getOwner()?->getUID() !== $currentUserId) { | ||
Check noticeCode scanning / Psalm DocblockTypeContradiction
OCP\IUser does not contain null
Check noticeCode scanning / Psalm RedundantConditionGivenDocblockType
Docblock-defined type OCP\IUser for $__tmp_nullsafe__8494 is never null
| ||
| $nodes = $this->rootFolder->getUserFolder($currentUserId)->getById($sourceFile->getId()); | ||
| $sourceFile = array_pop($nodes); | ||
| if (!$sourceFile) { | ||
| throw new NotFoundException("Version file not accessible by current user"); | ||
| } | ||
| } | ||
| return ($sourceFile->getPermissions() & $permissions) === $permissions; | ||
| } | ||
| } | ||
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.
Check notice
Code scanning / Psalm
PossiblyNullReference