Skip to content
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

Merged
merged 9 commits into from
Mar 23, 2018
Merged

Backend interfaces #8935

merged 9 commits into from
Mar 23, 2018

Conversation

rullzer
Copy link
Member

@rullzer rullzer commented Mar 22, 2018

This PR introduces interfaces to get rid of implementsActions of the user backends. Using interfaces here is much cleaner and actually what they were designed for.

I also created an abstractbackend that makes sure that backends using this new interface will continue to work as we slowly move over all the backends.

@klada @MorrisJobke how does this look?

@klada
Copy link

klada commented Mar 22, 2018

I like this approach. It's much cleaner than my suggestion from PR #8896 and user backend developers now have a clear starting point (which is AbstractBackend). The public abstract backend class still uses the OC\User\Backend namespace, but I think this is okay in this case, as this class is completely under your control.

Of course this also closes #8895.

@codecov
Copy link

codecov bot commented Mar 22, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@874f134). Click here to learn what that means.
The diff coverage is 96.77%.

@@            Coverage Diff            @@
##             master    #8935   +/-   ##
=========================================
  Coverage          ?   51.97%           
  Complexity        ?    25278           
=========================================
  Files             ?     1604           
  Lines             ?    94896           
  Branches          ?     1388           
=========================================
  Hits              ?    49321           
  Misses            ?    45575           
  Partials          ?        0
Impacted Files Coverage Δ Complexity Δ
lib/private/User/Database.php 73.22% <100%> (ø) 42 <17> (?)
lib/public/User/Backend/AbstractBackend.php 94.44% <94.44%> (ø) 9 <9> (?)

@rullzer
Copy link
Member Author

rullzer commented Mar 22, 2018

The public abstract backend class still uses the OC\User\Backend namespace, but I think this is okay in this case, as this class is completely under your control.

Yes that is fine. As long as you only use the OCP namespace it is all good.
Note that I also deprecated that method. But we need some time to move all the parts over. And this seems to be the best way I think.

@MorrisJobke
Copy link
Member

This is so much cleaner 👍 Nice 😄

@rullzer
Copy link
Member Author

rullzer commented Mar 22, 2018

@MorrisJobke I'll see if I can convert our db backend into this. And if all test still pass then I'd vote to get it in and move all other backens over slowly

@rullzer rullzer added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Mar 22, 2018
Copy link
Member

@ChristophWurst ChristophWurst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YESS! Way to go! 🙌

Just a tiny note: since we're using the I prefix for interfaces (I assume someone with a C# or similar background started this), I wonder if we should use A for abstract classes, like ABackend. I'm fine with either.

@MorrisJobke
Copy link
Member

Just a tiny note: since we're using the I prefix for interfaces (I assume someone with a C# or similar background started this), I wonder if we should use A for abstract classes, like ABackend. I'm fine with either.

Fine with me. @nickvergessen @blizzz @schiessle Opinions?

*/
interface ICheckPasswordBackend {
/**
* @since 14.0.0
Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -302,6 +302,15 @@
'OCP\\Template' => $baseDir . '/lib/public/Template.php',
'OCP\\User' => $baseDir . '/lib/public/User.php',
'OCP\\UserInterface' => $baseDir . '/lib/public/UserInterface.php',
'OCP\\User\\Backend\\AbstractBackend' => $baseDir . '/lib/public/User/Backend/AbstractBackend.php',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no up to date with latest changes

@@ -332,6 +332,15 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OCP\\Template' => __DIR__ . '/../../..' . '/lib/public/Template.php',
'OCP\\User' => __DIR__ . '/../../..' . '/lib/public/User.php',
'OCP\\UserInterface' => __DIR__ . '/../../..' . '/lib/public/UserInterface.php',
'OCP\\User\\Backend\\AbstractBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/AbstractBackend.php',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no up to date with latest changes

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Because we don't return consistent things yet :(

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
* @param int $actions The action to check for
* @return bool
*/
public function implementsActions($actions): bool {
Copy link
Member

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?

Copy link
Member Author

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).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

* @param string $password The password
* @return string|bool The uid on success false on failure
*/
public function checkPassword(string $loginName, string $password);
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay 👍

*
* @return int|bool The number of users on success false on failure
*/
public function countUsers();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same exception handling here.

* @param string $uid the username
* @return string|bool Datadir on success false on failure
*/
public function getHome(string $uid);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same exception handling here.

* @param string $password The password of the new user
* @return bool
*/
public function createUser(string $uid, string $password): bool;
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.

* @param string $displayName The new display name
* @return bool
*/
public function setDisplayName(string $uid, string $displayName): bool;
Copy link
Member

Choose a reason for hiding this comment

The 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.

* @param string $password The new password
* @return bool
*/
public function setPassword(string $uid, string $password): bool;
Copy link
Member

Choose a reason for hiding this comment

The 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.

@nickvergessen
Copy link
Member

Could have also started to use full words (Interface and Abstract) instead of introducing A now ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants