=======================
 Address book overview
=======================

The overview contains a list of all addressbooks and allows to create
new addressbooks.

Set up
======

Remove the address book defined on the layer to start empty:

>>> del layer['rootFolder']['ab']


Overview
========

The overview page requires an authenticated user with the
administrator role:

>>> from icemac.addressbook.testing import Browser, get_messages
>>> browser = Browser()
>>> browser.open('http://localhost/++skin++AddressBook/')
Traceback (most recent call last):
HTTPError: HTTP Error 401: Unauthorized

Before creating the first addressbook the overview page tells that
there are not addressbooks:

>>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
>>> browser.open('http://localhost/++skin++AddressBook/')
>>> print browser.contents
<!DOCTYPE ...
  ...There are no address books created yet, click on "Add address book" to create one...


View Addressbooks
=================

At first we have to create one:

>>> from icemac.addressbook.testing import create_addressbook
>>> _ = create_addressbook('AddressBook', title=u'test book')

The overview page contains a list of the existing addressbooks
together with the number of entries inside:

>>> browser.open('http://localhost/++skin++AddressBook/')
>>> print browser.contents
<!DOCTYPE ...
  <ul class="bullet">
    <li>
      <a href="http://localhost/++skin++AddressBook/AddressBook">test book</a>
      (0 items)
      <a href="http://localhost/++skin++AddressBook/AddressBook/@@delete_address_book.html">Delete</a>
   </li>
  </ul>
  ...

This view only displays addressbooks, when another object is in the
root folder it is not listed. (As there is no user interface to add an
object, I add it directly to the root folder.):

>>> from zope.container.btree import BTreeContainer
>>> layer['rootFolder']['btree'] = BTreeContainer()
>>> browser.open('http://localhost/++skin++AddressBook/')
>>> print browser.contents
<!DOCTYPE ...
<ul class="bullet">
  <li>
    <a href="http://localhost/++skin++AddressBook/AddressBook">test book</a>
    (0 items)
    <a href="http://localhost/++skin++AddressBook/AddressBook/@@delete_address_book.html">Delete</a>
  </li>
</ul>...

After creating a person one entry is displayed:

>>> from icemac.addressbook.testing import create_person
>>> ab = create_addressbook('ab2', title=u'ab w/ content')
>>> create_person(ab, ab, u'Tester', return_obj=False)
>>> browser.reload()
>>> print browser.contents
<!DOCTYPE ...
<ul class="bullet">
   <li>
     <a href="http://localhost/++skin++AddressBook/AddressBook">test book</a>        (0 items)
     <a href="http://localhost/++skin++AddressBook/AddressBook/@@delete_address_book.html">Delete</a>
   </li>
   <li>
     <a href="http://localhost/++skin++AddressBook/ab2">ab w/ content</a>
     (1 item)
     <a href="http://localhost/++skin++AddressBook/ab2/@@delete_address_book.html">Delete</a>
   </li>
</ul>...

>>> dummy = create_person(ab, ab, u'Tester2')
>>> browser.reload()
>>> print browser.contents
<!DOCTYPE ...
<ul class="bullet">
   <li>
     <a href="http://localhost/++skin++AddressBook/AddressBook">test book</a>
     (0 items)
     <a href="http://localhost/++skin++AddressBook/AddressBook/@@delete_address_book.html">Delete</a>
   </li>
   <li>
     <a href="http://localhost/++skin++AddressBook/ab2">ab w/ content</a>
     (2 items)
     <a href="http://localhost/++skin++AddressBook/ab2/@@delete_address_book.html">Delete</a>
  </li>
</ul>...


Delete address book
===================

The Administrator is able to delete the whole address book.  But
Editors and visitors are not allowed to do so, even they know the URL.

Set up
------

Users are a bit harder to delete, so we add them here to show they can
get deleted as well:

>>> from icemac.addressbook.testing import create_user
>>> create_user(ab, ab, u'Hans', u'User', u'hans@user.de', u'asdf', ['Visitor'])
>>> create_user(ab, ab, u'Kurt', u'Utzr', u'kurt@utzr.ch', u'asdf', ['Editor'])


Editor
------

>>> delete_address_book_url = (
...     'http://localhost/++skin++AddressBook/ab2/@@delete_address_book.html')
>>> editor_browser = Browser()
>>> editor_browser.addHeader('Authorization', 'Basic editor:editor')
>>> editor_browser.open(delete_address_book_url)
Traceback (most recent call last):
HTTPError: HTTP Error 403: Forbidden

Visitor
-------

>>> visitor_browser = Browser()
>>> visitor_browser.addHeader('Authorization', 'Basic visitor:visitor')
>>> visitor_browser.open(delete_address_book_url)
Traceback (most recent call last):
HTTPError: HTTP Error 403: Forbidden


Administrator
-------------

The Adminstrator has to select the `Delete` link. Then an `are you
sure` form is displayed:

>>> browser.getLink('Delete', index=1).click()
>>> browser.url
'http://localhost/++skin++AddressBook/ab2/@@delete_address_book.html'

When the adminstrator decides not to delete the address book he is led
back to the overview of all address books:

>>> browser.getControl('No, cancel').click()
>>> get_messages(browser)
['Deletion canceled.']
>>> browser.url
'http://localhost/++skin++AddressBook'

When he decides to delete the address book he is led back to the
overview as well:

>>> browser.getLink('Delete', index=1).click()
>>> browser.url
'http://localhost/++skin++AddressBook/ab2/@@delete_address_book.html'
>>> browser.getControl('Yes').click()
>>> get_messages(browser)
['"ab w/ content" deleted.']
>>> browser.url
'http://localhost/++skin++AddressBook'
>>> print browser.contents
<!DOCTYPE ...
  <ul class="bullet">
    <li>
      <a href="http://localhost/++skin++AddressBook/AddressBook">test book</a>
      (0 items)
      <a href="http://localhost/++skin++AddressBook/AddressBook/@@delete_address_book.html">Delete</a>
    </li>
  </ul>...
