<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
    i18n_domain="untranslated"
    >

  <include package="dexterity.membrane" />
  <include package="ploneintranet.contacts" />
  <include package="ploneintranet.network" />
  <include package="ploneintranet.notifications" />

  <permission
      id="plonepas.ManageGroups"
      title="Manage Groups"
      />

  <adapter
      factory=".indexers.Title"
      name="Title"
      />
  <adapter
      factory=".indexers.sortable_title"
      name="sortable_title"
      />
  <adapter
      factory=".indexers.email"
      name="email"
      />
  <adapter
      factory=".indexers.login_time"
      name="login_time"
      />
  <adapter
      factory=".indexers.login_time_default"
      name="login_time"
      />
  <adapter
      factory=".indexers.workspace_members"
      name="workspace_members"
      />

  <include package=".behaviors" />
  <include package=".browser" />
  <include package=".content" />
  <include package=".pas" />

  <interface interface=".interfaces.IFunctionalPrincipal" />

  <!-- Allow users to edit their own profiles -->
  <adapter
      factory=".permissions.UserProfileLocalRoleAdapter"
      name="user_owner_on_his_own_profile"
      />

  <adapter
      factory=".adapters.search_membergroup"
      provides="ploneintranet.userprofile.interfaces.IMemberGroup"
      for="*"
      />

  <!-- Adapt dexterity group users to IMembraneGroupGroups so that the
  lookup of group->groups in PAS is working for our workspaces.
  See the docstring of MembraneGroupsProvider for more details.
  -->

  <adapter
      factory=".adapters.MembraneGroupsProvider"
      provides="Products.membrane.interfaces.user.IMembraneUserGroups"
      for="dexterity.membrane.behavior.user.IMembraneUser"
      />

  <adapter
      factory=".adapters.MembraneGroupsProvider"
      provides="Products.membrane.interfaces.group.IMembraneGroupGroups"
      for=".content.workgroup.IWorkGroup"
      />

  <adapter
      factory=".adapters.Email2User"
      name="email2user_vs_membrane"
      />

  <adapter
      factory=".adapters.ProfileAvatarTraverser"
      name="quaive_profile_avatar"
      />

  <adapter factory=".indexers.CustomEmailFieldConverter" />

  <utility
      provides="zope.schema.interfaces.IVocabularyFactory"
      name="ploneintranet.userprofile.locations_vocabulary"
      component=".vocabularies.primaryLocationVocabulary"
      />

  <genericsetup:registerProfile
      name="default"
      title="Plone Intranet: -- [User Profiles]"
      description="Installs the ploneintranet.userprofile package"
      provides="Products.GenericSetup.interfaces.EXTENSION"
      directory="profiles/default"
      post_handler=".setuphandlers.on_install"
      />

  <genericsetup:registerProfile
      name="uninstall"
      title="Plone Intranet: -- [User Profiles uninstall]"
      description="Installs the ploneintranet.userprofile package"
      provides="Products.GenericSetup.interfaces.EXTENSION"
      directory="profiles/uninstall"
      post_handler="ploneintranet.userprofile.uninstall.uninstall"
      />

  <genericsetup:registerProfile
      name="testing"
      title="Plone Intranet: -- [User Profiles Testing]"
      description="Testing of the ploneintranet.userprofile package"
      provides="Products.GenericSetup.interfaces.EXTENSION"
      directory="profiles/testing"
      />

  <subscriber
      for="ploneintranet.userprofile.content.workgroup.IWorkGroup
           zope.lifecycleevent.interfaces.IObjectModifiedEvent"
      handler=".subscribers.clear_workspace_groups_plugin_cache"
      />

  <subscriber
      for="ploneintranet.userprofile.content.workgroup.IWorkGroup
           zope.lifecycleevent.interfaces.IObjectAddedEvent"
      handler=".subscribers.clear_acl_users_cache"
      />

  <subscriber
      for="ploneintranet.userprofile.content.workgroup.IWorkGroup
           zope.lifecycleevent.interfaces.IObjectModifiedEvent"
      handler=".subscribers.clear_acl_users_cache"
      />

  <subscriber
      for="Products.PluggableAuthService.interfaces.events.IUserLoggedInEvent"
      handler=".subscribers.on_user_login"
      />

  <subscriber
      for="ploneintranet.userprofile.content.userprofile.IUserProfile
           Products.DCWorkflow.interfaces.IAfterTransitionEvent"
      handler=".subscribers.on_user_transition"
      />

  <subscriber
      for="ploneintranet.userprofile.content.userprofile.IUserProfile
           zope.lifecycleevent.interfaces.IObjectAddedEvent"
      handler=".subscribers.on_user_added"
      />

  <subscriber
      for="dexterity.membrane.behavior.group.IMembraneGroup
           zope.lifecycleevent.interfaces.IObjectAddedEvent"
      handler=".subscribers.on_membrane_principal_created"
      />

  <subscriber
      for="dexterity.membrane.behavior.user.IMembraneUser
           zope.lifecycleevent.interfaces.IObjectAddedEvent"
      handler=".subscribers.on_membrane_principal_created"
      />

  <subscriber
      for="dexterity.membrane.behavior.group.IMembraneGroup
           zope.lifecycleevent.interfaces.IObjectModifiedEvent"
      handler=".subscribers.on_membrane_principal_modified"
      />

  <subscriber
      for="dexterity.membrane.behavior.user.IMembraneUser
           zope.lifecycleevent.interfaces.IObjectModifiedEvent"
      handler=".subscribers.on_membrane_principal_modified"
      />

  <subscriber
      for="dexterity.membrane.behavior.group.IMembraneGroup
           zope.lifecycleevent.interfaces.IObjectRemovedEvent"
      handler=".subscribers.on_membrane_principal_removed"
      />

  <subscriber
      for="dexterity.membrane.behavior.user.IMembraneUser
           zope.lifecycleevent.interfaces.IObjectRemovedEvent"
      handler=".subscribers.on_membrane_principal_removed"
      />

</configure>
