Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reindex managerRolesAndUsers recursively when managing ldap users #285

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading