-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Backend interfaces #8935
Backend interfaces #8935
Changes from all commits
226439a
355abbc
140e7b6
c30b9da
5aa0d83
cbd2be5
471272d
b723a2b
f5ce253
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2018 Roeland Jago Douma <roeland@famdouma.nl> | ||
* | ||
* @author Roeland Jago Douma <roeland@famdouma.nl> | ||
* | ||
* @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\User\Backend; | ||
|
||
use OC\User\Backend; | ||
use OCP\IUserBackend; | ||
use OCP\UserInterface; | ||
|
||
/** | ||
* @since 14.0.0 | ||
*/ | ||
abstract class ABackend implements IUserBackend, UserInterface { | ||
|
||
/** | ||
* @deprecated 14.0.0 | ||
* | ||
* @param int $actions The action to check for | ||
* @return bool | ||
*/ | ||
public function implementsActions($actions): bool { | ||
$implements = 0; | ||
|
||
if ($this instanceof ICreateUserBackend) { | ||
$implements |= Backend::CREATE_USER; | ||
} | ||
if ($this instanceof ISetPasswordBackend) { | ||
$implements |= Backend::SET_PASSWORD; | ||
} | ||
if ($this instanceof ICheckPasswordBackend) { | ||
$implements |= Backend::CHECK_PASSWORD; | ||
} | ||
if ($this instanceof IGetHomeBackend) { | ||
$implements |= Backend::GET_HOME; | ||
} | ||
if ($this instanceof IGetDisplayNameBackend) { | ||
$implements |= Backend::GET_DISPLAYNAME; | ||
} | ||
if ($this instanceof ISetDisplayNameBackend) { | ||
$implements |= Backend::SET_DISPLAYNAME; | ||
} | ||
if ($this instanceof IProvideAvatarBackend) { | ||
$implements |= Backend::PROVIDE_AVATAR; | ||
} | ||
if ($this instanceof ICountUsersBackend) { | ||
$implements |= Backend::COUNT_USERS; | ||
} | ||
|
||
return (bool)($actions & $implements); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2018 Roeland Jago Douma <roeland@famdouma.nl> | ||
* | ||
* @author Roeland Jago Douma <roeland@famdouma.nl> | ||
* | ||
* @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\User\Backend; | ||
|
||
/** | ||
* @since 14.0.0 | ||
*/ | ||
interface ICheckPasswordBackend { | ||
/** | ||
* @since 14.0.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you document the return values and usage for all those methods as well? (just take the ones from the DatabaseBackend There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
* | ||
* @param string $uid The username | ||
* @param string $password The password | ||
* @return string|bool The uid on success false on failure | ||
*/ | ||
public function checkPassword(string $loginName, string $password); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to type hint the success case and expect an exception on failure? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes it would. But lets do baby steps. First get this in and then have an issue/PR to discuss further steps and improvements. Because if we change all that we also have to change all the logic that is calling this etc. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay 👍 |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2018 Roeland Jago Douma <roeland@famdouma.nl> | ||
* | ||
* @author Roeland Jago Douma <roeland@famdouma.nl> | ||
* | ||
* @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\User\Backend; | ||
|
||
/** | ||
* @since 14.0.0 | ||
*/ | ||
interface ICountUsersBackend { | ||
|
||
/** | ||
* @since 14.0.0 | ||
* | ||
* @return int|bool The number of users on success false on failure | ||
*/ | ||
public function countUsers(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same exception handling here. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2018 Roeland Jago Douma <roeland@famdouma.nl> | ||
* | ||
* @author Roeland Jago Douma <roeland@famdouma.nl> | ||
* | ||
* @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\User\Backend; | ||
|
||
/** | ||
* @since 14.0.0 | ||
*/ | ||
interface ICreateUserBackend { | ||
|
||
/** | ||
* @since 14.0.0 | ||
* | ||
* @param string $uid The username of the user to create | ||
* @param string $password The password of the new user | ||
* @return bool | ||
*/ | ||
public function createUser(string $uid, string $password): bool; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I expect it to succeed or to throw an exception. So there should not be any return value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't change that without chaning the whole backend logic as well. It will happen but baby steps. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2018 Roeland Jago Douma <roeland@famdouma.nl> | ||
* | ||
* @author Roeland Jago Douma <roeland@famdouma.nl> | ||
* | ||
* @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\User\Backend; | ||
|
||
/** | ||
* @since 14.0.0 | ||
*/ | ||
interface IGetDisplayNameBackend { | ||
|
||
/** | ||
* @since 14.0.0 | ||
* | ||
* @param string $uid user ID of the user | ||
* @return string display name | ||
*/ | ||
public function getDisplayName($uid): string; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason there is no
int
type hinted?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes because this inherits from the old interfaces. And there is no typehint there.
Adding the typehint will make any userbackend do 💥 (including LDAP).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay