Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[users-docs] Restructured Documentation: New Unified Documentation Website #381

Merged
merged 36 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
13f3013
[docs] Restructured docs
pandafy Apr 26, 2024
a1ec91b
[chores] Fixed references
pandafy Apr 26, 2024
5ee1795
[chores] Fixed references
pandafy Apr 26, 2024
0e8dcb8
[docs] Added ref to API auth
nemesifier May 16, 2024
368fb1e
[docs] Updated "Authentication Backend" section
nemesifier May 21, 2024
d6af56e
[docs] Restructuring part 1
nemesifier May 28, 2024
5fccc45
[docs] Reformatted with docstrfmt
nemesifier May 28, 2024
1086883
[docs] Moved management commands to users docs
nemesifier May 28, 2024
c2dcaef
[docs] Updated dev installation instructions
nemesifier May 28, 2024
39dfb97
[docs] Updated dev index
nemesifier May 28, 2024
e7b99e2
[docs] Unified DRF classes in one page
nemesifier Jun 1, 2024
b9b744b
[docs] Improved index
nemesifier Jun 1, 2024
9a23db3
[docs] Admin utils
nemesifier Jun 1, 2024
35333e9
[docs] Misc utils
nemesifier Jun 1, 2024
f7cdec5
[docs] Moved ProtectedAPIMixin to DRF utils page
nemesifier Jun 1, 2024
f4d6547
[docs] Restructured Extending OpenWISP Users page
nemesifier Jun 4, 2024
04cecd8
[docs] Minor improvements
nemesifier Jun 4, 2024
ef1f3d3
[docs] Improved user facing text
nemesifier Jun 4, 2024
8415832
[docs] Point Django docs link to 4.2 version
nemesifier Jun 4, 2024
ca60194
[docs] Minor improvements to REST API and settings
nemesifier Jun 4, 2024
2d79d17
[docs] Explain basic concepts in detail #380
nemesifier Jun 4, 2024
3c505bf
[docs] Improved REST API page
nemesifier Jun 5, 2024
a34ed0f
[docs] Fixed links and other minor improvements
nemesifier Jun 5, 2024
0b74ee3
[skip ci] Fixed reference
pandafy Jun 14, 2024
2605467
[skip ci] Fixed references
pandafy Jun 26, 2024
e61afe6
[docs] Added link to github repo
nemesifier Jul 11, 2024
16ec89d
[skip ci] Fixed references to OpenWISP modules
pandafy Jul 15, 2024
3a7d005
[skip ci] Fixed references to OpenWISP modules
pandafy Jul 15, 2024
1e0c16c
[skip ci] Updated docs website URL
pandafy Jul 15, 2024
4bb791a
[docs] Table of contents, consistency, fixes
nemesifier Jul 16, 2024
ae8d8df
[docs] Minor improvements
nemesifier Jul 19, 2024
d949168
[docs] Added architecture diagram
nemesifier Jul 22, 2024
69caeba
[docs] Reformatted
nemesifier Jul 27, 2024
9841227
Merge branch 'master' into reorder-docs
nemesifier Aug 1, 2024
98af66c
[docs] Reformatted
nemesifier Aug 1, 2024
e71bbee
[qa] Don't skip README in docstrfmt
nemesifier Aug 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,678 changes: 25 additions & 1,653 deletions README.rst

Large diffs are not rendered by default.

94 changes: 94 additions & 0 deletions docs/developer/admin-utils.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
Admin Utilities
===============

This section outlines the admin utilities provided by the OpenWISP Users
module.

.. contents:: **Table of contents**:
:depth: 2
:local:

``MultitenantAdminMixin``
-------------------------

**Full python path**:
``openwisp_users.multitenancy.MultitenantAdminMixin``.

Adding this mixin to a ``ModelAdmin`` class makes it multitenant-capable,
allowing users to see only items of the organizations they manage or own.

This class has two important attributes:

- ``multitenant_shared_relations``: If the model has relations (e.g.,
``ForeignKey``, ``OneToOne``) to other multitenant models with an
``organization`` field, list those model attributes here as a list of
strings. See `how it is used in OpenWISP Controller
<https://github.com/openwisp/openwisp-controller/search?q=multitenant_shared_relations>`_
for a real-world example.
- ``multitenant_parent``: If the admin model relies on a parent model with
the ``organization`` field, specify the field pointing to the parent
here. See `how it is used in OpenWISP Firmware Upgrader
<https://github.com/openwisp/openwisp-firmware-upgrader/search?q=multitenant_parent>`_
for a real-world example.

``MultitenantOrgFilter``
------------------------

**Full python path**:
``openwisp_users.multitenancy.MultitenantOrgFilter``.

This autocomplete admin filter displays only organizations the current
user can manage. Below is an example of adding the autocomplete
organization filter in ``BookAdmin``:

.. code-block:: python

from django.contrib import admin
from openwisp_users.multitenancy import MultitenantOrgFilter


class BookAdmin(admin.ModelAdmin):
list_filter = [
MultitenantOrgFilter,
]
# other attributes

``MultitenantRelatedOrgFilter``
-------------------------------

**Full python path**:
``openwisp_users.multitenancy.MultitenantRelatedOrgFilter``.

This filter is similar to ``MultitenantOrgFilter`` but displays only
objects related to organizations the current user can manage. Use this for
creating filters for related multitenant models.

Consider the following example from `IpAddressAdmin in openwisp-ipam
<https://github.com/openwisp/openwisp-ipam/blob/956d9d25fc1ac339cb148ec7faf80046cc14be37/openwisp_ipam/admin.py#L216-L227>`_.
``IpAddressAdmin`` allows filtering `IpAddress objects by ``Subnet``
belonging to organizations managed by the user.

.. code-block:: python

from django.contrib import admin
from openwisp_users.multitenancy import MultitenantRelatedOrgFilter
from swapper import load_model

Subnet = load_model("openwisp_ipam", "Subnet")


class SubnetFilter(MultitenantRelatedOrgFilter):
field_name = "subnet"
parameter_name = "subnet_id"
title = _("subnet")


@admin.register(IpAddress)
class IpAddressAdmin(
VersionAdmin,
MultitenantAdminMixin,
TimeReadonlyAdminMixin,
ModelAdmin,
):
list_filter = [SubnetFilter]
# other options
Loading