from borg.localrole.default_adapter import DefaultLocalRoleAdapter
from borg.localrole.interfaces import ILocalRoleProvider
from ploneintranet.userprofile.content.userprofile import IUserProfile
from Products.membrane.interfaces import IMembraneUserObject
from zope.component import adapter
from zope.interface import implementer


@implementer(ILocalRoleProvider)
@adapter(IUserProfile)
class UserProfileLocalRoleAdapter(DefaultLocalRoleAdapter):
    """
    User's get 'Owner' on their own user profile
    """

    def getRoles(self, principal_id):
        """
        give an Owner who is also a 'selfpublisher', the reviewer role
        """
        context = self.context
        userid = IMembraneUserObject(context).getUserId()
        if principal_id == userid:
            return ("Owner",)
        return ()
