<?xml version="1.0"?>
<configure xmlns="http://namespaces.zope.org/zope">

  <include file="security.zcml" />

  <!-- Adapters -->

  <class class="schooltool.app.overlay.CalendarOverlayInfo">
    <implements
        interface="zope.annotation.interfaces.IAttributeAnnotatable" />
  </class>

  <adapter
      for="schooltool.app.overlay.ICalendarOverlayInfo"
      provides=".interfaces.IShowTimetables"
      factory=".app.ShowTimetables"
      trusted="true"
      />

  <class class=".app.ShowTimetables">
    <require
        permission="schooltool.view"
        interface=".interfaces.IShowTimetables" />
    <require
        permission="schooltool.view"
        set_schema=".interfaces.IShowTimetables" />
  </class>

  <adapter
      for=".interfaces.IHaveCalendar"
      provides=".interfaces.ISchoolToolCalendar"
      factory=".cal.getCalendar"
      trusted="true"
      />

  <adapter
      for=".interfaces.ISchoolToolCalendar"
      provides=".interfaces.IWriteCalendar"
      factory=".cal.WriteCalendar"
      />

  <adapter
      for=".interfaces.ISchoolToolApplication"
      provides=".interfaces.IApplicationPreferences"
      factory=".app.getApplicationPreferences"
      trusted="true"
      />

  <class class=".cal.WriteCalendar">
    <allow interface=".interfaces.IWriteCalendar" />
  </class>

  <adapter
      for="None"
      provides=".interfaces.ISchoolToolApplication"
      factory=".app.getSchoolToolApplication" />

  <!-- Utilities -->

  <class class=".security.SchoolToolAuthenticationUtility">
    <require
        permission="zope.ManageServices"
        interface="zope.app.security.interfaces.IAuthentication"
        />
  </class>

  <utility
      provides="schooltool.relationship.interfaces.IRelationshipSchema"
      component=".relationships.Instruction"
      name="http://schooltool.org/ns/instruction" />

  <utility
      provides="schooltool.relationship.interfaces.IRelationshipSchema"
      component=".relationships.CourseSections"
      name="http://schooltool.org/ns/coursesections" />

  <utility
      provides="schooltool.relationship.interfaces.IRelationshipSchema"
      component=".membership.Membership"
      name="http://schooltool.org/ns/membership" />

  <utility
      provides="schooltool.relationship.uri.IURIObject"
      component=".relationships.URIInstructor"
      name="http://schooltool.org/ns/instruction/instructor" />

  <utility
      provides="schooltool.relationship.uri.IURIObject"
      component=".relationships.URISection"
      name="http://schooltool.org/ns/instruction/section" />

  <utility
      provides="schooltool.relationship.uri.IURIObject"
      component=".relationships.URICourse"
      name="http://schooltool.org/ns/coursesections/course" />

  <utility
      provides="schooltool.relationship.uri.IURIObject"
      component=".relationships.URISectionOfCourse"
      name="http://schooltool.org/ns/coursesections/section" />

  <utility
      provides="schooltool.relationship.uri.IURIObject"
      component=".membership.URIMember"
      name="http://schooltool.org/ns/membership/member" />

  <utility
      provides="schooltool.relationship.uri.IURIObject"
      component=".membership.URIGroup"
      name="http://schooltool.org/ns/membership/group" />

  <utility
      provides="schooltool.app.interfaces.ISchoolToolInitializationUtility"
      factory=".app.SchoolToolInitializationUtility" />

  <!-- Event Subscribers -->

  <subscriber
      for="schooltool.app.interfaces.ISchoolToolApplication zope.app.container.interfaces.IObjectAddedEvent"
      handler=".security.authSetUpSubscriber"
      />

  <subscriber
      for="schooltool.relationship.interfaces.IBeforeRelationshipEvent"
      handler=".membership.enforceMembershipConstraints"
      />

  <subscriber
      for="schooltool.relationship.interfaces.IBeforeRelationshipEvent"
      handler=".relationships.enforceInstructionConstraints"
    />

  <subscriber
      for="schooltool.relationship.interfaces.IRelationshipAddedEvent"
      handler=".relationships.updateStudentCalendars"
      />

  <subscriber
      for="schooltool.relationship.interfaces.IRelationshipRemovedEvent"
      handler=".relationships.updateStudentCalendars"
      />

  <subscriber
      for="schooltool.relationship.interfaces.IRelationshipAddedEvent"
      handler=".relationships.updateInstructorCalendars"
      />

  <subscriber
      for="schooltool.relationship.interfaces.IRelationshipRemovedEvent"
      handler=".relationships.updateInstructorCalendars"
      />

  <subscriber
      for="zope.app.container.interfaces.IObjectRemovedEvent"
      handler=".overlay.unrelateCalendarOnDeletion"
      />

  <subscriber
      for="zope.app.container.interfaces.IObjectRemovedEvent"
      handler=".cal.clearCalendarOnDeletion" />

  <subscriber
      for="schooltool.app.interfaces.IApplicationInitializationEvent"
      handler=".main.initializeSchoolToolPlugins" />

  <subscriber
      for="schooltool.app.interfaces.IApplicationStartUpEvent"
      handler=".main.startSchoolToolPlugins" />

  <!-- Timetables for content components -->
  <class class="schooltool.app.app.SchoolToolApplication">
    <implements interface="schooltool.timetable.interfaces.IHaveTimetables" />
  </class>

  <class class="schooltool.person.person.Person">
    <implements interface="schooltool.timetable.interfaces.IHaveTimetables" />
  </class>

  <class class="schooltool.group.group.Group">
    <implements interface="schooltool.timetable.interfaces.IHaveTimetables" />
  </class>

  <class class="schooltool.resource.resource.BaseResource">
    <implements interface="schooltool.timetable.interfaces.IHaveTimetables" />
  </class>
  

  <!-- Core and Domain content objects -->

  <interface
      interface=".interfaces.ISchoolToolApplication"
      type="zope.app.content.interfaces.IContentType"
      />

  <class class=".app.SchoolToolApplication">
    <implements interface="schooltool.app.interfaces.IHaveCalendar" />
    <allow interface=".interfaces.ISchoolToolApplication" />
    <allow attributes="getSiteManager" />
  </class>

  <class class=".cal.Calendar">
    <require permission="schooltool.view"
             interface="schooltool.calendar.interfaces.ICalendar"
             attributes="title __cmp__" />
    <require permission="schooltool.edit"
             attributes="addEvent" />
    <require permission="schooltool.edit"
             attributes="clear removeEvent" />
  </class>

  <class class=".cal.CalendarEvent">
    <require permission="schooltool.view"
             interface="schooltool.calendar.interfaces.ICalendarEvent"
             attributes="resources" />
    <require permission="schooltool.edit"
             set_schema="schooltool.calendar.interfaces.ICalendarEvent"
             attributes="bookResource unbookResource"
             set_attributes="__parent__" />
  </class>

  <class class=".app.ApplicationPreferences">
    <require permission="zope.Public"
             interface=".interfaces.IApplicationPreferences" />
    <require permission="schooltool.edit"
             set_schema=".interfaces.IApplicationPreferences" />
  </class>

  <class class="schooltool.relationship.relationship.LinkSet">
    <allow
       interface="schooltool.relationship.interfaces.IRelationshipLinks"
       />
  </class>

  <class class="schooltool.relationship.relationship.Link">
    <allow
       interface="schooltool.relationship.interfaces.IRelationshipLink"
       />
  </class>

  <class class="schooltool.relationship.uri.URIObject">
    <allow
       interface="schooltool.relationship.uri.IURIObject"
       />
  </class>

  <!-- Views -->

  <include package=".browser" />
  <include package=".help" />

  <!-- XXX It feels wrong to tweak permissions of objects in a sibling. -->

  <class class="schooltool.calendar.mixins.ExpandedCalendarEvent">
    <require permission="schooltool.view"
             interface="schooltool.calendar.interfaces.IExpandedCalendarEvent"
             attributes="resources"
             />
  </class>

  <class class="schooltool.calendar.recurrent.DailyRecurrenceRule">
    <require permission="zope.Public"
             interface="schooltool.calendar.interfaces.IDailyRecurrenceRule" />
  </class>

  <class class="schooltool.calendar.recurrent.WeeklyRecurrenceRule">
    <require permission="zope.Public"
             interface="schooltool.calendar.interfaces.IWeeklyRecurrenceRule"
             />
  </class>

  <class class="schooltool.calendar.recurrent.MonthlyRecurrenceRule">
    <require permission="zope.Public"
             interface="schooltool.calendar.interfaces.IMonthlyRecurrenceRule"
             />
  </class>

  <class class="schooltool.calendar.recurrent.YearlyRecurrenceRule">
    <require permission="zope.Public"
             interface="schooltool.calendar.interfaces.IYearlyRecurrenceRule"
             />
  </class>

  <class class="schooltool.calendar.simple.ImmutableCalendar">
    <require permission="zope.Public"
             interface="schooltool.calendar.interfaces.ICalendar" />
  </class>

  <adapter
      for="schooltool.calendar.interfaces.IEditCalendar"
      factory=".cal.WriteCalendar"
      provides=".interfaces.IWriteCalendar" />

  <class
      class="schooltool.app.overlay.BoundOverlaidCalendarsProperty">
    <allow attributes="__iter__ __contains__" />
    <require
        permission="schooltool.view"
        attributes="add remove" />
  </class>

  <class class="schooltool.app.overlay.CalendarOverlayInfo">
    <require
        permission="schooltool.view"
        interface="schooltool.app.overlay.ICalendarOverlayInfo"/>
    <require
        permission="schooltool.editCalendarOverlays"
        set_schema="schooltool.app.overlay.ICalendarOverlayInfo"/>
  </class>

  <adapter
      factory=".app.getApplicationControl"
      trusted="true"
      />

  <adapterTraverserPlugin
      for="schooltool.app.interfaces.ISchoolToolApplication"
      layer="zope.publisher.interfaces.http.IHTTPRequest"
      name="control"
      adapter="zope.app.applicationcontrol.interfaces.IApplicationControl"
      permission="schooltool.edit"
      />

  <!-- Documentation -->

  <configure
      xmlns:zcml="http://namespaces.zope.org/zcml"
      xmlns:apidoc="http://namespaces.zope.org/apidoc"
      zcml:condition="have apidoc">

    <apidoc:bookchapter
        id="schooltool"
        title="SchoolTool"
        doc_path="README.txt" />

    <!-- Security -->
    <apidoc:bookchapter
        id="security"
        title="Security (General)"
        parent="schooltool"
        doc_path="security.txt" />

    <!-- Calendar -->
    <configure package="schooltool.calendar">
      <apidoc:bookchapter
          id="calendar"
          title="Calendar"
          parent="schooltool"
          doc_path="README.txt" />
    </configure>

    <apidoc:bookchapter
        id="booking"
        title="Booking Resources"
        parent="schooltool/calendar"
        doc_path="booking.txt" />

  </configure>

  <utility
      xmlns:zcml="http://namespaces.zope.org/zcml"
      zcml:condition="not-have authentication"
      factory=".security.PersonContainerAuthenticationPlugin"
      provides=".interfaces.ISchoolToolAuthenticationPlugin" />

  <!-- general utilities -->
  <!-- XXX: move the code to schooltool.app too -->
  <utility
      factory="schooltool.term.term.DateManagerUtility" />

  <!-- Temporary refugees from rest configure.zcml -->

  <view
      for="zope.interface.Interface"
      type="zope.publisher.interfaces.http.IHTTPRequest"
      provides="zope.publisher.interfaces.http.IHTTPPublisher"
      factory="schooltool.traverser.traverser.PluggableTraverser"
      permission="zope.Public"
      />

  <view
      for=".interfaces.ISchoolToolApplication"
      type="zope.publisher.interfaces.http.IHTTPRequest"
      provides="zope.publisher.interfaces.http.IHTTPPublisher"
      factory="schooltool.traverser.traverser.PluggableTraverser"
      permission="zope.Public"
      />

  <view
      for=".interfaces.ISchoolToolCalendar"
      type="zope.publisher.interfaces.http.IHTTPRequest"
      provides="zope.publisher.interfaces.http.IHTTPPublisher"
      factory="schooltool.traverser.traverser.PluggableTraverser"
      permission="zope.Public"
      />

  <adapter
      for="zope.app.container.interfaces.IReadContainer
           zope.publisher.interfaces.http.IHTTPRequest"
      provides="schooltool.traverser.interfaces.ITraverserPlugin"
      factory="zope.app.http.traversal.ContainerTraverser"
      permission="zope.Public"
      />

  <adapterTraverserPlugin
      for="schooltool.app.interfaces.IHaveCalendar"
      layer="zope.publisher.interfaces.http.IHTTPRequest"
      name="calendar.vfb"
      adapter="schooltool.app.interfaces.ISchoolToolCalendar"
      permission="zope.Public"
      />

  <adapterTraverserPlugin
      for="schooltool.app.interfaces.IHaveCalendar"
      layer="zope.publisher.interfaces.http.IHTTPRequest"
      name="calendar.ics"
      adapter="schooltool.app.interfaces.ISchoolToolCalendar"
      permission="zope.Public"
      />

  <adapterTraverserPlugin
      for="schooltool.app.interfaces.IHaveCalendar"
      layer="zope.publisher.interfaces.http.IHTTPRequest"
      name="calendar"
      adapter="schooltool.app.interfaces.ISchoolToolCalendar"
      permission="zope.Public"
      />

  <!-- the following are used by PUT requests on the normal web server -->
  <nullTraverserPlugin
      for="schooltool.app.interfaces.ISchoolToolCalendar"
      layer="zope.publisher.interfaces.http.IHTTPRequest"
      name="calendar.ics"
      permission="zope.Public"
      />

  <nullTraverserPlugin
      for="schooltool.app.interfaces.ISchoolToolCalendar"
      layer="zope.publisher.interfaces.http.IHTTPRequest"
      name="calendar.vfb"
      permission="zope.Public"
      />

  <view
      for="schooltool.app.interfaces.ISchoolToolCalendar"
      name="GET"
      factory=".browser.app.HTTPCalendarView"
      type="zope.publisher.interfaces.http.IHTTPRequest"
      permission="zope.Public"
      />

  <view
      for="schooltool.app.interfaces.ISchoolToolCalendar"
      name="PUT"
      factory=".browser.app.HTTPCalendarView"
      type="zope.publisher.interfaces.http.IHTTPRequest"
      permission="zope.Public"
      />

</configure>
