from plone.dexterity.content import Container
from plone.supermodel import model
from ploneintranet.userprofile.exc import CannotDeleteGroup
from ploneintranet.userprofile.interfaces import INeverDeletedMemberGroup
from zope.interface import implementer


class IWorkgroupContainer(model.Schema):
    """
    Marker interface for workgroup container
    """


@implementer(IWorkgroupContainer)
class WorkgroupContainer(Container):
    """
    A (singleton) folder to contain Workgroup instances
    """

    def _delObject(self, id, dp=1, suppress_events=False):
        """Block deletion of the required intranet group."""
        group = self.get(id, None)
        if INeverDeletedMemberGroup.providedBy(group):
            raise CannotDeleteGroup

        return super(self.__class__, self)._delObject(id, dp, suppress_events)
