==============
 Address book
==============

Person data (name, address, ...) is stored inside an address book.

>>> from zope.testbrowser.testing import Browser
>>> browser = Browser()

Create an address book
======================

As only managers are allowed to create address books we have to login:

>>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
>>> browser.open('http://localhost/++skin++AddressBook/')

On the start page there is a link to add an address book:

>>> browser.getLink('address book').click()
>>> browser.getControl('title').value = 'test book'
>>> browser.getControl('Add').click()
>>> address_book_url = browser.url
>>> address_book_url
'http://localhost/++skin++AddressBook/AddressBook'


Edit address book's data
========================

The manager can also edit the address book's data. The edit form shows
the formerly entred data:

>>> browser.getLink('Edit address book').click()
>>> browser.url
'http://localhost/++skin++AddressBook/AddressBook/@@edit.html'
>>> edit_address_book_url = browser.url
>>> browser.getControl('title').value
'test book'
>>> browser.getControl('title').value = 'ftest book'
>>> browser.getControl('Apply').click()

The edit form submits to itself and shows the stored data:

>>> browser.getControl('title').value
'ftest book'

Person list
===========

Initially there are no persons existing:

>>> browser.getLink('Person list').click()
>>> print browser.contents
<!DOCTYPE...
There are no persons entered yet, click on "Add person" to create one...

There is also an add link in the add menu to add a person:

>>> browser.getLink('person')
<Link text='person'
      url='http://localhost/++skin++AddressBook/AddressBook/@@addPerson.html'>


Editors
=======

Editors can add new persons:

>>> editor_browser = Browser()
>>> editor_browser.addHeader('Authorization', 'Basic editor:editor')
>>> editor_browser.open(address_book_url)
>>> editor_browser.getLink('person').click()

But there is no link to edit the address book's data (title)
because the editor is not allowed to do so:

>>> editor_browser.goBack()
>>> editor_browser.getLink('Edit address book')
Traceback (most recent call last):
LinkNotFoundError

Even opening the URL is not possible:

>>> editor_browser.open(edit_address_book_url)
Traceback (most recent call last):
HTTPError: HTTP Error 403: Forbidden


Visitors
========

Visitors can only visit data but are not allowed to change anything:

>>> visitor_browser = Browser()
>>> visitor_browser.addHeader('Authorization', 'Basic visitor:visitor')
>>> visitor_browser.open(address_book_url)
>>> visitor_browser.getLink('person')
Traceback (most recent call last):
LinkNotFoundError

There is also no link to edit the address book's data (title)
because the visitor is not allowed to do so:

>>> visitor_browser.getLink('Edit address book')
Traceback (most recent call last):
LinkNotFoundError

Even opening the URL is not possible:

>>> visitor_browser.open(edit_address_book_url)
Traceback (most recent call last):
HTTPError: HTTP Error 403: Forbidden


Delete all persons in addressbook
=================================

The Administrator is able to delete all persons in the address book on
the edit form. Users are not deleted because the are referenced as a
safty belt so the current user does not delete his credencials.

Editors and visitors are not allowed to do so, even they know the URL.

Editor
------

>>> delete_address_book_url = address_book_url + '/@@delete_content.html'
>>> editor_browser.open(delete_address_book_url)
Traceback (most recent call last):
HTTPError: HTTP Error 403: Forbidden

Visitor
-------

>>> visitor_browser.open(delete_address_book_url)
Traceback (most recent call last):
HTTPError: HTTP Error 403: Forbidden


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

Make sure there are some persons (with adresses) and some users in the
address book:

>>> from icemac.addressbook.testing import (create_person, create_user,
...     create_postal_address)
>>> ab = getRootFolder()['AddressBook']
>>> create_person(ab, ab, last_name=u'Tester', return_obj=False)
>>> create_person(ab, ab, last_name=u'Tester 2', return_obj=False)
>>> 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'])
>>> t3 = create_person(ab, ab, last_name=u'Tester 3')
>>> create_postal_address(ab, t3, city=u'Hettstedt', return_obj=False)

To delete all persons in the address book, the Adminstrator has to
open the `edit address book` form and select the `Delete all persons
in address book` button there. An `are you sure` form is displayed:

>>> browser.getLink('Edit address book').click()
>>> browser.getControl('Delete all persons in address book').click()
>>> browser.url
'http://localhost/++skin++AddressBook/AddressBook/@@delete_content.html'

When the adminstrator decides not to delete the persons he is led back
to the address book's edit form:

>>> print browser.contents
<!DOCTYPE ...
      <h1>Do you really want to delete all persons in this address book?</h1>...
                  <span>number of persons</span>...
    <span id="form-widgets-count"
          class="text-widget int-field">5</span>...

>>> browser.getControl('No, cancel').click()
>>> browser.url == edit_address_book_url
True

When he decides to delete all persons he is led back to then person
list where only the users are still shown:

>>> browser.getControl('Delete all persons in address book').click()
>>> browser.handleErrors = False
>>> browser.getControl('Yes, delete').click()
>>> browser.url
'http://localhost/++skin++AddressBook/AddressBook'
>>> print browser.contents
<!DOCTYPE ...
  <h2>Persons</h2>
  <ul>
    <li>
      <a href="http://localhost/++skin++AddressBook/AddressBook/Person-3">User, Hans</a>
    </li>
    <li>
      <a href="http://localhost/++skin++AddressBook/AddressBook/Person-4">Utzr, Kurt</a>
    </li>
  </ul>...
