##// END OF EJS Templates
caches: flush *all* caches used for permissions.
marcink -
r4331:d4b95196 default
parent child Browse files
Show More
@@ -1,44 +1,55 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2016-2020 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 import logging
22 22
23 23 from rhodecode import events
24 24 from rhodecode.lib import rc_cache
25 25
26 26 log = logging.getLogger(__name__)
27 27
28 # names of namespaces used for different permission related cached
29 # during flush operation we need to take care of all those
30 cache_namespaces = [
31 'cache_user_auth.{}',
32 'cache_user_repo_acl_ids.{}',
33 'cache_user_user_group_acl_ids.{}',
34 'cache_user_repo_group_acl_ids.{}'
35 ]
36
28 37
29 38 def trigger_user_permission_flush(event):
30 39 """
31 40 Subscriber to the `UserPermissionsChange`. This triggers the
32 41 automatic flush of permission caches, so the users affected receive new permissions
33 42 Right Away
34 43 """
35 44
36 45 affected_user_ids = set(event.user_ids)
37 46 for user_id in affected_user_ids:
38 cache_namespace_uid = 'cache_user_auth.{}'.format(user_id)
39 del_keys = rc_cache.clear_cache_namespace('cache_perms', cache_namespace_uid)
40 log.debug('Deleted %s cache keys for user_id: %s', del_keys, user_id)
47 for cache_namespace_uid_tmpl in cache_namespaces:
48 cache_namespace_uid = cache_namespace_uid_tmpl.format(user_id)
49 del_keys = rc_cache.clear_cache_namespace('cache_perms', cache_namespace_uid)
50 log.debug('Deleted %s cache keys for user_id: %s and namespace %s',
51 del_keys, user_id, cache_namespace_uid)
41 52
42 53
43 54 def includeme(config):
44 55 config.add_subscriber(trigger_user_permission_flush, events.UserPermissionsChange)
General Comments 0
You need to be logged in to leave comments. Login now