UserService Plugin removes custom properties when updating user

Hi All,

I’ve noticed that whenever I try to update existing user and it’s custom properties all key-value pairs which are not part of the payload are deleted.

**Example: **
my "testuser"
has 3 custom properties P1, P2 and P3

I construct a payload

<?xml version="1.0" encoding"UTF-8" standalone'"yes"?>
 <username>testuser</username>

 <name> Jon Doe </name>

 <properties>

      <property key="P1" value="some value1"/>

      <property key="P3" value="some value2"/>

 </properties>

I use that payload in my PUT request and for userService/users/{username} url

the effect is that my custom property P2 is removed.

a not really desirable behavior.

I assume that behavior is caused by running

user.getProperties().clear();

inside

private void addProperties(UserEntity userEntity) throws ServiceException

of class

UserServicePluginNG

If this is a feature not a bug… I can’t really see the logic behind it, so can someone explain?

Hey,

The main reason was to to update and delete user as simple as possible.

That means if I should keep the P2 by an update, I need also a possibility to remove the P2.

And that means I need to extend the delete endpoint with possibility to remove specific property.

I would be glad to see an Pull Request if you want to improve that, otherwise I could extend that in the near future.

Thanks Red,

I feel that an update should not remove any existing data beside updating those in payload.
Of course then we would be missing an endpoint to remove some data from existing user if we want to

You have more knowledge of most common use scenarios for the plugin so I leave it up to you how to best design it.
But please consider it a feature request for the next version. A better way to distinguish overwriting and updating a user.

When I was trying to find a suitable workaround, I was considering pulling all properties of the user and using this information in the update payload. But I haven’t found any easy way to do it.

For the moment I have modified your code to suit my needs any built my version of the plugin. But for the long run I’m kind of cutting myself from future updates.

When I was trying to find a suitable workaround, I was considering pulling all properties of the user and using this information in the update payload. But I haven’t found any easy way to do it.
You could get the user with properties by call:

GET /userService/users/{username}

Update the properties you need and send an PUT (update) with new values.

Documentation: User Service Plugin Readme

I’ve tried that but it returns only basic properties of a user, not the custom ones.

No, it’s replay also custom properties

Example:

GET http://localhost:9090/plugins/userService/users/admin

Response:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<user>
    <username>admin</username>
    <name>Administrator</name>
    <email>admin@example.com</email>
    <properties>
        <property key="filterGTALK" value="kraken-registrations=1"/>
        <property key="filterGADUGADU" value="kraken-registrations=1"/>
        <property key="filterMYSPACEIM" value="kraken-registrations=1"/>
        <property key="filterFACEBOOK" value="kraken-registrations=1"/>
        <property key="filterMSN" value="kraken-registrations=1"/>
        <property key="filterSIGNEDON" value="kraken-registrations=1"/>
        <property key="filterIRC" value="kraken-registrations=1"/>
        <property key="filterLIVEJOURNAL" value="kraken-registrations=1"/>
        <property key="filterXMPP" value="kraken-registrations=1"/>
        <property key="filterSIMPLE" value="kraken-registrations=1"/>
        <property key="filterRENREN" value="kraken-registrations=1"/>
        <property key="filterICQ" value="kraken-registrations=1"/>
        <property key="filterSET" value="kraken-registrations=1"/>
        <property key="filterQQ" value="kraken-registrations=1"/>
        <property key="filterYAHOO" value="kraken-registrations=1"/>
        <property key="filterAIM" value="kraken-registrations=1"/>
        <property key="filterSAMETIME" value="kraken-registrations=1"/>
    </properties>
</user>