From c4eb7b9cdf88f06bd930425d8b7b003d6a2c7ab7 Mon Sep 17 00:00:00 2001 From: Alexey Abel Date: Mon, 19 Oct 2020 15:38:33 +0200 Subject: [PATCH] Implement new user back end API This API uses single-method interfaces, an abstract base class for user back ends and exceptions. Signed-off-by: Alexey Abel --- lib/private/User/Backend.php | 1 + lib/public/IUserBackend.php | 2 + lib/public/User/Backend/ABackend.php | 1 + .../User/Backend/AbstractUserBackend.php | 46 +++++++++++++++ .../User/Backend/Action/ICheckPassword.php | 55 ++++++++++++++++++ .../User/Backend/Action/ICountUsers.php | 51 +++++++++++++++++ .../User/Backend/Action/ICreateUser.php | 54 ++++++++++++++++++ .../User/Backend/Action/IDeleteUser.php | 53 ++++++++++++++++++ .../Action/IFindUsersByDisplayName.php | 54 ++++++++++++++++++ .../Backend/Action/IFindUsersByUsername.php | 54 ++++++++++++++++++ .../User/Backend/Action/IGetDisplayName.php | 54 ++++++++++++++++++ lib/public/User/Backend/Action/IGetEMail.php | 54 ++++++++++++++++++ lib/public/User/Backend/Action/IGetHome.php | 54 ++++++++++++++++++ lib/public/User/Backend/Action/IGetQuota.php | 54 ++++++++++++++++++ .../User/Backend/Action/IGetRealUid.php | 56 +++++++++++++++++++ lib/public/User/Backend/Action/IHasUser.php | 52 +++++++++++++++++ .../User/Backend/Action/ISetDisplayName.php | 54 ++++++++++++++++++ lib/public/User/Backend/Action/ISetEMail.php | 54 ++++++++++++++++++ lib/public/User/Backend/Action/ISetHome.php | 54 ++++++++++++++++++ .../User/Backend/Action/ISetPassword.php | 54 ++++++++++++++++++ lib/public/User/Backend/Action/ISetQuota.php | 54 ++++++++++++++++++ .../Exception/ActionNotAvailableException.php | 10 ++++ .../Exception/UserAlreadyExistsException.php | 10 ++++ .../UserDoesNotExistInBackEndException.php | 10 ++++ .../User/Backend/ICheckPasswordBackend.php | 2 + .../User/Backend/ICountUsersBackend.php | 2 + .../User/Backend/ICreateUserBackend.php | 2 + .../User/Backend/IGetDisplayNameBackend.php | 2 + lib/public/User/Backend/IGetHomeBackend.php | 2 + .../User/Backend/IGetRealUIDBackend.php | 2 + .../Backend/IPasswordConfirmationBackend.php | 3 + .../User/Backend/ISetDisplayNameBackend.php | 2 + .../User/Backend/ISetPasswordBackend.php | 2 + lib/public/UserInterface.php | 9 ++- 34 files changed, 1022 insertions(+), 1 deletion(-) create mode 100644 lib/public/User/Backend/AbstractUserBackend.php create mode 100644 lib/public/User/Backend/Action/ICheckPassword.php create mode 100644 lib/public/User/Backend/Action/ICountUsers.php create mode 100644 lib/public/User/Backend/Action/ICreateUser.php create mode 100644 lib/public/User/Backend/Action/IDeleteUser.php create mode 100644 lib/public/User/Backend/Action/IFindUsersByDisplayName.php create mode 100644 lib/public/User/Backend/Action/IFindUsersByUsername.php create mode 100644 lib/public/User/Backend/Action/IGetDisplayName.php create mode 100644 lib/public/User/Backend/Action/IGetEMail.php create mode 100644 lib/public/User/Backend/Action/IGetHome.php create mode 100644 lib/public/User/Backend/Action/IGetQuota.php create mode 100644 lib/public/User/Backend/Action/IGetRealUid.php create mode 100644 lib/public/User/Backend/Action/IHasUser.php create mode 100644 lib/public/User/Backend/Action/ISetDisplayName.php create mode 100644 lib/public/User/Backend/Action/ISetEMail.php create mode 100644 lib/public/User/Backend/Action/ISetHome.php create mode 100644 lib/public/User/Backend/Action/ISetPassword.php create mode 100644 lib/public/User/Backend/Action/ISetQuota.php create mode 100644 lib/public/User/Backend/Exception/ActionNotAvailableException.php create mode 100644 lib/public/User/Backend/Exception/UserAlreadyExistsException.php create mode 100644 lib/public/User/Backend/Exception/UserDoesNotExistInBackEndException.php diff --git a/lib/private/User/Backend.php b/lib/private/User/Backend.php index c87dc5d2d5..bd729699e1 100644 --- a/lib/private/User/Backend.php +++ b/lib/private/User/Backend.php @@ -29,6 +29,7 @@ use OCP\UserInterface; /** * Abstract base class for user management. Provides methods for querying backend * capabilities. + * @deprecated 21.0.0 use \OCP\Public\User\Backend\AbstractUserBackEnd instead */ abstract class Backend implements UserInterface { /** diff --git a/lib/public/IUserBackend.php b/lib/public/IUserBackend.php index 7f1cbe3b4b..a0953cc586 100644 --- a/lib/public/IUserBackend.php +++ b/lib/public/IUserBackend.php @@ -36,6 +36,7 @@ namespace OCP; * Interface IUserBackend * * @since 8.0.0 + * @deprecated 21.0.0 use \OCP\Public\User\Backend\AbstractUserBackEnd instead */ interface IUserBackend { @@ -43,6 +44,7 @@ interface IUserBackend { * Backend name to be shown in user management * @return string the name of the backend to be shown * @since 8.0.0 + * @deprecated 21.0.0 use \OCP\Public\User\Backend\IUserBackEnd instead */ public function getBackendName(); } diff --git a/lib/public/User/Backend/ABackend.php b/lib/public/User/Backend/ABackend.php index a57a561369..b79cd2d8b7 100644 --- a/lib/public/User/Backend/ABackend.php +++ b/lib/public/User/Backend/ABackend.php @@ -33,6 +33,7 @@ use OCP\UserInterface; /** * @since 14.0.0 + * @deprecated 21.0.0 use \OCP\Public\User\Backend\AbstractUserBackEnd instead */ abstract class ABackend implements IUserBackend, UserInterface { diff --git a/lib/public/User/Backend/AbstractUserBackend.php b/lib/public/User/Backend/AbstractUserBackend.php new file mode 100644 index 0000000000..b565b54386 --- /dev/null +++ b/lib/public/User/Backend/AbstractUserBackend.php @@ -0,0 +1,46 @@ + + * + * @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 . + * + */ + +namespace OCP\User\Backend; + +/** + * Class AbstractUserBackend should be used as a base for all user back ends, e.g. implemented by apps. + * Additionally implement any number of interfaces in OCP\User\Backend\Action. + * + * @package OCP\User\Backend + * @since 21.0.0 + */ +class AbstractUserBackend { + + /** @var string */ + private $backEndName; + + public function __construct(string $backEndName) { + $this->backEndName = $backEndName; + } + + public function getName(): string { + return $this->backEndName; + } +} diff --git a/lib/public/User/Backend/Action/ICheckPassword.php b/lib/public/User/Backend/Action/ICheckPassword.php new file mode 100644 index 0000000000..6aa810dc2a --- /dev/null +++ b/lib/public/User/Backend/Action/ICheckPassword.php @@ -0,0 +1,55 @@ + + * + * @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 . + * + */ + +namespace OCP\User\Backend\Action; + +use OCP\User\Backend\Exception\ActionNotAvailableException; +use OCP\User\Backend\Exception\UserDoesNotExistInBackEndException; + + +/** + * @since 21.0.0 + */ +interface ICheckPassword { + /** + * @return bool whether the implementing user back end has the ability to check a password at this time + * or with the current configuration + */ + public function canCheckPassword() : bool; + + /** + * Returns whether the supplied password is correct for the supplied user. + * + * Before using this method, you must call `can...Currently()` of this interface to ensure that the user + * backend can perform this action at his time or with the current configuration, since this can change + * during runtime. The implementing user back end will throw an ActionNotAvailableException if it doesn't. + * + * @param string $username the username of the checked user + * @param string $password the password of the user to check + * @return bool true if password is correct, false otherwise + * @throws ActionNotAvailableException if this action is not supported at this time + * @throws UserDoesNotExistInBackEndException if specified username doesn't exist in the user back end + */ + public function checkPassword(string $username, string $password): bool; +} diff --git a/lib/public/User/Backend/Action/ICountUsers.php b/lib/public/User/Backend/Action/ICountUsers.php new file mode 100644 index 0000000000..17899e66e4 --- /dev/null +++ b/lib/public/User/Backend/Action/ICountUsers.php @@ -0,0 +1,51 @@ + + * + * @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 . + * + */ + +namespace OCP\User\Backend\Action; + +use OCP\User\Backend\Exception\ActionNotAvailableException; + + +/** + * @since 21.0.0 + */ +interface ICountUsers { + /** + * @return bool whether the implementing user back end has the ability to count users at this time + * or with the current configuration + */ + public function canCountUsers() : bool; + + /** + * Returns the number of users present in this user backend. + * + * Before using this method, you must call `can...Currently()` of this interface to ensure that the user + * backend can perform this action at his time or with the current configuration, since this can change + * during runtime. The implementing user back end will throw an ActionNotAvailableException if it doesn't. + * + * @return int the number of users present in this user backend + * @throws ActionNotAvailableException if this action is not supported at this time + */ + public function countUsers(): int; +} diff --git a/lib/public/User/Backend/Action/ICreateUser.php b/lib/public/User/Backend/Action/ICreateUser.php new file mode 100644 index 0000000000..b79f877632 --- /dev/null +++ b/lib/public/User/Backend/Action/ICreateUser.php @@ -0,0 +1,54 @@ + + * + * @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 . + * + */ + +namespace OCP\User\Backend\Action; + +use OCP\User\Backend\Exception\ActionNotAvailableException; +use OCP\User\Backend\Exception\UserAlreadyExistsException; + + +/** + * @since 21.0.0 + */ +interface ICreateUser { + /** + * @return bool whether the implementing user back end has the ability to create a user at this time + * or with the current configuration + */ + public function canCreateUser(): bool; + + /** + * Creates a new user. + * + * Before using this method, you must call `can...Currently()` of this interface to ensure that the user + * backend can perform this action at his time or with the current configuration, since this can change + * during runtime. The implementing user back end will throw an ActionNotAvailableException if it doesn't. + * + * @param string $username the username of the new user + * @param string $password the password of the new user + * @throws ActionNotAvailableException if this action is not supported at this time + * @throws UserAlreadyExistsException if a user with provided username already exists + */ + public function createUser(string $username, string $password): void; +} diff --git a/lib/public/User/Backend/Action/IDeleteUser.php b/lib/public/User/Backend/Action/IDeleteUser.php new file mode 100644 index 0000000000..96d23e1088 --- /dev/null +++ b/lib/public/User/Backend/Action/IDeleteUser.php @@ -0,0 +1,53 @@ + + * + * @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 . + * + */ + +namespace OCP\User\Backend\Action; + +use OCP\User\Backend\Exception\ActionNotAvailableException; +use OCP\User\Backend\Exception\UserDoesNotExistInBackEndException; + + +/** + * @since 21.0.0 + */ +interface IDeleteUser { + /** + * @return bool whether the implementing user back end has the ability to create a user at this time + * or with the current configuration + */ + public function canDeleteUser() : bool; + + /** + * Deletes a user. + * + * Before using this method, you must call `can...Currently()` of this interface to ensure that the user + * backend can perform this action at his time or with the current configuration, since this can change + * during runtime. The implementing user back end will throw an ActionNotAvailableException if it doesn't. + * + * @param string $username the username of the user to be deleted + * @throws ActionNotAvailableException if this action is not supported at this time + * @throws UserDoesNotExistInBackEndException if specified username doesn't exist in the user back end + */ + public function deleteUser(string $username): void; +} diff --git a/lib/public/User/Backend/Action/IFindUsersByDisplayName.php b/lib/public/User/Backend/Action/IFindUsersByDisplayName.php new file mode 100644 index 0000000000..dbc306b50c --- /dev/null +++ b/lib/public/User/Backend/Action/IFindUsersByDisplayName.php @@ -0,0 +1,54 @@ + + * + * @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 . + * + */ + +namespace OCP\User\Backend\Action; + +use OCP\User\Backend\Exception\ActionNotAvailableException; + + +/** + * @since 21.0.0 + */ +interface IFindUsersByDisplayName { + /** + * @return bool whether the implementing user back end has the ability to search users at this time + * or with the current configuration + */ + public function canFindUsersByDisplayName() : bool; + + /** + * Finds users by display name and returns a list of matched users. + * + * Before using this method, you must call `can...Currently()` of this interface to ensure that the user + * backend can perform this action at his time or with the current configuration, since this can change + * during runtime. The implementing user back end will throw an ActionNotAvailableException if it doesn't. + * + * @param string $pattern the search pattern + * @param int $limit limit the returned users to only this many + * @param int $offset start the returned users at this position, 0-based + * @return iterable list of users that matched the pattern or empty iterable if none matched + * @throws ActionNotAvailableException if this action is not supported at this time + */ + public function findUsersByDisplayName(string $pattern, ?int $limit, ?int $offset): iterable; +} diff --git a/lib/public/User/Backend/Action/IFindUsersByUsername.php b/lib/public/User/Backend/Action/IFindUsersByUsername.php new file mode 100644 index 0000000000..a0abf61972 --- /dev/null +++ b/lib/public/User/Backend/Action/IFindUsersByUsername.php @@ -0,0 +1,54 @@ + + * + * @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 . + * + */ + +namespace OCP\User\Backend\Action; + +use OCP\User\Backend\Exception\ActionNotAvailableException; + + +/** + * @since 21.0.0 + */ +interface IFindUsersByUsername { + /** + * @return bool whether the implementing user back end has the ability to search users at this time + * or with the current configuration + */ + public function canFindUsersByUsername() : bool; + + /** + * Finds users by username and returns a list of matched users. + * + * Before using this method, you must call `can...Currently()` of this interface to ensure that the user + * backend can perform this action at his time or with the current configuration, since this can change + * during runtime. The implementing user back end will throw an ActionNotAvailableException if it doesn't. + * + * @param string $pattern the search pattern + * @param int $limit limit the returned users to only this many + * @param int $offset start the returned users at this position, 0-based + * @return iterable list of users that matched the pattern or empty iterable if none matched + * @throws ActionNotAvailableException if this action is not supported at this time + */ + public function findUsersByUsername(string $pattern, ?int $limit, ?int $offset): iterable; +} diff --git a/lib/public/User/Backend/Action/IGetDisplayName.php b/lib/public/User/Backend/Action/IGetDisplayName.php new file mode 100644 index 0000000000..6711fcc8cf --- /dev/null +++ b/lib/public/User/Backend/Action/IGetDisplayName.php @@ -0,0 +1,54 @@ + + * + * @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 . + * + */ + +namespace OCP\User\Backend\Action; + +use OCP\User\Backend\Exception\ActionNotAvailableException; +use OCP\User\Backend\Exception\UserDoesNotExistInBackEndException; + + +/** + * @since 21.0.0 + */ +interface IGetDisplayName { + /** + * @return bool whether the implementing user back end has the ability to get a display name at this time + * or with the current configuration + */ + public function canGetDisplayName() : bool; + + /** + * Gets the display name for a user. + * + * Before using this method, you must call `can...Currently()` of this interface to ensure that the user + * backend can perform this action at his time or with the current configuration, since this can change + * during runtime. The implementing user back end will throw an ActionNotAvailableException if it doesn't. + * + * @param string $username the username to get the display name for + * @return string the display name of the user + * @throws ActionNotAvailableException if this action is not supported at this time + * @throws UserDoesNotExistInBackEndException if specified username doesn't exist in the user back end + */ + public function getDisplayName(string $username): string; +} diff --git a/lib/public/User/Backend/Action/IGetEMail.php b/lib/public/User/Backend/Action/IGetEMail.php new file mode 100644 index 0000000000..0da4bc686c --- /dev/null +++ b/lib/public/User/Backend/Action/IGetEMail.php @@ -0,0 +1,54 @@ + + * + * @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 . + * + */ + +namespace OCP\User\Backend\Action; + +use OCP\User\Backend\Exception\ActionNotAvailableException; +use OCP\User\Backend\Exception\UserDoesNotExistInBackEndException; + + +/** + * @since 21.0.0 + */ +interface IGetEMail { + /** + * @return bool whether the implementing user back end has the ability to get a e-mail at this time + * or with the current configuration + */ + public function canGetEMail() : bool; + + /** + * Gets the e-mail address for a user. + * + * Before using this method, you must call `can...Currently()` of this interface to ensure that the user + * backend can perform this action at his time or with the current configuration, since this can change + * during runtime. The implementing user back end will throw an ActionNotAvailableException if it doesn't. + * + * @param string $username the username to get the e-mail for + * @return string the e-mail of the user + * @throws ActionNotAvailableException if this action is not supported at this time + * @throws UserDoesNotExistInBackEndException if specified username doesn't exist in the user back end + */ + public function getEMail(string $username): string; +} diff --git a/lib/public/User/Backend/Action/IGetHome.php b/lib/public/User/Backend/Action/IGetHome.php new file mode 100644 index 0000000000..11d58558c1 --- /dev/null +++ b/lib/public/User/Backend/Action/IGetHome.php @@ -0,0 +1,54 @@ + + * + * @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 . + * + */ + +namespace OCP\User\Backend\Action; + +use OCP\User\Backend\Exception\ActionNotAvailableException; +use OCP\User\Backend\Exception\UserDoesNotExistInBackEndException; + + +/** + * @since 21.0.0 + */ +interface IGetHome { + /** + * @return bool whether the implementing user back end has the ability to get a home folder at this time + * or with the current configuration + */ + public function canGetHome() : bool; + + /** + * Gets the home folder for a user. + * + * Before using this method, you must call `can...Currently()` of this interface to ensure that the user + * backend can perform this action at his time or with the current configuration, since this can change + * during runtime. The implementing user back end will throw an ActionNotAvailableException if it doesn't. + * + * @param string $username the username to get the home folder for + * @return string the home folder of the user + * @throws ActionNotAvailableException if this action is not supported at this time + * @throws UserDoesNotExistInBackEndException if specified username doesn't exist in the user back end + */ + public function getHome(string $username): string; +} diff --git a/lib/public/User/Backend/Action/IGetQuota.php b/lib/public/User/Backend/Action/IGetQuota.php new file mode 100644 index 0000000000..01f5fed02b --- /dev/null +++ b/lib/public/User/Backend/Action/IGetQuota.php @@ -0,0 +1,54 @@ + + * + * @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 . + * + */ + +namespace OCP\User\Backend\Action; + +use OCP\User\Backend\Exception\ActionNotAvailableException; +use OCP\User\Backend\Exception\UserDoesNotExistInBackEndException; + + +/** + * @since 21.0.0 + */ +interface IGetQuota { + /** + * @return bool whether the implementing user back end has the ability to get a quota at this time + * or with the current configuration + */ + public function canGetQuota() : bool; + + /** + * Gets the quota for a user. + * + * Before using this method, you must call `can...Currently()` of this interface to ensure that the user + * backend can perform this action at his time or with the current configuration, since this can change + * during runtime. The implementing user back end will throw an ActionNotAvailableException if it doesn't. + * + * @param string $username the username to get the quota for + * @return string the quota of the user + * @throws ActionNotAvailableException if this action is not supported at this time + * @throws UserDoesNotExistInBackEndException if specified username doesn't exist in the user back end + */ + public function getQuota(string $username): string; +} diff --git a/lib/public/User/Backend/Action/IGetRealUid.php b/lib/public/User/Backend/Action/IGetRealUid.php new file mode 100644 index 0000000000..a49c6d8572 --- /dev/null +++ b/lib/public/User/Backend/Action/IGetRealUid.php @@ -0,0 +1,56 @@ + + * + * @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 . + * + */ + +namespace OCP\User\Backend\Action; + +use OCP\User\Backend\Exception\ActionNotAvailableException; +use OCP\User\Backend\Exception\UserDoesNotExistInBackEndException; + + +/** + * @since 21.0.0 + */ +interface IGetRealUid { + /** + * @return bool whether the implementing user back end has the ability to get the real uid at this time + * or with the current configuration + */ + public function canGetRealUid() : bool; + + /** + * Some back ends accept different UIDs than what is the internal UID to be used. + * For example the database backend accepts different cased UIDs in all the functions + * but the internal UID that is to be used should be correctly cased. + * + * Before using this method, you must call `can...Currently()` of this interface to ensure that the user + * backend can perform this action at his time or with the current configuration, since this can change + * during runtime. The implementing user back end will throw an ActionNotAvailableException if it doesn't. + * + * @param string $username the username to get the real UID for + * @return string the real UID of the user + * @throws ActionNotAvailableException if this action is not supported at this time + * @throws UserDoesNotExistInBackEndException if specified username doesn't exist in the user back end + */ + public function getRealUid(string $username): string; +} diff --git a/lib/public/User/Backend/Action/IHasUser.php b/lib/public/User/Backend/Action/IHasUser.php new file mode 100644 index 0000000000..828f17cec3 --- /dev/null +++ b/lib/public/User/Backend/Action/IHasUser.php @@ -0,0 +1,52 @@ + + * + * @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 . + * + */ + +namespace OCP\User\Backend\Action; + +use OCP\User\Backend\Exception\ActionNotAvailableException; + + +/** + * @since 21.0.0 + */ +interface IHasUser { + /** + * @return bool whether the implementing user back end has the ability to check whether a user exsits at + * this time or with the current configuration + */ + public function canHasUser() : bool; + + /** + * Checks whether a user exists in this user back end. + * + * Before using this method, you must call `can...Currently()` of this interface to ensure that the user + * backend can perform this action at his time or with the current configuration, since this can change + * during runtime. The implementing user back end will throw an ActionNotAvailableException if it doesn't. + * + * @param string $username the username whose existence is checked + * @return bool whether the user exists in this user back end + * @throws ActionNotAvailableException if this action is not supported at this time + */ + public function hasUser(string $username): bool; +} diff --git a/lib/public/User/Backend/Action/ISetDisplayName.php b/lib/public/User/Backend/Action/ISetDisplayName.php new file mode 100644 index 0000000000..d220f875c5 --- /dev/null +++ b/lib/public/User/Backend/Action/ISetDisplayName.php @@ -0,0 +1,54 @@ + + * + * @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 . + * + */ + +namespace OCP\User\Backend\Action; + +use OCP\User\Backend\Exception\ActionNotAvailableException; +use OCP\User\Backend\Exception\UserDoesNotExistInBackEndException; + + +/** + * @since 21.0.0 + */ +interface ISetDisplayName { + /** + * @return bool whether the implementing user back end has the ability to set a display name at this time + * or with the current configuration + */ + public function canSetDisplayName() : bool; + + /** + * Sets a new display name for a user. + * + * Before using this method, you must call `can...Currently()` of this interface to ensure that the user + * backend can perform this action at his time or with the current configuration, since this can change + * during runtime. The implementing user back end will throw an ActionNotAvailableException if it doesn't. + * + * @param string $username the username to set the display name for + * @param string $newDisplayName the new display name of the user + * @throws ActionNotAvailableException if this action is not supported at this time + * @throws UserDoesNotExistInBackEndException if specified username doesn't exist in the user back end + */ + public function setDisplayName(string $username, string $newDisplayName): void; +} diff --git a/lib/public/User/Backend/Action/ISetEMail.php b/lib/public/User/Backend/Action/ISetEMail.php new file mode 100644 index 0000000000..c7e2d8d7c1 --- /dev/null +++ b/lib/public/User/Backend/Action/ISetEMail.php @@ -0,0 +1,54 @@ + + * + * @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 . + * + */ + +namespace OCP\User\Backend\Action; + +use OCP\User\Backend\Exception\ActionNotAvailableException; +use OCP\User\Backend\Exception\UserDoesNotExistInBackEndException; + + +/** + * @since 21.0.0 + */ +interface ISetEMail { + /** + * @return bool whether the implementing user back end has the ability to set a e-mail at this time + * or with the current configuration + */ + public function canSetEMail() : bool; + + /** + * Sets a new e-mail for a user. + * + * Before using this method, you must call `can...Currently()` of this interface to ensure that the user + * backend can perform this action at his time or with the current configuration, since this can change + * during runtime. The implementing user back end will throw an ActionNotAvailableException if it doesn't. + * + * @param string $username the username to set the e-mail for + * @param string $newEMail the new e-mail of the user + * @throws ActionNotAvailableException if this action is not supported at this time + * @throws UserDoesNotExistInBackEndException if specified username doesn't exist in the user back end + */ + public function setEMail(string $username, string $newEMail): void; +} diff --git a/lib/public/User/Backend/Action/ISetHome.php b/lib/public/User/Backend/Action/ISetHome.php new file mode 100644 index 0000000000..64825e01a8 --- /dev/null +++ b/lib/public/User/Backend/Action/ISetHome.php @@ -0,0 +1,54 @@ + + * + * @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 . + * + */ + +namespace OCP\User\Backend\Action; + +use OCP\User\Backend\Exception\ActionNotAvailableException; +use OCP\User\Backend\Exception\UserDoesNotExistInBackEndException; + + +/** + * @since 21.0.0 + */ +interface ISetHome { + /** + * @return bool whether the implementing user back end has the ability to set a home folder at this time + * or with the current configuration + */ + public function canSetHome() : bool; + + /** + * Sets a new home folder for a user. + * + * Before using this method, you must call `can...Currently()` of this interface to ensure that the user + * backend can perform this action at his time or with the current configuration, since this can change + * during runtime. The implementing user back end will throw an ActionNotAvailableException if it doesn't. + * + * @param string $username the username to set the home folder for + * @param string $newHome the new home folder of the user + * @throws ActionNotAvailableException if this action is not supported at this time + * @throws UserDoesNotExistInBackEndException if specified username doesn't exist in the user back end + */ + public function setHome(string $username, string $newHome): void; +} diff --git a/lib/public/User/Backend/Action/ISetPassword.php b/lib/public/User/Backend/Action/ISetPassword.php new file mode 100644 index 0000000000..b4e213fbf0 --- /dev/null +++ b/lib/public/User/Backend/Action/ISetPassword.php @@ -0,0 +1,54 @@ + + * + * @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 . + * + */ + +namespace OCP\User\Backend\Action; + +use OCP\User\Backend\Exception\ActionNotAvailableException; +use OCP\User\Backend\Exception\UserDoesNotExistInBackEndException; + + +/** + * @since 21.0.0 + */ +interface ISetPassword { + /** + * @return bool whether the implementing user back end has the ability to set a password at this time + * or with the current configuration + */ + public function canSetPassword() : bool; + + /** + * Sets a new password for a user. + * + * Before using this method, you must call `can...Currently()` of this interface to ensure that the user + * backend can perform this action at his time or with the current configuration, since this can change + * during runtime. The implementing user back end will throw an ActionNotAvailableException if it doesn't. + * + * @param string $username the username to set the password for + * @param string $newPassword the new password of the user + * @throws ActionNotAvailableException if this action is not supported at this time + * @throws UserDoesNotExistInBackEndException if specified username doesn't exist in the user back end + */ + public function setPassword(string $username, string $newPassword): void; +} diff --git a/lib/public/User/Backend/Action/ISetQuota.php b/lib/public/User/Backend/Action/ISetQuota.php new file mode 100644 index 0000000000..681d122b35 --- /dev/null +++ b/lib/public/User/Backend/Action/ISetQuota.php @@ -0,0 +1,54 @@ + + * + * @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 . + * + */ + +namespace OCP\User\Backend\Action; + +use OCP\User\Backend\Exception\ActionNotAvailableException; +use OCP\User\Backend\Exception\UserDoesNotExistInBackEndException; + + +/** + * @since 21.0.0 + */ +interface ISetQuota { + /** + * @return bool whether the implementing user back end has the ability to set a quota at this time + * or with the current configuration + */ + public function canSetQuota() : bool; + + /** + * Sets a new quota for a user. + * + * Before using this method, you must call `can...Currently()` of this interface to ensure that the user + * backend can perform this action at his time or with the current configuration, since this can change + * during runtime. The implementing user back end will throw an ActionNotAvailableException if it doesn't. + * + * @param string $username the username to set the quota for + * @param string $newQuota the new quota value + * @throws ActionNotAvailableException if this action is not supported at this time + * @throws UserDoesNotExistInBackEndException if specified username doesn't exist in the user back end + */ + public function setQuota(string $username, string $newQuota): void; +} diff --git a/lib/public/User/Backend/Exception/ActionNotAvailableException.php b/lib/public/User/Backend/Exception/ActionNotAvailableException.php new file mode 100644 index 0000000000..9163dd659a --- /dev/null +++ b/lib/public/User/Backend/Exception/ActionNotAvailableException.php @@ -0,0 +1,10 @@ +