Commit aac6859b authored by Ivan Tyagov's avatar Ivan Tyagov

Save local role group in __ac_local_roles_group_id_dict__ as it will be used later in indexation to

not pollute with more than required rows table roles_and_users.
As result this will increase a bit object database.
parent da28a475
......@@ -129,22 +129,29 @@ class IndexableObjectWrapper(object):
user_role_dict = {}
user_view_permission_role_dict = {}
optimized_role_set = set()
# First parse optimized roles and build optimized_role_set
for role_definition_group, user_and_role_list in local_roles_group_id_group_id.items():
try:
group_allowed_set = allowed_by_local_roles_group_id[role_definition_group]
except KeyError:
allowed_by_local_roles_group_id[role_definition_group] = group_allowed_set = set()
for user, role in user_and_role_list:
prefix = 'user:' + user
group_allowed_set.update((prefix, '%s:%s' % (prefix, role)))
optimized_role_set.add((user, role))
# Then parse other roles
for user, roles in localroles.iteritems():
prefix = 'user:' + user
for role in roles:
if (role in role_dict) and (getUserById(user) is not None):
# If role is monovalued, check if key is a user.
# If not, continue to index it in roles_and_users table.
user_role_dict[role] = user
if (user, role) not in optimized_role_set:
user_role_dict[role] = user # Only add to user_role_dict if not in optimized_role_set (double check)
if role in allowed_role_set:
user_view_permission_role_dict[role] = user
elif role in allowed_role_set:
for group in local_roles_group_id_group_id.get(user, ('', )):
try:
group_allowed_set = allowed_by_local_roles_group_id[group]
except KeyError:
allowed_by_local_roles_group_id[group] = group_allowed_set = set()
group_allowed_set.update((prefix, '%s:%s' % (prefix, role)))
# sort `allowed` principals
sorted_allowed_by_local_roles_group_id = {}
......
......@@ -97,14 +97,10 @@ class LocalRoleAssignorMixIn(object):
for group_id, role_list \
in role_generator.getLocalRolesFor(ob, user_name).iteritems():
group_id_role_dict.setdefault(group_id, set()).update(role_list)
# don't keep track of default group not to increase db size
if local_roles_group_id:
if local_roles_group_id not in \
local_roles_group_id_group_id.get(group_id, ()):
local_roles_group_id_group_id[group_id] = \
local_roles_group_id_group_id.get(group_id, ()) +\
(local_roles_group_id,)
for role in role_list:
# Feed local_roles_group_id_group_id with local roles assigned to a group
local_roles_group_id_group_id.setdefault(local_roles_group_id, set()).update(((group_id, role),))
## Update role assignments to groups
# Save the owner
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment