.. include:: /Includes.rst.txt .. _extending-navigation-access: ===================== Navigation and Access ===================== A package adds its pages to the navigation in the left sidebar. Every route, API operation and navigation entry names the actors that may use it; a request without such a declaration is denied. Navigation entries ================== Implement ``NavigationEntries`` and return the entries. The navigation of the attendance package: .. code-block:: php use WebVision\Adsum\Core\Shared\Navigation\NavigationEntries; use WebVision\Adsum\Core\Shared\Navigation\NavigationEntry; final readonly class AttendanceNavigation implements NavigationEntries { public function entries(): iterable { yield new NavigationEntry('myDays', 'myTime', 5, 'nav.myDays', 'clock', 'app_my_days', ['self']); yield new NavigationEntry('teamDays', 'team', 30, 'nav.teamDays', 'list-checks', 'app_team_days', ['managerInScope', 'hr']); } } The constructor arguments of ``NavigationEntry`` are, in this order: ``key`` A unique key of the entry. ``group`` The group the entry belongs to. ``order`` The position in the group. Lower numbers come first; entries with the same number are sorted by key. ``labelKey`` The translation key of the label, for example ``nav.myDays`` (see :ref:`extending-translations-icons`). ``icon`` The name of an icon in the icon set of a package (see :ref:`extending-translations-icons`). ``route`` The route name of the page. ``access`` The actors that see the entry. A reader sees an entry only if admitted by its ``access``, and a group only if it has a visible entry. Give an entry the same access as its page. Groups ====== The groups are fixed and shown in this order: - ``home``, shown as :guilabel:`Overview` - ``myTime``, shown as :guilabel:`My time` - ``team``, shown as :guilabel:`Team` - ``organisation``, shown as :guilabel:`Organisation` - ``administration``, shown as :guilabel:`Administration` Choose the group by the audience of the page. Top bar items ============= A package can add custom elements to the top bar, left of the notification bell, such as the clock of the attendance package. Implement ``TopBarItems`` and return the tag names: .. code-block:: php use WebVision\Adsum\Core\Shared\Navigation\TopBarItems; final readonly class ClockTopBar implements TopBarItems { public function itemsFor(User $reader, CompanyId $companyId): iterable { yield 'tt-clock'; } } The class decides whether its elements apply to the reader in that company. Define the custom element in the entry module of the package (see :ref:`extending-frontend`). Actors ====== These actors are valid in ``#[Access]``, in ``x-access`` of the API contract and in navigation entries: ``public`` Anyone, without login. ``anyEmployee`` Any logged-in employee of the company. ``self`` A logged-in user acting on their own data. ``participant``, ``managerInScope``, ``approver`` A logged-in user related to the subject: a participant of the record, a manager of the person in their reporting line, or an approver of the request. The action checks the relationship in a voter or a scoped query. Derived actors of packages, such as ``projectManager`` Registered with ``#[AsAccessActor(name: 'projectManager', package: 'adsum-projects')]`` on the class that decides it from current data. A name may be registered once and must not be a core actor; an actor no installed package registers is refused. Core operations use core actors only. ``hr``, ``admin`` Holders of the role in the company of the request. The role is checked before the action runs. The ``#[Access]`` attribute =========================== Every controller action declares who may call it with ``#[Access]``: .. code-block:: php use WebVision\Adsum\Core\Shared\Security\Access; #[Route('/team/roster', name: 'app_roster', methods: ['GET'])] #[Access('managerInScope', 'hr')] public function roster(): Response { // ... } The attribute goes on a class or a method and takes one or more actors. An action without ``#[Access]`` answers 403. OpenAPI ``x-access`` ==================== Every operation of the API contract declares the same actors in ``x-access`` (see :ref:`extending-api`): .. code-block:: yaml workingTimeModels: get: operationId: listWorkingTimeModels x-access: - anyEmployee - hr - admin An API route declares exactly the actors its operation lists. Data categories of person fields ================================ A class that describes a person, such as an API resource, an export or a report row, is marked with ``#[PersonResource]``. Each of its properties carries a ``#[DataCategory]``: .. code-block:: php use WebVision\Adsum\Core\Shared\Security\Category; use WebVision\Adsum\Core\Shared\Security\DataCategory; use WebVision\Adsum\Core\Shared\Security\PersonResource; #[PersonResource] final readonly class DirectoryEntryResource { public function __construct( #[DataCategory(Category::Directory)] public string $displayName, // ... ) {} } The category decides who may read a property: ``directory`` Everyone in the company. ``workData`` The person, their managers in scope and HR. ``personal`` The person and HR. ``hrInternal`` HR only. The schema in the OpenAPI contract names the same category with ``x-data-category``: .. code-block:: yaml DirectoryEntry: type: object properties: displayName: type: string x-data-category: directory