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

[user_ldap] Update profile from LDAP fields #36565

Merged
merged 23 commits into from
Apr 20, 2023

Conversation

march42
Copy link
Contributor

@march42 march42 commented Feb 6, 2023

Summary

Implement feature, to update user profile data from LDAP attributes.
Add configuration items for LDAP attribute mapping (Administration - LDAP/AD integration - Advanced - User Profile Attributes)
Add methods for user profile properties to lib/private/User/User.php
Add connections for LDAP attributes to user profile properties

TODO

  • Testing with various setting and scenario

Checklist

@szaimen szaimen added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Feb 9, 2023
@szaimen szaimen requested review from come-nc, blizzz and artonge February 9, 2023 17:39
Copy link
Contributor

@come-nc come-nc left a comment

Choose a reason for hiding this comment

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

The feature will be popular I think but the code needs to be refined.
Also we must be very careful about performance in user_ldap, this should have no performance impact when not used.

@Pytal Can you review this? It’s a lot related to the profile system.

@come-nc come-nc requested a review from Pytal February 13, 2023 08:59
Copy link
Contributor Author

@march42 march42 left a comment

Choose a reason for hiding this comment

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

cleanup: remove unneeded unset

@march42 march42 force-pushed the feature/ldap_update_profile branch from 370262a to e92713e Compare February 14, 2023 14:56
@march42
Copy link
Contributor Author

march42 commented Feb 27, 2023

I reworked the code:

  • prepare and propagate an array with the profile data from LDAP and fetching user just once. Like @come-nc suggested.
  • added Fediverse profile property
  • did some cleanup and simplification
  • fixed messages from psalm

I have found, that some commits are not correctly signed-off. Seems to be like all commits through GitHub Desktop. So I would probably best rebase the branch before you finally merge it. Any suggestions?

@march42 march42 requested review from Pytal and come-nc and removed request for blizzz, artonge, Pytal and come-nc February 27, 2023 10:14
Copy link
Contributor

@come-nc come-nc left a comment

Choose a reason for hiding this comment

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

See my last comment, please go through the accountmanager instead of adding methods to OCP\User.

Also, could you please detail how this will behave for multivalue fields from LDAP?

Regarding scope, if I understand correctly the admin can force a given scope for all profile data synced from LDAP?
What happens if the user then changes the scope?

Is it possible for the admin to leave the scope option empty to let users decide the scope of each information?

@come-nc come-nc changed the title Feature/ldap update profile [user_ldap] Update profile from LDAP fields Feb 27, 2023
@come-nc
Copy link
Contributor

come-nc commented Feb 27, 2023

I have found, that some commits are not correctly signed-off. Seems to be like all commits through GitHub Desktop. So I would probably best rebase the branch before you finally merge it. Any suggestions?

You can use rebase with --signoff option.
For instance git rebase HEAD~25 --signoff will add a signoff to the last 25 commits.

@march42
Copy link
Contributor Author

march42 commented Feb 28, 2023 via email

@come-nc
Copy link
Contributor

come-nc commented Feb 28, 2023

Now, you got me a little pissed, because you were unspecific and I think I'm not supposed to read your mind. I'll be specific, so we could find an agreement on how to handle. First of all. I feel unappreciated, even unseen. I created my branch in May 2022, after issue 32085 was opened. see #32085 (comment) I invested time, to package my quick'n'dirty hack and pretty it up, before committing to GitHub. I updated the documentation, run numerous test and checked different scenarios. Nobody seemed to care, until February 2023, when I was asked to make a pull request.

I’m sorry you feel that way, that was not my intention of course.
I do not follow feature requests in the issues closely as we already have a lot on our plate. So I only became aware of this when the PR was open and I got pinged for a review.
I’m used to reviewing code from collegues and being picky about it, to try to merge the best code as possible. Sorry if that felt like too much complains, your work is appreciated of course. As I previously stated I think this feature will be welcomed by users.

I don't need this to be integrated. I don't have any intentions on wasting my time or your time. I have two working solutions and patching after update is done in minutes. If this is unwanted or unappreciated, I'm happy with closing and deletion. This is your call to make. After your suggestions two weeks ago I took time, to rework the code and test on current version 25 and version 26 beta 3 and 4. […] I took time, to rewrite the code and even more time to test it and cleanup the coding. Now I have to go back and do it again, because your suggestions were too cautious phrased. I'm not very happy with this and I will have to make time for this next weekend.

I am happy with the refactoring you did regarding fetching the user and I do not think it overlaps that much with going through the account intead of OCP\IUser.
Only the calls to $user->setProfileProperty will need to change on user_ldap side.

  1. What do you want me to do with those unset. I don't want you to be uncomfortable. I did, what I thought was intended. Looking at the original code of processAttributes, for example version 25 starting line 162, you can see a number of unset($attr) in lines 172, 192, 201, 232. I used that present code as guideline for my coding. I am pretty unaffected by wether or not those are present. I’m still not comfortable with those unset, we are not micromanaging memory anywhere else in our code like this. Like I said, You are doing it in your code exactly in the questioned processAttributes function. What should I do to make you comfortable? 3. I will take time, to ckeck and test this specifically and add more clearification to the documentation.

Thank you for the pointers on processAttribute, that’s code from before I joined Nextcloud, I did not see much unset in the rest of the code.
I was just afraid by merging those unset of setting a precedent and having unsets added everywhere in the code. Because I do not understand why these local vars should be unset more than any other.
@blizzz Do you remember what is the rationale behind the unset calls in processAttribute?

Thank you for your details on scope handling, that sounds quite reasonable.

If this is eating too much of your time I can take it from here if your prefer.

@march42 march42 force-pushed the feature/ldap_update_profile branch from 1a18abe to 225a46d Compare March 7, 2023 19:11
march42 and others added 19 commits April 6, 2023 08:20
Signed-off-by: Marc Hefter <marchefter@march42.net>
Signed-off-by: Marc Hefter <marchefter@gmail.com>
Signed-off-by: Marc Hefter <marchefter@march42.net>
Signed-off-by: Marc Hefter <marchefter@gmail.com>
…p#639

Signed-off-by: Marc Hefter <marchefter@march42.net>
Signed-off-by: Marc Hefter <marchefter@gmail.com>
…er, IDBConnection

Signed-off-by: Marc Hefter <marchefter@march42.net>
Signed-off-by: Marc Hefter <marchefter@gmail.com>
Signed-off-by: march42 <marchefter@gmail.com>
Signed-off-by: Marc Hefter <marchefter@gmail.com>
Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com>
Signed-off-by: Marc Hefter <marchefter@march42.net>
Signed-off-by: Marc Hefter <marchefter@gmail.com>
Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com>
Signed-off-by: Marc Hefter <marchefter@gmail.com>
Co-authored-by: Pytal <24800714+Pytal@users.noreply.github.com>
Signed-off-by: Marc Hefter <marchefter@march42.net>
Signed-off-by: Marc Hefter <marchefter@gmail.com>
Signed-off-by: Marc Hefter <marchefter@gmail.com>
Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com
Signed-off-by: Marc Hefter <marchefter@gmail.com>
using an array to buffer profile updates, like suggested by @come-nc
clean some code and remove unneccessary redundancy
added the Fediverse profile property

Co-Authored-By: Côme Chilliet <91878298+come-nc@users.noreply.github.com>
Signed-off-by: Marc Hefter <marchefter@gmail.com>
Signed-off-by: Marc Hefter <marchefter@gmail.com>
rework updateProfile in user_ldap/lib/User/User.php
some cleanup at processAttributes in user_ldap/lib/User/User.php
rearranged Fediverse attribute, to match profile layout

Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com>
Signed-off-by: Marc Hefter <marchefter@gmail.com>
removed changes from lib/public/IUser.php
removed changes from lib/private/User/LazyUser.php
removed changes from lib/private/User/User.php

Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com>
Signed-off-by: Marc Hefter <marchefter@gmail.com>
merging defaultScopes from DEFAULT_SCOPES and account_manager.default_property_scope
removing unneccessary profileScope setting (using config.php instead)
honoring admin choice 'profile.enabled'=>false in config.php
moved checking for empty array to updateProfile function
corrected some typos and cleaned some comments

Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com>
Signed-off-by: Marc Hefter <marchefter@gmail.com>
replace '$' with ', ' delimiter for address property
reformatted some code to 80 column
early check and return, if wasRefreshed('profile')
removed FIXMEs after digging and double checking

Signed-off-by: Marc Hefter <marchefter@gmail.com>
Signed-off-by: Marc Hefter <marchefter@gmail.com>
Signed-off-by: Marc Hefter <marchefter@gmail.com>
added error message on InvalidArgumentException

Signed-off-by: Marc Hefter <marchefter@gmail.com>
@march42 march42 force-pushed the feature/ldap_update_profile branch from 8e18632 to eec5e70 Compare April 11, 2023 14:44
Check profile data checksum before updating user profile, to ensure
data has changed. Write checksum to user settings and cache.

Signed-off-by: Marc Hefter <marchefter@gmail.com>
@szaimen
Copy link
Contributor

szaimen commented Apr 17, 2023

Merge?

@szaimen szaimen added 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels Apr 17, 2023
@march42
Copy link
Contributor Author

march42 commented Apr 20, 2023

Merge?

If you're asking me, then yes.

@szaimen szaimen merged commit 93966e9 into nextcloud:master Apr 20, 2023
@welcome
Copy link

welcome bot commented Apr 20, 2023

Thanks for your first pull request and welcome to the community! Feel free to keep them coming! If you are looking for issues to tackle then have a look at this selection: https://github.com/nextcloud/server/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22

@come-nc
Copy link
Contributor

come-nc commented Apr 20, 2023

There are open questions in nextcloud/documentation#9614

@march42 march42 deleted the feature/ldap_update_profile branch April 27, 2023 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4. to release Ready to be released and/or waiting for tests to finish enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Import personal data from LDAP
5 participants