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

  <include
      package="."
      file="implements.zcml"
      />

  <include
      package="Products.CMFCore"
      file="permissions.zcml"
      />
  <include package="Products.CMFPlacefulWorkflow" />
  <include package="collective.workspace" />
  <include package="ploneintranet.invitations" />
  <include package="ploneintranet.theme" />
  <include package="ploneintranet.activitystream" />
  <include package="ploneintranet.bookmarks" />
  <include package="ploneintranet.microblog" />
  <include package="ploneintranet.network" />
  <include package="ploneintranet.search" />
  <include package="ploneintranet.todo" />
  <include package="slc.mailrouter" />
  <include package="slc.outdated" />

  <!-- does NOT include Owner, in contrast with collective.workspace: Manage roster -->
  <permission
      id="ploneintranet.workspace.ManageWorkspace"
      title="ploneintranet.workspace: Manage workspace"
      >
    <role name="Manager" />
    <role name="Site Administrator" />
    <role name="TeamManager" />
  </permission>

  <include package=".basecontent" />
  <include package=".behaviors" />
  <include package=".browser" />
  <include package=".notifications" />

  <include file="indexers.zcml" />
  <include file="mailrouters.zcml" />

  <subscriber
      for="*
           collective.workspace.events.TeamMemberEvent"
      handler="ploneintranet.userprofile.subscribers.clear_workspace_groups_plugin_cache"
      />

  <subscriber
      for="collective.workspace.interfaces.IHasWorkspace
           zope.lifecycleevent.interfaces.IObjectAddedEvent"
      handler="ploneintranet.userprofile.subscribers.on_membrane_principal_created"
      />

  <subscriber
      for="collective.workspace.interfaces.IHasWorkspace
           zope.lifecycleevent.interfaces.IObjectModifiedEvent"
      handler="ploneintranet.userprofile.subscribers.on_membrane_principal_modified"
      />

  <subscriber
      for="*
           collective.workspace.events.TeamMemberEvent"
      handler="ploneintranet.userprofile.subscribers.on_membrane_principal_modified"
      />

  <subscriber
      for="collective.workspace.interfaces.IHasWorkspace
           zope.lifecycleevent.interfaces.IObjectRemovedEvent"
      handler="ploneintranet.userprofile.subscribers.on_membrane_principal_removed"
      />

  <subscriber
      for="ploneintranet.workspace.workspacefolder.IWorkspaceFolder
           zope.lifecycleevent.interfaces.IObjectAddedEvent"
      handler=".subscribers.workspace_added"
      />

  <subscriber
      for="ploneintranet.workspace.behaviors.subspace.ISubspace
           zope.lifecycleevent.interfaces.IObjectModifiedEvent"
      handler=".subscribers.update_superspace_modified"
      />

  <!-- Subscribe to accepted token event which is fired
       when user clicks on the link in received email-->
  <subscriber
      for="ploneintranet.invitations.events.ITokenAccepted"
      handler=".subscribers.invitation_accepted"
      />

  <!-- Subscribe to user removed event, and delete him
       from all workspaces where he is a member -->
  <subscriber
      for="Products.PluggableAuthService.interfaces.events.IPrincipalDeletedEvent"
      handler=".subscribers.user_deleted_from_site_event"
      />

  <subscriber
      for="ploneintranet.todo.content.todo.ITodo
           zope.lifecycleevent.interfaces.IObjectAddedEvent"
      handler=".subscribers.update_todo_state"
      />

  <subscriber
      for="ploneintranet.todo.content.todo.ITodo
           zope.lifecycleevent.interfaces.IObjectModifiedEvent"
      handler=".subscribers.update_todo_state"
      />

  <subscriber
      for=".case.ICase
           Products.DCWorkflow.interfaces.IAfterTransitionEvent"
      handler=".subscribers.handle_case_workflow_state_changed"
      />

  <adapter
      factory=".adapters.PloneIntranetWorkspace"
      provides="collective.workspace.interfaces.IWorkspace"
      for="ploneintranet.workspace.workspacefolder.IWorkspaceFolder"
      />

  <adapter
      factory=".adapters.PloneIntranetWorkspace"
      provides="ploneintranet.userprofile.interfaces.IMemberGroup"
      for="ploneintranet.workspace.workspacefolder.IWorkspaceFolder"
      />

  <adapter
      factory="ploneintranet.workspace.adapters.WorkspaceLocalRoleAdapter"
      name="workspace_local_role_adapter"
      />

  <adapter
      factory="ploneintranet.workspace.adapters.RemoteAdminLocalRoleAdapter"
      name="remote_admin_role_provider"
      />

  <adapter
      factory=".adapters.EventReaderGroupLocalRoles"
      name="event_reader_role_provider"
      />

  <adapter
      factory=".adapters.EventMaintainerGroupLocalRoles"
      name="event_maintainer_role_provider"
      />

  <adapter
      factory=".adapters.EventCalendarOwnerLocalRoles"
      name="event_calendar_owner_role_provider"
      />

  <adapter
      factory=".adapters.MetroMap"
      provides=".interfaces.IMetroMap"
      for=".case.ICase"
      />

  <adapter
      factory=".adapters.MetroMap"
      provides=".interfaces.IMetroMap"
      for="ploneintranet.workspace.workspacecontainer.IWorkspaceContainer"
      />

  <!-- grouping storage -->
  <adapter
      factory=".adapters.GroupingStorage"
      provides="ploneintranet.workspace.interfaces.IGroupingStorage"
      for="ploneintranet.workspace.interfaces.IGroupingStoragable"
      />

  <subscriber
      for="plone.app.contenttypes.interfaces.IFolder
           zope.lifecycleevent.interfaces.IObjectAddedEvent"
      handler=".subscribers.folder_added_to_workspace"
      />

  <subscriber
      for="plone.dexterity.interfaces.IDexterityContent
           zope.lifecycleevent.interfaces.IObjectAddedEvent"
      handler=".subscribers.content_object_added_to_workspace"
      />

  <subscriber
      for="plone.dexterity.interfaces.IDexterityContent
           zope.lifecycleevent.interfaces.IObjectModifiedEvent"
      handler=".subscribers.content_object_edited_in_workspace"
      />

  <subscriber
      for="plone.dexterity.interfaces.IDexterityContent
           zope.lifecycleevent.interfaces.IObjectRemovedEvent"
      handler=".subscribers.content_object_removed_from_workspace"
      />

  <subscriber
      for="plone.dexterity.interfaces.IDexterityContent
           zope.lifecycleevent.interfaces.IObjectMovedEvent"
      handler=".subscribers.content_object_moved"
      />

  <subscriber
      for="plone.dexterity.interfaces.IDexterityFTI
           zope.lifecycleevent.IObjectModifiedEvent"
      handler=".subscribers.workspace_groupbehavior_toggled"
      />

  <subscriber
      for="plone.dexterity.interfaces.IDexterityContent
           OFS.interfaces.IObjectClonedEvent"
      handler=".subscribers.create_title_from_id"
      />

  <!-- When content within a workspace is modified, a StatusUpdate is created.
       We don't need to listen to the creation of other content types.
  -->
  <subscriber
      for="ploneintranet.microblog.interfaces.IStatusUpdate
           zope.lifecycleevent.interfaces.IObjectAddedEvent"
      handler=".subscribers.update_workspace_modification_date"
      />

  <subscriber
      for="ploneintranet.microblog.interfaces.IStatusUpdate
           zope.lifecycleevent.interfaces.IObjectModifiedEvent"
      handler=".subscribers.update_workspace_modification_date"
      />

  <subscriber
      for="plone.dexterity.interfaces.IDexterityContent
           zope.lifecycleevent.interfaces.IObjectModifiedEvent"
      handler=".subscribers.update_workspace_modification_date"
      />

  <subscriber
      for="*
           ploneintranet.workspace.interfaces.IObjectTrashedEvent"
      handler=".subscribers.reindex_when_trashed"
      />

  <configure zcml:condition="installed collective.auditlog">
    <subscriber
        for="ploneintranet.workspace.interfaces.IWorkspaceCreatedFromTemplateEvent"
        handler="collective.auditlog.handlers.execute_event"
        />
  </configure>

  <interface
      interface="ploneintranet.workspace.interfaces.IWorkspaceCreatedFromTemplateEvent"
      type="plone.contentrules.rule.interfaces.IRuleEventType"
      name="Workspace created from template"
      />

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

  <utility
      name="ploneintranet.workspace.vocabularies.Divisions"
      component=".vocabularies.DivisionsVocabularyFactory"
      />

  <genericsetup:registerProfile
      name="default"
      title="Plone Intranet: -- [Workspace]"
      description="Workspace for PloneIntranet"
      provides="Products.GenericSetup.interfaces.EXTENSION"
      directory="profiles/default"
      post_handler="ploneintranet.workspace.setuphandlers.post_install"
      />

  <genericsetup:registerProfile
      name="uninstall"
      title="Plone Intranet: -- [Workspace uninstall]"
      description="Workspace for PloneIntranet"
      provides="Products.GenericSetup.interfaces.EXTENSION"
      directory="profiles/uninstall"
      post_handler="ploneintranet.workspace.uninstall.uninstall"
      />

</configure>
