From b04abef20fbd9f566a616d47c6b7e4191b485ace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 11 Jul 2017 12:56:32 +0200 Subject: [PATCH] Also push user to Algolia when its role changes through the badger This may cause some superfluous pushes, though. --- pillar/api/users/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pillar/api/users/__init__.py b/pillar/api/users/__init__.py index 369081fd..bae7a2aa 100644 --- a/pillar/api/users/__init__.py +++ b/pillar/api/users/__init__.py @@ -54,7 +54,14 @@ def user_group_action(user_id: bson.ObjectId, group_id: bson.ObjectId, action: s f'user not found.') +def _update_algolia_user_changed_role(sender, user: dict): + log.debug('Sending updated user %s to Algolia due to role change', user['_id']) + hooks.push_updated_user_to_algolia(user, original=None) + + def setup_app(app, api_prefix): + from pillar.api import service + app.on_pre_GET_users += hooks.check_user_access app.on_post_GET_users += hooks.post_GET_user app.on_pre_PUT_users += hooks.check_put_access @@ -65,3 +72,5 @@ def setup_app(app, api_prefix): app.on_fetched_resource_users += hooks.after_fetching_user_resource app.register_api_blueprint(blueprint_api, url_prefix=api_prefix) + + service.signal_user_changed_role.connect(_update_algolia_user_changed_role)