Skip to content

Commit

Permalink
Merge pull request #285 from euphorie/scrum-2640-reindex-manage-ldap-…
Browse files Browse the repository at this point in the history
…users-recursively

Reindex managerRolesAndUsers recursively when managing ldap users
  • Loading branch information
reinhardt authored Oct 29, 2024
2 parents cc4793c + ecc6cfc commit dce906b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Changelog
10.0.3 (unreleased)
-------------------

- Also update admin index for sectors and tools when managing ldap users.
(`#2640 <https://github.com/syslabcom/scrum/issues/2640>`_)
[reinhardt]

- Action Plan: Strip HTML from comments
(`#2763 <https://github.com/syslabcom/scrum/issues/2763>`_)
[reinhardt]
Expand Down
21 changes: 20 additions & 1 deletion src/osha/oira/content/browser/manage_ldap_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
from plone.memoize.view import memoize_contextless
from Products.Five import BrowserView

import logging


logger = logging.getLogger(__name__)


class BaseManageLDAPUsersView(BrowserView):
_roles = set()
Expand Down Expand Up @@ -67,6 +72,20 @@ def revoke_roles(self, user):
obj=self.context,
)

def reindex_manager_roles(self, obj):
"""Reindex `managerRolesAndUsers` index for `obj` and its contents recursively.
Based on Products.CMFCore.CMFCatalogAware.CatalogAware.reindexObjectSecurity
"""
catalog = api.portal.get_tool("portal_catalog")
path = "/".join(obj.getPhysicalPath())
for brain in catalog.unrestrictedSearchResults(path=path):
try:
ob = brain._unrestrictedGetObject()
except (AttributeError, KeyError):
# don't fail on catalog inconsistency
continue
ob.reindexObject(idxs=["managerRolesAndUsers"])

def maybe_manage_local_roles(self):
"""Check the request and see if we should mange some user local
roles."""
Expand All @@ -83,7 +102,7 @@ def maybe_manage_local_roles(self):
self.grant_roles(user)
elif ldap_action == "revoke":
self.revoke_roles(user)
self.context.reindexObject(idxs=["managerRolesAndUsers"])
self.reindex_manager_roles(self.context)

def __call__(self):
self.maybe_manage_local_roles()
Expand Down

0 comments on commit dce906b

Please sign in to comment.