from collective.externaleditor.browser.views import ExternalEditorEnabledView
from collective.externaleditor.browser.views import ExternalEditView
from plone import api


def always_activated():
    return api.portal.get_registry_record(
        "ploneintranet.workspace.externaleditor_always_activated", default="False"
    )


class EnabledView(ExternalEditorEnabledView):
    """
    Display the link to the external editor in the interface.
    """

    def isActivatedInMemberProperty(self):
        if always_activated():
            return True
        else:
            return super().isActivatedInMemberProperty()

    def isActivatedInSiteProperty(self):
        if always_activated():
            return True
        else:
            return super().isActivatedInSiteProperty()


class EditView(ExternalEditView):
    """
    Return the object for editing.
    """

    def isActivatedInMemberProperty(self):
        if always_activated():
            return True
        else:
            return super().isActivatedInMemberProperty()

    def isActivatedInSiteProperty(self):
        if always_activated():
            return True
        else:
            return super().isActivatedInSiteProperty()
