<commit_before>.. _integrator_functionalities:

Functionalities
===============

In c2cgeoportal we have a functionalities system to manage generic
functionality.

They are define at four levels:

 - anonymous users (define in ``anonymous_functionalities`` in ``config.yaml.in``)
 - registered users (define in ``registered_functionalities`` in ``config.yaml.in``)
 - role (linked functionalities to the Role in the admin interface)
 - user (linked functionalities to the User in the admin interface)

Each level overwrite the functionalities of his previous level.

Configuration
-------------

In the ``config.yaml.in`` we have various variable that's used to configur the
functionalities:

``formalchemy_available_functionalities``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Define the functionality that we have in the combobox of the admin interface.

``anonymous_functionalities``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
As previously explain the functionality used by the anonymous users.

``registered_functionalities``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
As previously explain the functionality used by the registered users.

``webclient_string_functionalities``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
List of functionalities available in the ``viewer.js``, in the
``FUNCTIONALITY`` variable as a unique value.

For example we can have::

    var FUNCTIONALITY = {"default_basemap": "plan"};

``webclient_array_functionalities``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
List of functionalities available in the ``viewer.js``, in the
``FUNCTIONALITIES`` variable as an array.

For example we can have::

    var FUNCTIONALITIES = {"default_basemap": ["plan", "ortho"]};

<commit_msg>[doc] improved functionality chapter<commit_after>.. _integrator_functionalities:

Functionality
=============

c2cgeoportal provides a system for managing *functionality* in a generic way.
Functionality can be associated to users, and elements of the user interface
can change based on the user's permissions.

Functionality can be associated to users through different ways:

1. The functionality for anonymous users is defined through the
   ``anonymous_functionalities`` variable in the ``config.yaml.in``
   configuration file.
2. The functionality for authenticated users is defined through the
   ``registered_functionalities`` variable in the ``config.yaml.in``
   configuration file.
3. The functionality for a specific role is defined in the database through the
   admin interface.
4. The functionality for a specific user is defined in the database through the
   admin interface.

Each level overwrites the previous levels. For example, if the user is
authenticated and has associated functionality in the ``user`` database table
then the ``anonymous_functionalities`` and ``registered_functionalities``
configuration variables, and any functionality associated with his role, will be
ignored.

Configuration
-------------

The ``config.yaml.in`` file includes variables for managing *functionality*.

``admin_interface``/``available_functionalities``
    A list of strings representating features that can be added to the
    ``functionality`` database table through the admin interface.

    For example::

        admin_interface:
            available_functionalities:
            - default_basemap
            - print_template
            - mapserver_substitution


``functionalities``/``anonymous``
    The functionality accessible to anonymous users. This is a list of
    key/value pairs, whose values are either arrays, or scalars.

    For example::

        functionalities:
            anonymous:
                print_template:
                - 1 A4 portrait
                - 2 A3 landscape
                default_basemap: plan

    In this example anonymous users can print maps using the ``1 A4 portrait``
    and ``2 A3 landscape`` layouts only. And their default base layer is the
    ``plan`` layer.

``functionalities``/``registered_functionalities``
    The functionality accessible to all authenticated users. This is a list of
    key/value pairs, of the same form of ``anonymous_functionalities``.

``functionalities``/``webclient_string``

    The functionality that is made available to Mako templates (e.g.
    ``viewer.js``) through the ``functionality`` template variable as
    a dictionary whose values are scalars.

    For example::

        functionalities:
            webclient_string:
            - default_basemap

    In this case, and if the user can effectively use the
    ``default_basemap``/``plan`` functionality, then the value of the
    ``functionality`` template variable will be a dict with one key/value pair:
    ``"default_basemap"``/``"plan"``.

    .. note::

        ``viewer.js`` actually creates a js variable named ``FUNCTIONALITY``
        from the ``functionality`` dict. For example::

            var FUNCTIONALITY = {"default_basemap": "plan"};

``functionalities``/``webclient_array``
    The functionality that is made available to Mako templates (e.g.
    ``viewer.js``) through the ``functionalities`` template variable as
    a dictionary whose values are scalars.

    For example::

        functionalities:
            webclient_array:
            - default_basemap

    In this case, and if the user can use both ``default_basemap``/``plan`` and
    ``default_basemap``/``ortho``, then the value of the ``functionalities``
    template variable will be a dict with one key/value pair:
    ``"default_basemap"``/``["plan","ortho"]``.

    .. note::

        ``viewer.js`` actually creates a js variable named ``FUNCTIONALITIES``
        from the ``functionalities`` dict. For example::

            var FUNCTIONALITIES = {"default_basemap": ["plan", "ortho"]};

{'fraction_non_alphanumeric': 0.11966410076976906, 'fraction_numerical': 0.00244926522043387, 'mean_word_length': 3.8285472972972974, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5609419', 'n_tokens_mistral': 1480, 'n_tokens_neox': 1397, 'n_words': 589}