==================
 User preferences
==================

There are user specific preferences in the address book:

Set up
======

We need a browser to access the address book:

>>> from icemac.addressbook.testing import Browser
>>> browser = Browser()
>>> browser.login('mgr')
>>> browser.open('http://localhost/++skin++AddressBook/ab')

Location
========

There is a link in the main navigation which currently leads to the
person list preferences:

>>> browser.getLink('Preferences').click()
>>> browser.url
'http://localhost/++skin++AddressBook/ab/++preferences++/ab'
>>> preferences_url = browser.url
>>> browser.getControl('sort direction').displayOptions
['ascending (A-->Z)', 'descending (Z-->A)']

Only accessible when logged in
==============================

The preferences are only accessible for logged-in users. Anonymous
users get redirected to the login screen:

>>> anon = Browser()
>>> anon.open(preferences_url)
>>> print anon.url
http://localhost/++skin++AddressBook/ab/@@loginForm.html?camefrom=http%3A%2F%2Flocalhost%2F%2B%2Bskin%2B%2BAddressBook%2Fab%2F%2B%2Bpreferences%2B%2B%2Fab%2F%40%40index.html

Visitors are able to access the preferences, the form is displayed:

>>> visitor = Browser()
>>> visitor.login('visitor')
>>> visitor.open(preferences_url)
>>> visitor.getControl('sort direction').displayOptions
['ascending (A-->Z)', 'descending (Z-->A)']

Editors are also able to access the preferences:

>>> editor = Browser()
>>> editor.login('editor')
>>> editor.open(preferences_url)
>>> editor.getControl('sort direction').displayOptions
['ascending (A-->Z)', 'descending (Z-->A)']


Each user has his own preferences
=================================

The preferences are personal ones, they are not shared between users:

>>> from icemac.addressbook.testing import get_messages
>>> visitor.getControl('sort direction').displayValue
['ascending (A-->Z)']
>>> visitor.getControl('sort direction').displayValue = ['descending (Z-->A)']
>>> visitor.getControl('Apply').click()
>>> get_messages(visitor)
['Data successfully updated.']
>>> visitor.getLink('Preferences').click()
>>> visitor.getControl('sort direction').displayValue
['descending (Z-->A)']

>>> editor.reload()
>>> editor.getControl('sort direction').displayValue
['ascending (A-->Z)']
