diff options
Diffstat (limited to 'lib/public')
22 files changed, 746 insertions, 51 deletions
diff --git a/lib/public/WorkflowEngine/IOperationCompat.php b/lib/public/App/Events/AppDisableEvent.php index 3e5f58a2867..5a50587446f 100644 --- a/lib/public/WorkflowEngine/IOperationCompat.php +++ b/lib/public/App/Events/AppDisableEvent.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de> + * @copyright Copyright (c) 2022, Thomas Citharel <nextcloud@tcit.fr> * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> + * @author Thomas Citharel <nextcloud@tcit.fr> * * @license GNU AGPL version 3 or any later version * @@ -23,28 +23,29 @@ declare(strict_types=1); * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ -namespace OCP\WorkflowEngine; +namespace OCP\App\Events; + +use OCP\EventDispatcher\Event; /** - * Interface IOperationCompat - * - * This interface extends IOperation to provide compatibility with old style - * Event classes. It is only present for a transition period and will be - * removed in 2023 again. - * - * @since 18.0.0 - * @deprecated + * @since 27.0.0 */ -interface IOperationCompat { +class AppDisableEvent extends Event { + private string $appId; + + /** + * @since 27.0.0 + */ + public function __construct(string $appId) { + parent::__construct(); + + $this->appId = $appId; + } + /** - * Like onEvent, but used with events that are not based on - * \OCP\EventDispatcher\Event. - * - * This method is introduced for compatibility reasons and will be removed - * in 2023 again. - * - * @since 18.0.0 - * @deprecated + * @since 27.0.0 */ - public function onEventCompat(string $eventName, $event, IRuleMatcher $ruleMatcher): void; + public function getAppId(): string { + return $this->appId; + } } diff --git a/lib/public/App/Events/AppEnableEvent.php b/lib/public/App/Events/AppEnableEvent.php new file mode 100644 index 00000000000..1aff3630f86 --- /dev/null +++ b/lib/public/App/Events/AppEnableEvent.php @@ -0,0 +1,62 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2022, Thomas Citharel <nextcloud@tcit.fr> + * + * @author Thomas Citharel <nextcloud@tcit.fr> + * + * @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\App\Events; + +use OCP\EventDispatcher\Event; + +/** + * @since 27.0.0 + */ +class AppEnableEvent extends Event { + private string $appId; + /** @var string[] */ + private array $groupIds; + + /** + * @param string[] $groupIds + * @since 27.0.0 + */ + public function __construct(string $appId, array $groupIds = []) { + parent::__construct(); + + $this->appId = $appId; + $this->groupIds = $groupIds; + } + + /** + * @since 27.0.0 + */ + public function getAppId(): string { + return $this->appId; + } + + /** + * @since 27.0.0 + */ + public function getGroupIds(): array { + return $this->groupIds; + } +} diff --git a/lib/public/App/Events/AppUpdateEvent.php b/lib/public/App/Events/AppUpdateEvent.php new file mode 100644 index 00000000000..92f1f8f9b16 --- /dev/null +++ b/lib/public/App/Events/AppUpdateEvent.php @@ -0,0 +1,51 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2022, Thomas Citharel <nextcloud@tcit.fr> + * + * @author Thomas Citharel <nextcloud@tcit.fr> + * + * @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\App\Events; + +use OCP\EventDispatcher\Event; + +/** + * @since 27.0.0 + */ +class AppUpdateEvent extends Event { + private string $appId; + + /** + * @since 27.0.0 + */ + public function __construct(string $appId) { + parent::__construct(); + + $this->appId = $appId; + } + + /** + * @since 27.0.0 + */ + public function getAppId(): string { + return $this->appId; + } +} diff --git a/lib/public/App/IAppManager.php b/lib/public/App/IAppManager.php index de36fafcdfe..faaf871a74c 100644 --- a/lib/public/App/IAppManager.php +++ b/lib/public/App/IAppManager.php @@ -94,6 +94,20 @@ interface IAppManager { public function isDefaultEnabled(string $appId):bool; /** + * Load an app, if not already loaded + * @param string $app app id + * @since 26.0.0 + */ + public function loadApp(string $app): void; + + /** + * Check if an app is loaded + * @param string $app app id + * @since 26.0.0 + */ + public function isAppLoaded(string $app): bool; + + /** * Enable an app for every user * * @param string $appId @@ -183,6 +197,27 @@ interface IAppManager { public function isShipped($appId); /** + * Loads all apps + * + * @param string[] $types + * @return bool + * + * This function walks through the Nextcloud directory and loads all apps + * it can find. A directory contains an app if the file /appinfo/info.xml + * exists. + * + * if $types is set to non-empty array, only apps of those types will be loaded + * @since 26.0.0 + */ + public function loadApps(array $types = []): bool; + + /** + * Check if an app is of a specific type + * @since 26.0.0 + */ + public function isType(string $app, array $types): bool; + + /** * @return string[] * @since 9.0.0 */ diff --git a/lib/public/AppFramework/Bootstrap/IRegistrationContext.php b/lib/public/AppFramework/Bootstrap/IRegistrationContext.php index 6350169510f..f83f30c0f1c 100644 --- a/lib/public/AppFramework/Bootstrap/IRegistrationContext.php +++ b/lib/public/AppFramework/Bootstrap/IRegistrationContext.php @@ -39,6 +39,7 @@ use OCP\Files\Template\ICustomTemplateProvider; use OCP\IContainer; use OCP\Notification\INotifier; use OCP\Preview\IProviderV2; +use OCP\Translation\ITranslationProvider; /** * The context object passed to IBootstrap::register @@ -218,6 +219,16 @@ interface IRegistrationContext { public function registerTemplateProvider(string $providerClass): void; /** + * Register a custom translation provider class that can provide translation + * between languages through the OCP\Translation APIs + * + * @param string $providerClass + * @psalm-param class-string<ITranslationProvider> $providerClass + * @since 21.0.0 + */ + public function registerTranslationProvider(string $providerClass): void; + + /** * Register an INotifier class * * @param string $notifierClass diff --git a/lib/public/AppFramework/Controller.php b/lib/public/AppFramework/Controller.php index 89cfd2e55fc..e8500d5ae1a 100644 --- a/lib/public/AppFramework/Controller.php +++ b/lib/public/AppFramework/Controller.php @@ -91,6 +91,9 @@ abstract class Controller { if ($data->getLastModified() !== null) { $response->setLastModified($data->getLastModified()); } + if ($data->isThrottled()) { + $response->throttle($data->getThrottleMetadata()); + } return $response; } diff --git a/lib/public/AppFramework/Http/Attribute/BruteForceProtection.php b/lib/public/AppFramework/Http/Attribute/BruteForceProtection.php new file mode 100644 index 00000000000..386889769cb --- /dev/null +++ b/lib/public/AppFramework/Http/Attribute/BruteForceProtection.php @@ -0,0 +1,52 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2023 Joas Schilling <coding@schilljs.com> + * + * @author Joas Schilling <coding@schilljs.com> + * + * @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\AppFramework\Http\Attribute; + +use Attribute; + +/** + * Attribute for controller methods that want to protect passwords, keys, tokens + * or other data against brute force + * + * @since 27.0.0 + */ +#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] +class BruteForceProtection { + /** + * @since 27.0.0 + */ + public function __construct( + protected string $action + ) { + } + + /** + * @since 27.0.0 + */ + public function getAction(): string { + return $this->action; + } +} diff --git a/lib/public/AppFramework/Http/Attribute/UseSession.php b/lib/public/AppFramework/Http/Attribute/UseSession.php index 79185919def..a6bac011d59 100644 --- a/lib/public/AppFramework/Http/Attribute/UseSession.php +++ b/lib/public/AppFramework/Http/Attribute/UseSession.php @@ -2,7 +2,7 @@ declare(strict_types=1); -/* +/** * @copyright 2023 Christoph Wurst <christoph@winzerhof-wurst.at> * * @author 2023 Christoph Wurst <christoph@winzerhof-wurst.at> diff --git a/lib/public/AppFramework/Http/Response.php b/lib/public/AppFramework/Http/Response.php index 4db6caa556c..152f8c4a3c5 100644 --- a/lib/public/AppFramework/Http/Response.php +++ b/lib/public/AppFramework/Http/Response.php @@ -257,7 +257,7 @@ class Response { $this->headers['Content-Security-Policy'] = $this->getContentSecurityPolicy()->buildPolicy(); $this->headers['Feature-Policy'] = $this->getFeaturePolicy()->buildPolicy(); - $this->headers['X-Robots-Tag'] = 'none'; + $this->headers['X-Robots-Tag'] = 'noindex, nofollow'; if ($this->ETag) { $mergeWith['ETag'] = '"' . $this->ETag . '"'; diff --git a/lib/public/AppFramework/Utility/ITimeFactory.php b/lib/public/AppFramework/Utility/ITimeFactory.php index 92101fd3848..7a6acf97b2d 100644 --- a/lib/public/AppFramework/Utility/ITimeFactory.php +++ b/lib/public/AppFramework/Utility/ITimeFactory.php @@ -3,6 +3,7 @@ declare(strict_types=1); /** + * @copyright Copyright (c) 2022, Joas Schilling <coding@schilljs.com> * @copyright Copyright (c) 2016, ownCloud, Inc. * * @author Bernhard Posselt <dev@bernhard-posselt.com> @@ -26,22 +27,37 @@ declare(strict_types=1); */ namespace OCP\AppFramework\Utility; +use Psr\Clock\ClockInterface; + /** - * Needed to mock calls to time() + * Use this to get a timestamp or DateTime object in code to remain testable + * * @since 8.0.0 + * @since 26.0.0 Extends the \Psr\Clock\ClockInterface interface + * @ref https://www.php-fig.org/psr/psr-20/#21-clockinterface */ -interface ITimeFactory { + +interface ITimeFactory extends ClockInterface { /** * @return int the result of a call to time() * @since 8.0.0 + * @deprecated 26.0.0 {@see ITimeFactory::now()} */ public function getTime(): int; /** * @param string $time - * @param \DateTimeZone $timezone + * @param \DateTimeZone|null $timezone * @return \DateTime * @since 15.0.0 + * @deprecated 26.0.0 {@see ITimeFactory::now()} */ public function getDateTime(string $time = 'now', \DateTimeZone $timezone = null): \DateTime; + + /** + * @param \DateTimeZone $timezone + * @return static + * @since 26.0.0 + */ + public function withTimeZone(\DateTimeZone $timezone): static; } diff --git a/lib/public/Authentication/Token/IProvider.php b/lib/public/Authentication/Token/IProvider.php new file mode 100644 index 00000000000..da2e400eb79 --- /dev/null +++ b/lib/public/Authentication/Token/IProvider.php @@ -0,0 +1,41 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2022 Artur Neumann <artur@jankaritech.com> + * + * @author Artur Neumann <artur@jankaritech.com> + * + * @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\Authentication\Token; + +/** + * @since 24.0.8 + */ +interface IProvider { + /** + * invalidates all tokens of a specific user + * if a client name is given only tokens of that client will be invalidated + * + * @param string $uid + * @param string|null $clientName + * @since 24.0.8 + * @return void + */ + public function invalidateTokensOfUser(string $uid, ?string $clientName); +} diff --git a/lib/public/Files/ObjectStore/IObjectStoreMultiPartUpload.php b/lib/public/Files/ObjectStore/IObjectStoreMultiPartUpload.php new file mode 100644 index 00000000000..f46982f3112 --- /dev/null +++ b/lib/public/Files/ObjectStore/IObjectStoreMultiPartUpload.php @@ -0,0 +1,59 @@ +<?php +/* + * @copyright Copyright (c) 2021 Julius Härtl <jus@bitgrid.net> + * + * @author Julius Härtl <jus@bitgrid.net> + * + * @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/>. + * + */ + +declare(strict_types=1); + + +namespace OCP\Files\ObjectStore; + +use Aws\Result; + +/** + * @since 26.0.0 + */ +interface IObjectStoreMultiPartUpload { + /** + * @since 26.0.0 + */ + public function initiateMultipartUpload(string $urn): string; + + /** + * @since 26.0.0 + */ + public function uploadMultipartPart(string $urn, string $uploadId, int $partId, $stream, $size): Result; + + /** + * @since 26.0.0 + */ + public function completeMultipartUpload(string $urn, string $uploadId, array $result): int; + + /** + * @since 26.0.0 + */ + public function abortMultipartUpload(string $urn, string $uploadId): void; + + /** + * @since 26.0.0 + */ + public function getMultipartUploads(string $urn, string $uploadId): array; +} diff --git a/lib/public/Files/Storage/IChunkedFileWrite.php b/lib/public/Files/Storage/IChunkedFileWrite.php new file mode 100644 index 00000000000..01f5cbbb20a --- /dev/null +++ b/lib/public/Files/Storage/IChunkedFileWrite.php @@ -0,0 +1,70 @@ +<?php +/* + * @copyright Copyright (c) 2021 Julius Härtl <jus@bitgrid.net> + * + * @author Julius Härtl <jus@bitgrid.net> + * + * @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/>. + * + */ + +declare(strict_types=1); + + +namespace OCP\Files\Storage; + +use OCP\Files\GenericFileException; + +/** + * @since 26.0.0 + */ +interface IChunkedFileWrite extends IStorage { + /** + * @param string $targetPath Relative target path in the storage + * @return string writeToken to be used with the other methods to uniquely identify the file write operation + * @throws GenericFileException + * @since 26.0.0 + */ + public function startChunkedWrite(string $targetPath): string; + + /** + * @param string $targetPath + * @param string $writeToken + * @param string $chunkId + * @param resource $data + * @param int|null $size + * @throws GenericFileException + * @since 26.0.0 + */ + public function putChunkedWritePart(string $targetPath, string $writeToken, string $chunkId, $data, int $size = null): ?array; + + /** + * @param string $targetPath + * @param string $writeToken + * @return int + * @throws GenericFileException + * @since 26.0.0 + */ + public function completeChunkedWrite(string $targetPath, string $writeToken): int; + + /** + * @param string $targetPath + * @param string $writeToken + * @throws GenericFileException + * @since 26.0.0 + */ + public function cancelChunkedWrite(string $targetPath, string $writeToken): void; +} diff --git a/lib/public/Group/Events/BeforeGroupChangedEvent.php b/lib/public/Group/Events/BeforeGroupChangedEvent.php new file mode 100644 index 00000000000..d30113c23be --- /dev/null +++ b/lib/public/Group/Events/BeforeGroupChangedEvent.php @@ -0,0 +1,94 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright 2023 Julien Veyssier <julien-nc@posteo.net> + * + * @author Julien Veyssier <julien-nc@posteo.net> + * + * @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\Group\Events; + +use OCP\EventDispatcher\Event; +use OCP\IGroup; + +/** + * @since 26.0.0 + */ +class BeforeGroupChangedEvent extends Event { + private IGroup $group; + private string $feature; + /** @var mixed */ + private $value; + /** @var mixed */ + private $oldValue; + + /** + * @since 26.0.0 + */ + public function __construct(IGroup $group, + string $feature, + $value, + $oldValue = null) { + parent::__construct(); + $this->group = $group; + $this->feature = $feature; + $this->value = $value; + $this->oldValue = $oldValue; + } + + /** + * + * @since 26.0.0 + * + * @return IGroup + */ + public function getGroup(): IGroup { + return $this->group; + } + + /** + * + * @since 26.0.0 + * + * @return string + */ + public function getFeature(): string { + return $this->feature; + } + + /** + * @since 26.0.0 + * + * @return mixed + */ + public function getValue() { + return $this->value; + } + + /** + * + * @since 26.0.0 + * + * @return mixed + */ + public function getOldValue() { + return $this->oldValue; + } +} diff --git a/lib/public/IRequest.php b/lib/public/IRequest.php index bb290233306..93f065500cb 100644 --- a/lib/public/IRequest.php +++ b/lib/public/IRequest.php @@ -78,6 +78,11 @@ interface IRequest { public const USER_AGENT_CLIENT_DESKTOP = '/^Mozilla\/5\.0 \([A-Za-z ]+\) (mirall|csyncoC)\/.*$/'; /** + * @since 26.0.0 + */ + public const USER_AGENT_TALK_DESKTOP = '/^Mozilla\/5\.0 \((?!Android|iOS)[A-Za-z ]+\) Nextcloud\-Talk v.*$/'; + + /** * @since 9.1.0 */ public const USER_AGENT_CLIENT_IOS = '/^Mozilla\/5\.0 \(iOS\) (ownCloud|Nextcloud)\-iOS.*$/'; diff --git a/lib/public/RichObjectStrings/Definitions.php b/lib/public/RichObjectStrings/Definitions.php index 383d626c155..57da9f4eb30 100644 --- a/lib/public/RichObjectStrings/Definitions.php +++ b/lib/public/RichObjectStrings/Definitions.php @@ -347,6 +347,12 @@ class Definitions { 'description' => 'Whether or not a preview is available. If `no` the mimetype icon should be used', 'example' => 'yes', ], + 'mtime' => [ + 'since' => '25.0.0', + 'required' => false, + 'description' => 'The mtime of the file/folder as unix timestamp', + 'example' => '1661854213', + ], ], ], 'forms-form' => [ diff --git a/lib/public/Share/IShare.php b/lib/public/Share/IShare.php index f8f75be4c41..40548c6c73d 100644 --- a/lib/public/Share/IShare.php +++ b/lib/public/Share/IShare.php @@ -118,6 +118,11 @@ interface IShare { public const TYPE_DECK_USER = 13; /** + * @since 26.0.0 + */ + public const TYPE_SCIENCEMESH = 15; + + /** * @since 18.0.0 */ public const STATUS_PENDING = 0; diff --git a/lib/public/WorkflowEngine/IEntityCompat.php b/lib/public/Translation/IDetectLanguageProvider.php index a1c6d20c034..f6db4f7d9c1 100644 --- a/lib/public/WorkflowEngine/IEntityCompat.php +++ b/lib/public/Translation/IDetectLanguageProvider.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de> + * @copyright Copyright (c) 2023 Julius Härtl <jus@bitgrid.net> * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> + * @author Julius Härtl <jus@bitgrid.net> * * @license GNU AGPL version 3 or any later version * @@ -21,27 +21,19 @@ declare(strict_types=1); * * 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\WorkflowEngine; + + +namespace OCP\Translation; /** - * Interface IEntityCompat - * - * This interface extends IEntity to provide compatibility with old style - * Event classes. It is only present for a transition period and will be - * removed in 2023 again. - * - * @since 18.0.0 - * @deprecated + * @since 26.0.0 */ -interface IEntityCompat extends IEntity { +interface IDetectLanguageProvider { /** - * Like prepareRuleMatcherCompat, but works with events that are not based - * on \OCP\EventDispatcher\Event. + * Try to detect the language of a given string * - * @since 18.0.0 - * @deprecated + * @since 26.0.0 */ - public function prepareRuleMatcherCompat(IRuleMatcher $ruleMatcher, string $eventName, $event): void; + public function detectLanguage(string $text): ?string; } diff --git a/lib/public/Translation/ITranslationManager.php b/lib/public/Translation/ITranslationManager.php new file mode 100644 index 00000000000..c6b67462152 --- /dev/null +++ b/lib/public/Translation/ITranslationManager.php @@ -0,0 +1,60 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2023 Julius Härtl <jus@bitgrid.net> + * + * @author Julius Härtl <jus@bitgrid.net> + * + * @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\Translation; + +use InvalidArgumentException; +use OCP\PreConditionNotMetException; +use RuntimeException; + +/** + * @since 26.0.0 + */ +interface ITranslationManager { + /** + * @since 26.0.0 + */ + public function hasProviders(): bool; + + /** + * @since 26.0.0 + */ + public function canDetectLanguage(): bool; + + /** + * @since 26.0.0 + * @return LanguageTuple[] + */ + public function getLanguages(): array; + + /** + * @since 26.0.0 + * @throws PreConditionNotMetException If no provider was registered but this method was still called + * @throws InvalidArgumentException If no matching provider was found that can detect a language + * @throws RuntimeException If the translation failed for other reasons + */ + public function translate(string $text, ?string $fromLanguage, string $toLanguage): string; +} diff --git a/lib/public/Translation/ITranslationProvider.php b/lib/public/Translation/ITranslationProvider.php new file mode 100644 index 00000000000..ac77ba2230e --- /dev/null +++ b/lib/public/Translation/ITranslationProvider.php @@ -0,0 +1,50 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2022 Julius Härtl <jus@bitgrid.net> + * + * @author Julius Härtl <jus@bitgrid.net> + * + * @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\Translation; + +use RuntimeException; + +/** + * @since 26.0.0 + */ +interface ITranslationProvider { + /** + * @since 26.0.0 + */ + public function getName(): string; + + /** + * @since 26.0.0 + */ + public function getAvailableLanguages(): array; + + /** + * @since 26.0.0 + * @throws RuntimeException If the text could not be translated + */ + public function translate(?string $fromLanguage, string $toLanguage, string $text): string; +} diff --git a/lib/public/Translation/LanguageTuple.php b/lib/public/Translation/LanguageTuple.php new file mode 100644 index 00000000000..9defb17e4b6 --- /dev/null +++ b/lib/public/Translation/LanguageTuple.php @@ -0,0 +1,69 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2023 Julius Härtl <jus@bitgrid.net> + * + * @author Julius Härtl <jus@bitgrid.net> + * + * @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\Translation; + +use JsonSerializable; + +/** + * @since 26.0.0 + */ +class LanguageTuple implements JsonSerializable { + /** + * @since 26.0.0 + */ + public function __construct( + private string $from, + private string $fromLabel, + private string $to, + private string $toLabel + ) { + } + + /** + * @since 26.0.0 + */ + public function jsonSerialize(): array { + return [ + 'from' => $this->from, + 'fromLabel' => $this->fromLabel, + 'to' => $this->to, + 'toLabel' => $this->toLabel, + ]; + } + + /** + * @since 26.0.0 + */ + public static function fromArray(array $data): LanguageTuple { + return new self( + $data['from'], + $data['fromLabel'], + $data['to'], + $data['toLabel'], + ); + } +} diff --git a/lib/public/User/Events/BeforeUserLoggedInEvent.php b/lib/public/User/Events/BeforeUserLoggedInEvent.php index a0818bff88f..ca74f926a17 100644 --- a/lib/public/User/Events/BeforeUserLoggedInEvent.php +++ b/lib/public/User/Events/BeforeUserLoggedInEvent.php @@ -24,27 +24,29 @@ declare(strict_types=1); * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ + namespace OCP\User\Events; +use OCP\Authentication\IApacheBackend; use OCP\EventDispatcher\Event; /** * @since 18.0.0 */ class BeforeUserLoggedInEvent extends Event { - /** @var string */ - private $username; - - /** @var string */ - private $password; + private string $username; + private ?string $password; + private ?IApacheBackend $backend; /** * @since 18.0.0 + * @since 26.0.0 password can be null */ - public function __construct(string $username, string $password) { + public function __construct(string $username, ?string $password, ?IApacheBackend $backend = null) { parent::__construct(); $this->username = $username; $this->password = $password; + $this->backend = $backend; } /** @@ -58,8 +60,19 @@ class BeforeUserLoggedInEvent extends Event { /** * @since 18.0.0 + * @since 26.0.0 value can be null */ - public function getPassword(): string { + public function getPassword(): ?string { return $this->password; } + + /** + * return backend if available (or null) + * + * @return IApacheBackend|null + * @since 26.0.0 + */ + public function getBackend(): ?IApacheBackend { + return $this->backend; + } } |