Webhooks for User attribute changes

Problem to solve

There are no System Hook Events for when user attribute change.

Actualy the system hooks on the User entity are only fire when a user is created, removed, failed to login, or renamed.

There is no hook fired when there are others modifications, such as when a user is blocked, when he changes is profile informations, or any others data to the entity attributes.

Intended users

Developers of APIs that rely on System Hooks to create an event based solution instead of a polling/syncing based solution.

Proposal

Add a user_update system hook that will be fired any time an attribute of a user is changed, unless the user is renamed, and unless some often changed attributes are changed.

List of often changed attrbute :

  • last_sign_in_at
  • confirmed_at
  • last_activity_on
  • current_sign_in_at

It means any time one of the info visible on /api/v4/user/ changes, unless username is modified, and unless only an often changed attribute is changed.

The hook data should look like :

{
   "event_name": "user_update",
   "created_at": "2012-07-21T07:44:07Z",
   "updated_at": "2012-07-21T07:38:22Z",
        "email": "js@gitlabhq.com",
         "name": "John Smith",
     "username": "js",
      "user_id": 41
}

So this have to work exactly the same as project_update, but for the user entity, and also excluding often changed attributes. From the doc :

... project_update and project_rename deserve some clarification: project_update is fired any time an attribute of a project is changed (including name, description, and tags) unless the path attribute is also changed. In that case, a project_rename is triggered instead (so that, for instance, if all you care about is the repository URL, you can just listen for project_rename).

That means, in case the user is renamed (= username change), only user_rename hook is fired.

The except often attribute is changed feature may be an option, as it may be too tricky.

Permissions and Security

N/A

Documentation

To add in the doc:

  1. The new hook in the hook list : user_update

  2. after the section about the project_update and project_rename hooks :

Also, user_update and user_rename follow the same principle as project_update and project_rename: user_update is fired any time an attribute of an user is changed unless the username attribute is also changed. In that case, a user_rename is triggered instead.

There is nothing to add in the /admin/hooks page, the current user_* events are not mentionned, see the text:

System hook will be triggered on set of events like creating project or adding ssh key. But you can also enable extra triggers like Push events.

Availability & Testing

What does success look like, and how can we measure that?

user_updatehook is triggered when any of the user attribute change expect for username and often changed attributes.

If the user is renamed, user_update hook must not be triggered.

Links / references