from five import grok
from import PortletAssignmentMapping
from collective.groupdashboard.interfaces import IGroupPortletAssignmentMapping
from import IPortletPermissionChecker
from AccessControl import getSecurityManager, Unauthorized
from Acquisition import aq_inner
# Provide a specific storage for group dashboard portlets with its own
# security checker
class GroupPortletAssignmentMapping(PortletAssignmentMapping):
    """An assignment mapping for user/dashboard portlets
    def id(self):
        manager = self.__manager__
        key = self.__name__
        return "++groupdashboard++%s+%s" % (manager, key,)
class GroupPortletAssignmentChecker(grok.Adapter):
    """Check the permisssion for editing group portlets
    def __call__(self):
        sm = getSecurityManager()
        context = aq_inner(self.context)
        if not sm.checkPermission("collective.groupdashboard: Edit group dashboard", context):
            raise Unauthorized("You are not allowed to manage group portlets")