Skip to content

Conversation

@blizzz
Copy link
Member

@blizzz blizzz commented Jan 17, 2019

Fixes an exception leading to a 404 return of the user details request on the members of a specified group. Please read #12991 (comment) for detailed reasonings.

To reproduce

  1. Have LDAP configured
  2. Have a local group "group1"
  3. Add an LDAP user to "group1", and another user (local or ldap does not matter, for comparison "stillExistingUser")
  4. Delete the user from LDAP (or change the filter to exclude the user)
  5. Use "occ ldap:check-user" to ensure this user is detected as deleted on LDAP (beware caching)
  6. Use the curl call against the provisioning API to get the user details (or go to Users page and click on the group)
  7. curl -H "OCS-APIRequest: true" "http://admin:[email protected]/ocs/v2.php/cloud/groups/group1/users/details"
    Before:
<?xml version="1.0"?>
<ocs>
 <meta>
  <status>failure</status>
  <statuscode>404</statuscode>
  <message>Invalid query, please check the syntax. API specifications are here: http://www.freedesktop.org/wiki/Specifications/open-collaboration-services.
</message>
 </meta>
 <data/>
</ocs>

After:

<?xml version="1.0"?>
<ocs>
 <meta>
  <status>ok</status>
  <statuscode>200</statuscode>
  <message>OK</message>
 </meta>
 <data>
  <users>
   <stillExistingUser>
    <enabled>1</enabled>
    <storageLocation>/path/to/data/stillExistingUser</storageLocation>
    <id>stillExistingUser</id>
    <lastLogin>1546614345000</lastLogin>
    <backend>Database</backend>
    <!-- ... -->
   </stillExistingUser>
  </users>
 </data>
</ocs>

$usersDetails[$userId] = ['id' => $userId];
}
} catch(OCSNotFoundException $e) {
// continue if a users ceased to exist.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe at least log something?
What's the use case of having a list of users where the user does not exists here?

Copy link
Member Author

Choose a reason for hiding this comment

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

The user is not added to the list when this Exception pops up. Or do you mean something else?

Copy link
Member

Choose a reason for hiding this comment

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

I mean, I don't really like having blank catches :p

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not an error condition, but a valid scenario.

# cf. https://github.com/nextcloud/server/issues/12991
$data['storageLocation'] = $targetUserObject->getHome();
} catch (NoUserException $e) {
throw new OCSNotFoundException($e->getMessage(), $e);
Copy link
Member

Choose a reason for hiding this comment

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

Why throw the OCS not found exception? This is mainly osmething to throw when the middleware will handle it. The NoUserException seems perfectly valid here.

Copy link
Member Author

Choose a reason for hiding this comment

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

@blizzz blizzz requested a review from MorrisJobke January 24, 2019 09:42
@blizzz
Copy link
Member Author

blizzz commented Jan 24, 2019

so, dear reviewers, is it OK to go in?

Copy link
Member

@skjnldsv skjnldsv left a comment

Choose a reason for hiding this comment

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

Then good for me :)

Copy link
Member

@MorrisJobke MorrisJobke left a comment

Choose a reason for hiding this comment

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

Code makes sense 👍

@MorrisJobke MorrisJobke merged commit 6cdb392 into master Jan 24, 2019
@MorrisJobke MorrisJobke deleted the fix/12991/catch-nouserexception-groupusersdetails branch January 24, 2019 13:23
@MorrisJobke
Copy link
Member

@blizzz Backport to which branches?

@MorrisJobke
Copy link
Member

/backport to stable15

@MorrisJobke
Copy link
Member

/backport to stable14

@MorrisJobke
Copy link
Member

Background: the report was against 14.0.4

@backportbot-nextcloud
Copy link

The backport to stable14 failed. Please do this backport manually.

@backportbot-nextcloud
Copy link

backport to stable15 in #13792

@rullzer
Copy link
Member

rullzer commented Jan 29, 2019

@blizzz backport to 14 failed. Could you do that manually?

@blizzz
Copy link
Member Author

blizzz commented Jan 30, 2019

yes, this was expected. doing it 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.

5 participants