from plone import api
from Products.PluggableAuthService.interfaces.plugins import IGroupsPlugin


def uninstall(context):
    """Reset the proper pas plugins"""
    au = api.portal.get_tool("acl_users")
    banned_ids = ("membrane_groups", "recursive_groups")
    for banned_id in banned_ids:
        try:
            au.plugins.activatePlugin(IGroupsPlugin, banned_id)
        except KeyError:
            pass  # Already activated

    try:
        au.plugins.deactivatePlugin(IGroupsPlugin, "pi_recursive_groups")
    except KeyError:
        pass  # Already deactivated
    if "pi_recursive_groups" in au:
        del au["pi_recursive_groups"]
