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

  <!-- Category Vocabulary -->
  <utility
      provides="zope.schema.interfaces.IVocabularyFactory"
      component="schooltool.gradebook.category.CategoryVocabulary"
      name="schooltool.gradebook.categories"
      />
  <adapter
      for="schooltool.app.interfaces.ISchoolToolApplication"
      factory=".gradebook.GradebookInit"
      name="schooltool.gradebook" />

  <!-- Activity Adapters -->
  <adapter
      for="schooltool.course.interfaces.ISection"
      provides=".interfaces.IActivities"
      factory=".activity.getSectionActivities"
      trusted="true"
      />

  <!-- Activity Content and Security -->
  <class class=".activity.Activities">
    <require
        permission="schooltool.view"
        interface=".interfaces.IActivities"
        />
    <require
        permission="schooltool.edit"
        set_schema=".interfaces.IActivities"
        />
  </class>
  <class class=".activity.Worksheet">
    <allow interface="zope.interface.common.mapping.IReadMapping" />
    <require
        permission="schooltool.view"
        attributes="keys __iter__ values items __len__
                    title getCategoryWeights"
        />
    <require
        permission="schooltool.edit"
        interface="zope.interface.common.mapping.IWriteMapping"
        set_schema=".interfaces.IWorksheet"
        attributes="changePosition setCategoryWeight"
        />
  </class>
  <class class=".activity.Activity">
    <allow interface="zope.interface.common.mapping.IReadMapping" />
    <require
        permission="schooltool.view"
        attributes="keys __iter__ values items __len__
                    addBase removeBase
                    title description category scoresystem date"
        />
    <require
        permission="schooltool.edit"
        interface="zope.interface.common.mapping.IWriteMapping"
        set_schema=".interfaces.IActivity"
        />
  </class>
  <class class=".activity.LinkedActivity">
    <allow interface="zope.interface.common.mapping.IReadMapping" />
    <require
        permission="schooltool.view"
        attributes="keys __iter__ values items __len__
                    addBase removeBase
                    source external_activity_id title description category
		    scoresystem date points getExternalActivity"
        />
    <require
        permission="schooltool.edit"
        interface="zope.interface.common.mapping.IWriteMapping"
        set_schema=".interfaces.ILinkedActivity"
        />
  </class>

  <!-- External Activities Vocabulary -->

  <utility
      provides="zope.schema.interfaces.IVocabularyFactory"
      factory="schooltool.gradebook.activity.ExternalActivitiesVocabulary"
      name="schooltool.gradebook.external_activities"
      />

  <!-- Gradebook Adapter -->
  <class class=".gradebook.Gradebook">
    <require
        permission="schooltool.view"
        interface=".interfaces.IReadGradebook" />
    <require
        permission="schooltool.edit"
        interface=".interfaces.IEditGradebook" />
  </class>

  <!-- This adapter locates itself. -->
  <adapter
      for=".interfaces.IWorksheet"
      provides=".interfaces.IGradebook"
      factory=".gradebook.Gradebook"
      trusted="true"
      />

  <!-- MyGrades Adapter -->
  <class class=".gradebook.MyGrades">
    <require
        permission="schooltool.view"
        interface=".interfaces.IMyGrades" />
  </class>

  <!-- This adapter locates itself. -->
  <adapter
      for=".interfaces.IWorksheet"
      provides=".interfaces.IMyGrades"
      factory=".gradebook.MyGrades"
      trusted="true"
      />

  <!-- Adapters to get to a section. -->
  <adapter
      for=".interfaces.IGradebook"
      provides="schooltool.course.interfaces.ISection"
      factory=".gradebook.getGradebookSection"
      />
  <adapter
      for=".interfaces.IWorksheet"
      provides="schooltool.course.interfaces.ISection"
      factory=".gradebook.getWorksheetSection"
      />

  <!-- Pluggable traverser plugins for HTTP paths -->
  <adapterTraverserPlugin
      for="schooltool.course.interfaces.ISection"
      layer="zope.publisher.interfaces.http.IHTTPRequest"
      name="activities"
      adapter="schooltool.gradebook.interfaces.IActivities"
      />

  <!-- special traversal adapter for traversing from worksheet to gradebook -->
  <adapter
      for=".interfaces.IWorksheet
           zope.publisher.interfaces.http.IHTTPRequest"
      provides="zope.publisher.interfaces.IPublishTraverse"
      factory=".gradebook.WorksheetGradebookTraverser" />

  <!-- apidoc help setup -->
  <configure
      xmlns:zcml="http://namespaces.zope.org/zcml"
      xmlns:apidoc="http://namespaces.zope.org/apidoc"
      zcml:condition="have apidoc">
    <apidoc:bookchapter
        id="gradebook"
        title="Gradebook API"
        parent="schooltool"
        doc_path="README.txt" />
  </configure>

  <include package=".browser" />

  <!-- security settings -->
  <security:setting
      key="administration_can_grade_students"
      text="Administration can grade students"
      default="False" />
  <security:crowd
      name="grade_editors"
      factory=".gradebook.GradebookEditorsCrowd" />
  <security:allow
      interface="schooltool.gradebook.interfaces.IGradebook"
      permission="schooltool.view"
      crowds="administration section_instructors" />
  <security:allow
      interface="schooltool.gradebook.interfaces.IGradebook"
      permission="schooltool.edit"
      crowds="section_instructors grade_editors" />

  <adapter factory=".gradebook.GradebookAppStartup"
           name="gradebook_startup_init" />

</configure>
