diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-08-01 09:44:31 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-01 09:44:31 +0200 |
commit | f74e89bde5892a68500eeea3fa98a511b1d7f7e9 (patch) | |
tree | a152cdabfedf9caf21483b5dfb9e3f2574cc3ca5 /lib/public | |
parent | 952acd4d276b3190d23e0597c5e01b1dfc4d72bc (diff) | |
parent | 7b723813cef60e744ab14ab418c82e5ec67a9f2e (diff) | |
download | nextcloud-server-f74e89bde5892a68500eeea3fa98a511b1d7f7e9.tar.gz nextcloud-server-f74e89bde5892a68500eeea3fa98a511b1d7f7e9.zip |
Merge pull request #32482 from nextcloud/enh/noid/share-attributes
Add share attributes + prevent download permission
Diffstat (limited to 'lib/public')
-rw-r--r-- | lib/public/Files/Events/BeforeDirectFileDownloadEvent.php | 84 | ||||
-rw-r--r-- | lib/public/Files/Events/BeforeZipCreatedEvent.php | 91 | ||||
-rw-r--r-- | lib/public/Share/IAttributes.php | 68 | ||||
-rw-r--r-- | lib/public/Share/IShare.php | 31 |
4 files changed, 272 insertions, 2 deletions
diff --git a/lib/public/Files/Events/BeforeDirectFileDownloadEvent.php b/lib/public/Files/Events/BeforeDirectFileDownloadEvent.php new file mode 100644 index 00000000000..a32c95c6408 --- /dev/null +++ b/lib/public/Files/Events/BeforeDirectFileDownloadEvent.php @@ -0,0 +1,84 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright 2022 Carl Schwan <carl@carlschwan.eu> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +namespace OCP\Files\Events; + +use OCP\EventDispatcher\Event; + +/** + * This event is triggered when a user tries to download a file + * directly. + * + * @since 25.0.0 + */ +class BeforeDirectFileDownloadEvent extends Event { + private string $path; + private bool $successful = true; + private ?string $errorMessage = null; + + /** + * @since 25.0.0 + */ + public function __construct(string $path) { + parent::__construct(); + $this->path = $path; + } + + /** + * @since 25.0.0 + */ + public function getPath(): string { + return $this->path; + } + + /** + * @since 25.0.0 + */ + public function isSuccessful(): bool { + return $this->successful; + } + + /** + * Set if the event was successful + * + * @since 25.0.0 + */ + public function setSuccessful(bool $successful): void { + $this->successful = $successful; + } + + /** + * Get the error message, if any + * @since 25.0.0 + */ + public function getErrorMessage(): ?string { + return $this->errorMessage; + } + + /** + * @since 25.0.0 + */ + public function setErrorMessage(string $errorMessage): void { + $this->errorMessage = $errorMessage; + } +} diff --git a/lib/public/Files/Events/BeforeZipCreatedEvent.php b/lib/public/Files/Events/BeforeZipCreatedEvent.php new file mode 100644 index 00000000000..18f41a42899 --- /dev/null +++ b/lib/public/Files/Events/BeforeZipCreatedEvent.php @@ -0,0 +1,91 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright 2022 Carl Schwan <carl@carlschwan.eu> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCP\Files\Events; + +use OCP\EventDispatcher\Event; + +/** + * @since 25.0.0 + */ +class BeforeZipCreatedEvent extends Event { + private string $directory; + private array $files; + private bool $successful = true; + private ?string $errorMessage = null; + + /** + * @since 25.0.0 + */ + public function __construct(string $directory, array $files) { + parent::__construct(); + $this->directory = $directory; + $this->files = $files; + } + + /** + * @since 25.0.0 + */ + public function getDirectory(): string { + return $this->directory; + } + + /** + * @since 25.0.0 + */ + public function getFiles(): array { + return $this->files; + } + + /** + * @since 25.0.0 + */ + public function isSuccessful(): bool { + return $this->successful; + } + + /** + * Set if the event was successful + * + * @since 25.0.0 + */ + public function setSuccessful(bool $successful): void { + $this->successful = $successful; + } + + /** + * Get the error message, if any + * @since 25.0.0 + */ + public function getErrorMessage(): ?string { + return $this->errorMessage; + } + + /** + * @since 25.0.0 + */ + public function setErrorMessage(string $errorMessage): void { + $this->errorMessage = $errorMessage; + } +} diff --git a/lib/public/Share/IAttributes.php b/lib/public/Share/IAttributes.php new file mode 100644 index 00000000000..6e4cee08b12 --- /dev/null +++ b/lib/public/Share/IAttributes.php @@ -0,0 +1,68 @@ +<?php +/** + * @author Piotr Mrowczynski <piotr@owncloud.com> + * + * @copyright Copyright (c) 2019, ownCloud GmbH + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ +namespace OCP\Share; + +/** + * Interface IAttributes + * + * @package OCP\Share + * @since 25.0.0 + */ +interface IAttributes { + + /** + * Sets an attribute enabled/disabled. If the key did not exist before it will be created. + * + * @param string $scope scope + * @param string $key key + * @param bool $enabled enabled + * @return IAttributes The modified object + * @since 25.0.0 + */ + public function setAttribute($scope, $key, $enabled); + + /** + * Returns if attribute is enabled/disabled for given scope id and key. + * If attribute does not exist, returns null + * + * @param string $scope scope + * @param string $key key + * @return bool|null + * @since 25.0.0 + */ + public function getAttribute($scope, $key); + + /** + * Formats the IAttributes object to array with the following format: + * [ + * 0 => [ + * "scope" => <string>, + * "key" => <string>, + * "enabled" => <bool> + * ], + * ... + * ] + * + * @return array formatted IAttributes + * @since 25.0.0 + */ + public function toArray(); +} diff --git a/lib/public/Share/IShare.php b/lib/public/Share/IShare.php index 1d3cf9bbbdf..5a825552e26 100644 --- a/lib/public/Share/IShare.php +++ b/lib/public/Share/IShare.php @@ -36,7 +36,9 @@ use OCP\Files\NotFoundException; use OCP\Share\Exceptions\IllegalIDChangeException; /** - * Interface IShare + * This interface allows to represent a share object. + * + * This interface must not be implemented in your application. * * @since 9.0.0 */ @@ -300,7 +302,7 @@ interface IShare { * See \OCP\Constants::PERMISSION_* * * @param int $permissions - * @return \OCP\Share\IShare The modified object + * @return IShare The modified object * @since 9.0.0 */ public function setPermissions($permissions); @@ -315,6 +317,31 @@ interface IShare { public function getPermissions(); /** + * Create share attributes object + * + * @since 25.0.0 + * @return IAttributes + */ + public function newAttributes(): IAttributes; + + /** + * Set share attributes + * + * @param ?IAttributes $attributes + * @since 25.0.0 + * @return IShare The modified object + */ + public function setAttributes(?IAttributes $attributes); + + /** + * Get share attributes + * + * @since 25.0.0 + * @return ?IAttributes + */ + public function getAttributes(): ?IAttributes; + + /** * Set the accepted status * See self::STATUS_* * |