Merge branch 'master' of gitlab.com:allianceauth/allianceauth into v4.x

This commit is contained in:
Ariel Rin
2023-12-08 14:49:56 +10:00
94 changed files with 2865 additions and 1642 deletions

View File

@@ -10,7 +10,7 @@ To get started, `pip install pre-commit`, then `pre-commit install` to add the g
Before any code is "git push"-ed, pre-commit will check it for uniformity and correct it if possible
```bash
```shell
check python ast.....................................(no files to check)Skipped
check yaml...........................................(no files to check)Skipped
check json...........................................(no files to check)Skipped

View File

@@ -26,12 +26,14 @@ rearrange toctrees.
## Documentation Format
CommonMark Markdown is the current preferred format, via [recommonmark](https://github.com/rtfd/recommonmark).
reStructuredText is supported if required, or you can execute snippets of reST inside Markdown by using a code block:
CommonMark-plus Markdown is the current preferred format, via [MyST-Parser](https://github.com/executablebooks/MyST-Parser).
reStructuredText is supported if required, or you can execute snippets of MyST inside Markdown by using a code block:
```eval_rst
reStructuredText here
```
````md
```{eval-rst}
reStructuredText here
```
````
Markdown is used elsewhere on Github so it provides the most portability of documentation from Issues and Pull Requests
as well as providing an easier initial migration path from the Github wiki.

View File

@@ -2,10 +2,9 @@
This section contains important information on how to develop Alliance Auth itself.
```eval_rst
.. toctree::
:maxdepth: 1
:::{toctree}
:maxdepth: 1
documentation
code-style
```
documentation
code-style
:::

View File

@@ -2,14 +2,12 @@
This section describes how to extend **Alliance Auth** with custom apps, services and themes.
```eval_rst
.. toctree::
:maxdepth: 1
:::{toctree}
:maxdepth: 1
integrating-services
custom-themes
menu-hooks
url-hooks
logging
css-framework
```
integrating-services
menu-hooks
url-hooks
logging
css-framework
:::

View File

@@ -21,19 +21,19 @@ Typically a service will contain 5 key components:
The architecture looks something like this:
```none
urls -------▶ Views
▲ |
| |
| ▼
ServiceHook ----▶ Tasks ----▶ Manager
|
|
AllianceAuth
urls -------▶ Views
▲ |
| |
| ▼
ServiceHook ----▶ Tasks ----▶ Manager
|
|
AllianceAuth
Where:
Module --▶ Dependency/Import
Where:
Module --▶ Dependency/Import
```
While this is the typical structure of the existing services modules, there is no enforcement of this structure and you are, effectively, free to create whatever architecture may be necessary. A service module need not even communicate with an external service, for example, if similar triggers such as validate_user, delete_user are required for a module it may be convenient to masquerade as a service. Ideally though, using the common structure improves the maintainability for other developers.
@@ -50,23 +50,22 @@ def register_service():
This would register the ExampleService class which would need to be a subclass of `services.hooks.ServiceHook`.
```eval_rst
.. important::
The hook **MUST** be registered in ``yourservice.auth_hooks`` along with any other hooks you are registering for Alliance Auth.
```
:::{important}
The hook **MUST** be registered in ``yourservice.auth_hooks`` along with any other hooks you are registering for Alliance Auth.
:::
A subclassed `ServiceHook` might look like this:
```python
class ExampleService(ServicesHook):
def __init__(self):
ServicesHook.__init__(self)
self.urlpatterns = urlpatterns
self.service_url = 'http://exampleservice.example.com'
def __init__(self):
ServicesHook.__init__(self)
self.urlpatterns = urlpatterns
self.service_url = 'http://exampleservice.example.com'
"""
Overload base methods here to implement functionality
"""
"""
Overload base methods here to implement functionality
"""
```
### The ServiceHook class
@@ -79,7 +78,7 @@ Instance Variables:
- [self.name](#selfname)
- [self.urlpatterns](#selfurlpatterns)
- [self.service_ctrl_template](#selfservice-ctrl-template)
- [self.service_ctrl_template](#selfservice_ctrl_template)
Properties:
@@ -123,7 +122,9 @@ class MyService(ServiceHook):
All of your apps defined urlpatterns will then be included in the `URLconf` when the core application starts.
### Properties
#### self.service_ctrl_template
This is provided as a courtesy and defines the default template to be used with [render_service_ctrl](#render_service_ctrl). You are free to redefine or not use this variable at all.
#### title
@@ -150,12 +151,14 @@ The function should return a boolean, `True` if successfully disabled, `False` o
Validate the users service account, deleting it if they should no longer have access. The `user` parameter should be a Django User object.
An implementation will probably look like the following:
```python
def validate_user(self, user):
logger.debug('Validating user %s %s account' % (user, self.name))
if ExampleTasks.has_account(user) and not self.service_active_for_user(user):
self.delete_user(user, notify_user=True)
```
No return value is expected.
This function will be called periodically on all users to validate that the given user should have their current service accounts.
@@ -312,3 +315,9 @@ You should have a look through some of the other service modules before you get
## Testing
You will need to add unit tests for all aspects of your service module before it is accepted. Be mindful that you don't actually want to make external calls to the service so you should mock the appropriate components to prevent this behavior.
```{eval-rst}
.. autoclass:: allianceauth.services.hooks.ServicesHook
:members:
:undoc-members:
```

View File

@@ -36,3 +36,11 @@ Options are: *(all options accept entries of levels listed below them)*
* `WARNING`
* `ERROR`
* `CRITICAL`
## allianceauth.services.hooks.get_extension_logger
```{eval-rst}
.. automodule:: allianceauth.services.hooks.get_extension_logger
:members:
:undoc-members:
```

View File

@@ -12,7 +12,7 @@ def register_menu():
The `MenuItemHook` class specifies some parameters/instance variables required for menu item display.
```eval_rst
```{eval-rst}
.. autoclass:: allianceauth.services.hooks.MenuItemHook
:members: __init__
:undoc-members:
@@ -24,23 +24,22 @@ The `MenuItemHook` class specifies some parameters/instance variables required f
This is a great feature to signal the user, that he has some open issues to take care of within an app. For example Auth uses this feature to show the specific number of open group request to the current user.
```eval_rst
.. hint::
Here is how to stay consistent with the Auth design philosophy for using this feature:
1. Use it to display open items that the current user can close by himself only. Do not use it for items, that the user has no control over.
2. If there are currently no open items, do not show a badge at all.
```
:::{hint}
Here is how to stay consistent with the Auth design philosophy for using this feature:
1. Use it to display open items that the current user can close by himself only. Do not use it for items, that the user has no control over.
2. If there are currently no open items, do not show a badge at all.
:::
To use it set count the `render()` function of your subclass in accordance to the current user. Here is an example:
```eval_rst
```{eval-rst}
.. automodule:: allianceauth.services.hooks.MenuItemHook
:members: render
:noindex:
:undoc-members:
```
```Python
```python
def render(self, request):
# ...
self.count = calculate_count_for_user(request.user)

View File

@@ -30,10 +30,11 @@ In addition is it possible to make views public. Normally, all views are automat
An app can opt-out of this feature by adding a list of views to be excluded when registering the URLs. See the `excluded_views` parameter for details.
```eval_rst
.. note::
Note that for a public view to work, administrators need to also explicitly allow apps to have public views in their AA installation, by adding the apps label to ``APPS_WITH_PUBLIC_VIEWS`` setting.
```
:::{note}
Note that for a public view to work, administrators need to also explicitly allow apps to have public views in their AA installation, by adding the apps label to ``APPS_WITH_PUBLIC_VIEWS`` setting.
:::
>>>>>>>
## Examples
An app called `plugin` provides a single view:
@@ -70,7 +71,7 @@ When this app is included in the project's `settings.INSTALLED_APPS` users would
## API
```eval_rst
```{eval-rst}
.. autoclass:: allianceauth.services.hooks.UrlHook
:members:
```

View File

@@ -6,10 +6,9 @@ The main benefit of this setup is that it runs all services and code in the nati
In addition all tools described in this guide are open source or free software.
```eval_rst
.. hint::
This guide is meant for development purposes only and not for installing AA in a production environment. For production installation please see chapter **Installation**.
```
:::{hint}
This guide is meant for development purposes only and not for installing AA in a production environment. For production installation please see chapter **Installation**.
:::
## Overview
@@ -25,10 +24,9 @@ The development environment consists of the following components:
We will use the build-in Django development web server, so we don't need to setup a WSGI server or a web server.
```eval_rst
.. note::
This setup works with both WSL 1 and WSL 2. However, due to the significantly better performance we recommend WSL 2.
```
:::{note}
This setup works with both WSL 1 and WSL 2. However, due to the significantly better performance we recommend WSL 2.
:::
## Requirement
@@ -39,32 +37,27 @@ The only requirement is a PC with Windows 10 and Internet connection in order to
### Windows Subsystem for Linux
- Install from here: [Microsoft docs](https://docs.microsoft.com/en-us/windows/wsl/install-win10)
- Choose Ubuntu 18.04. LTS or higher
### Visual Studio Code
- Install from here: [VSC Download](https://code.visualstudio.com/Download)
- Open the app and install the following VSC extensions:
- Remote WSL
- Connect to WSL. This will automatically install the VSC server on the VSC server for WSL
- Once connected to WSL install the Python extension on the WSL side
## Setting up WSL / Linux
Open a WSL bash and update all software packets:
```bash
```shell
sudo apt update && sudo apt upgrade -y
```
### Install Tools
```bash
```shell
sudo apt-get install build-essential
sudo apt-get install gettext
```
@@ -73,36 +66,33 @@ sudo apt-get install gettext
Next we need to install Python and related development tools.
```eval_rst
.. hint::
To check your system's Python 3 version you can enter: ``python3 --version``
:::{note}
Should your Ubuntu come with a newer version of Python we recommend to still setup your dev environment with the oldest Python 3 version currently supported by AA (e.g Python 3.8 at this time of writing) to ensure your apps are compatible with all current AA installations
You an check out this `page <https://askubuntu.com/questions/682869/how-do-i-install-a-different-python-version-using-apt-get/1195153>`_ on how to install additional Python versions on Ubuntu.
If you install a different python version from the default you need to adjust some of the commands below to install appopriate versions of those packages for example using Python 3.8 you might need to run the following after using the setup steps for the repository mentioned in the AskUbuntu post above:
```shell
sudo apt-get install python3.8 python3.8-dev python3.8-venv python3-setuptools python3-pip python-pip
```
```eval_rst
.. note::
Should your Ubuntu come with a newer version of Python we recommend to still setup your dev environment with the oldest Python 3 version currently supported by AA (e.g Python 3.8 at this time of writing) to ensure your apps are compatible with all current AA installations
You an check out this `page <https://askubuntu.com/questions/682869/how-do-i-install-a-different-python-version-using-apt-get/1195153>`_ on how to install additional Python versions on Ubuntu.
If you install a different python version from the default you need to adjust some of the commands below to install appopriate versions of those packages for example using Python 3.8 you might need to run the following after using the setup steps for the repository mentioned in the AskUbuntu post above:
`sudo apt-get install python3.8 python3.8-dev python3.8-venv python3-setuptools python3-pip python-pip`
```
:::
Use the following command to install Python 3 with all required libraries with the default version:
```bash
```shell
sudo apt-get install python3 python3-dev python3-venv python3-setuptools python3-pip python-pip
```
### Install redis and other tools
```bash
```shell
sudo apt-get install unzip git redis-server curl libssl-dev libbz2-dev libffi-dev pkg-config
```
Start redis
```bash
```shell
sudo redis-server --daemonize yes
```
@@ -110,30 +100,29 @@ sudo redis-server --daemonize yes
Install MySQL and required libraries with the following command:
```bash
```shell
sudo apt-get install mysql-server mysql-client libmysqlclient-dev
```
```eval_rst
.. note::
We chose to use MySQL instead of MariaDB, because the standard version of MariaDB that comes with this Ubuntu distribution will not work with AA.
```
:::{note}
We chose to use MySQL instead of MariaDB, because the standard version of MariaDB that comes with this Ubuntu distribution will not work with AA.
:::
We need to apply a permission fix to mysql or you will get a warning with every startup:
```bash
```shell
sudo usermod -d /var/lib/mysql/ mysql
```
Start the mysql server
```bash
```shell
sudo service mysql start
```
Create database and user for AA
```bash
```shell
sudo mysql -u root
```
@@ -147,23 +136,22 @@ exit;
Add timezone info to mysql:
```bash
```shell
sudo mysql_tzinfo_to_sql /usr/share/zoneinfo | sudo mysql -u root mysql
```
```eval_rst
.. note::
If your WSL does not have an init.d service, it will not automatically start your services such as MySQL and Redis when you boot your Windows machine and you have to manually start them. For convenience we recommend putting these commands in a bash script. Here is an example:
::
#/bin/bash
# start services for AA dev
sudo service mysql start
sudo redis-server --daemonize yes
:::{note}
If your WSL does not have an init.d service, it will not automatically start your services such as MySQL and Redis when you boot your Windows machine and you have to manually start them. For convenience we recommend putting these commands in a bash script. Here is an example:
```shell
#/bin/bash
# start services for AA dev
sudo service mysql start
sudo redis-server --daemonize yes
```
:::
### Setup dev folder on WSL
Setup your folders on WSL bash for your dev project. Our approach will setup one AA project with one venv and multiple apps running under the same AA project, but each in their own folder and git.
@@ -183,28 +171,27 @@ Following this approach you can also setup additional AA projects, e.g. aa-dev-2
Create the root folder `aa-dev`.
```eval_rst
.. hint::
The folders `venv` and `myauth` will be created automatically in later steps. Please do not create them manually as this would lead to errors.
```
:::{hint}
The folders `venv` and `myauth` will be created automatically in later steps. Please do not create them manually as this would lead to errors.
:::
### Setup virtual Python environment for aa-dev
Create the virtual environment. Run this in your aa-dev folder:
```bash
```shell
python3 -m venv venv
```
And activate your venv:
```bash
```shell
source venv/bin/activate
```
### Install and update basic Python packages
```bash
```shell
pip install -U pip setuptools wheel
```
@@ -212,19 +199,19 @@ pip install -U pip setuptools wheel
### Install and create AA instance
```bash
```shell
pip install allianceauth
```
Now we are ready to setup our AA instance. Make sure to run this command in your aa-dev folder:
```bash
```shell
allianceauth start myauth
```
Next we will setup our VSC project for aa-dev by starting it directly from the WSL bash:
```bash
```shell
code .
```
@@ -244,10 +231,9 @@ For the Eve Online related setup you need to create a SSO app on the developer s
Open your local Django settings with VSC. The file is under `myauth/myauth/settings/local.py`
```eval_rst
.. hint::
There are two Django settings files: ``base.py`` and ``local.py``. The base settings file is controlled by the AA project and may change at any time. It is therefore recommended to only change the local settings file.
```
:::{hint}
There are two Django settings files: ``base.py`` and ``local.py``. The base settings file is controlled by the AA project and may change at any time. It is therefore recommended to only change the local settings file.
:::
```python
DEBUG = True
@@ -293,14 +279,14 @@ REGISTRATION_VERIFY_EMAIL = False
Before we can start AA we need to run migrations:
```bash
```shell
cd myauth
python manage.py migrate
```
We also need to create a superuser for our AA installation:
```bash
```shell
python manage.py createsuperuser
```
@@ -310,24 +296,22 @@ python manage.py createsuperuser
We are now ready to run out AA instance with the following command:
```bash
```shell
python manage.py runserver
```
Once running you can access your auth site on the browser under `http://localhost:8000`. Or the admin site under `http://localhost:8000/admin`
```eval_rst
.. hint::
You can start your AA server directly from a terminal window in VSC or with a VSC debug config (see chapter about debugging for details).
```
:::{hint}
You can start your AA server directly from a terminal window in VSC or with a VSC debug config (see chapter about debugging for details).
:::
```eval_rst
.. note::
**Debug vs. Non-Debug mode**
Usually it is best to run your dev AA instance in debug mode, so you get all the detailed error messages that helps a lot for finding errors. But there might be cases where you want to test features that do not exist in debug mode (e.g. error pages) or just want to see how your app behaves in non-debug / production mode.
:::{note}
**Debug vs. Non-Debug mode**
Usually it is best to run your dev AA instance in debug mode, so you get all the detailed error messages that helps a lot for finding errors. But there might be cases where you want to test features that do not exist in debug mode (e.g. error pages) or just want to see how your app behaves in non-debug / production mode.
When you turn off debug mode you will see a problem though: Your pages will not render correctly. The reason is that Django will stop serving your static files in production mode and expect you to serve them from a real web server. Luckily, there is an option that forces Django to continue serving your static files directly even when not in debug mode. Just start your server with the following option: ``python manage.py runserver --insecure``
```
When you turn off debug mode you will see a problem though: Your pages will not render correctly. The reason is that Django will stop serving your static files in production mode and expect you to serve them from a real web server. Luckily, there is an option that forces Django to continue serving your static files directly even when not in debug mode. Just start your server with the following option: ``python manage.py runserver --insecure``
:::
### Celery
@@ -335,7 +319,7 @@ In addition you can start a celery worker instance for myauth. For development p
This can be done from the command line with the following command in the myauth folder (where manage.py is located):
```bash
```shell
celery -A myauth worker -l info -P solo
```
@@ -499,7 +483,7 @@ Open a WSL bash and navigate to the aa-dev folder. Make sure you have activate y
Run these commands:
```bash
```shell
git clone https://gitlab.com/ErikKalkoken/allianceauth-example-plugin.git
pip install -e allianceauth-example-plugin
```
@@ -508,7 +492,7 @@ Add `'example'` to INSTALLED_APPS in your `local.py` settings.
Run migrations and restart your AA server, e.g.:
```bash
```shell
cd myauth
python manage.py migrate
```

View File

@@ -2,9 +2,8 @@
Here you find guides on how to setup your development environment for AA.
```eval_rst
.. toctree::
:maxdepth: 1
:::{toctree}
:maxdepth: 1
aa-dev-setup-wsl-vsc-v2
```
aa-dev-setup-wsl-vsc-v2
:::

View File

@@ -2,12 +2,11 @@
**Alliance Auth** is designed to be extended easily. Learn how to develop your own apps and services for AA or to develop for AA core in the development chapter.
```eval_rst
.. toctree::
:maxdepth: 2
:::{toctree}
:maxdepth: 1
custom/index
aa_core/index
dev_setup/index
tech_docu/index
```
custom/index
aa_core/index
dev_setup/index
tech_docu/index
:::

View File

@@ -2,16 +2,15 @@
To reduce redundancy and help speed up development we encourage developers to utilize the following packages when developing apps for Alliance Auth.
```eval_rst
.. toctree::
:maxdepth: 1
:::{toctree}
:maxdepth: 1
discord_client
discord_service
esi
evelinks
eveonline
notifications
testutils
utils
```
discord_client
discord_service
esi
evelinks
eveonline
notifications
testutils
utils
:::

View File

@@ -14,10 +14,9 @@ Alliance Auth is an online web application and as such the user expects fast and
As a rule of thumb we therefore recommend to use celery tasks for every process that can take longer than 1 sec to complete (also think about how long your process might take with large amounts of data).
```eval_rst
.. note::
Another solution for dealing with long response time in particular when loading pages is to load parts of a page asynchronously, for example with AJAX.
```
:::{note}
Another solution for dealing with long response time in particular when loading pages is to load parts of a page asynchronously, for example with AJAX.
:::
### Recurrence
@@ -40,7 +39,7 @@ Please use the following approach to ensure your tasks are working properly with
Here is an example implementation of a task:
```Python
```python
import logging
from celery import shared_task
@@ -54,7 +53,7 @@ def example():
This task can then be started from any another Python module like so:
```Python
```python
from .tasks import example
example.delay()
@@ -80,7 +79,7 @@ However, many long running tasks consist of several smaller processes that need
Example implementation for a celery chain:
```Python
```python
import logging
from celery import shared_task, chain
@@ -106,14 +105,13 @@ In this example we fist add 10 example tasks that need to run one after the othe
The list of task signatures is then converted to a chain and started asynchronously.
```eval_rst
.. hint::
In our example we use ``si()``, which is a shortcut for "immutable signatures" and prevents us from having to deal with result sharing between tasks.
:::{hint}
In our example we use ``si()``, which is a shortcut for "immutable signatures" and prevents us from having to deal with result sharing between tasks.
For more information on signature and work flows see the official documentation on `Canvas <https://docs.celeryproject.org/en/latest/userguide/canvas.html>`_.
For more information on signature and work flows see the official documentation on `Canvas <https://docs.celeryproject.org/en/latest/userguide/canvas.html>`_.
In this context please note that Alliance Auth currently only supports chaining, because all other variants require a so called results back, which Alliance Auth does not have.
```
In this context please note that Alliance Auth currently only supports chaining, because all other variants require a so called results back, which Alliance Auth does not have.
:::
## How can I define periodic tasks for my app?
@@ -121,7 +119,7 @@ Periodic tasks are normal celery tasks which are added the scheduler for periodi
Example setting:
```Python
```python
CELERYBEAT_SCHEDULE['structures_update_all_structures'] = {
'task': 'structures.tasks.update_all_structures',
'schedule': crontab(minute='*/30'),
@@ -137,7 +135,7 @@ CELERYBEAT_SCHEDULE['structures_update_all_structures'] = {
In Alliance Auth we have defined task priorities from 0 - 9 as follows:
```eval_rst
```{eval-rst}
====== ========= ===========
Number Priority Description
====== ========= ===========
@@ -150,30 +148,25 @@ In Alliance Auth we have defined task priorities from 0 - 9 as follows:
====== ========= ===========
```
```eval_rst
.. warning::
Please make sure to use task priorities with care and especially do not use higher priorities without a good reason. All apps including Alliance Auth share the same task queues, so using higher task priorities excessively can potentially prevent more important tasks (of other apps) from completing on time.
You also want to make sure to run use lower priorities if you have a large amount of tasks or long running tasks, which are not super urgent. (e.g. the regular update of all Eve characters from ESI runs with priority 7)
```
```eval_rst
.. hint::
If no priority is specified all tasks will be started with the default priority, which is 5.
```
:::{warning}
Please make sure to use task priorities with care and especially do not use higher priorities without a good reason. All apps including Alliance Auth share the same task queues, so using higher task priorities excessively can potentially prevent more important tasks (of other apps) from completing on time.
You also want to make sure to run use lower priorities if you have a large amount of tasks or long running tasks, which are not super urgent. (e.g. the regular update of all Eve characters from ESI runs with priority 7)
:::
:::{hint}
If no priority is specified all tasks will be started with the default priority, which is 5.
:::
To run a task with a different priority you need to specify it when starting it.
Example for starting a task with priority 3:
```Python
```python
example.apply_async(priority=3)
```
```eval_rst
.. hint::
For defining a priority to tasks you can not use the convenient shortcut ``delay()``, but instead need to start a task with ``apply_async()``, which also requires you to pass parameters to your task function differently. Please check out the `official docs <https://docs.celeryproject.org/en/stable/reference/celery.app.task.html#celery.app.task.Task.apply_async>`_ for details.
```
:::{hint}
For defining a priority to tasks you can not use the convenient shortcut ``delay()``, but instead need to start a task with ``apply_async()``, which also requires you to pass parameters to your task function differently. Please check out the `official docs <https://docs.celeryproject.org/en/stable/reference/celery.app.task.html#celery.app.task.Task.apply_async>`_ for details.
:::
## What special features should I be aware of?
@@ -186,18 +179,18 @@ Celery-once is a celery extension "that allows you to prevent multiple execution
We use a custom backend for celery_once in Alliance Auth defined [here](https://gitlab.com/allianceauth/allianceauth/-/blob/master/allianceauth/services/tasks.py#L14)
You can import it for use like so:
```Python
```python
from allianceauth.services.tasks import QueueOnce
```
An example of AllianceAuth's use within the `@sharedtask` decorator, can be seen [here](https://gitlab.com/allianceauth/allianceauth/-/blob/master/allianceauth/services/modules/discord/tasks.py#L62) in the discord module
You can use it like so:
```Python
```python
@shared_task(bind=True, name='your_modules.update_task', base=QueueOnce)
```
Please see the [official documentation](hhttps://pypi.org/project/celery_once/) of celery-once for details.
Please see the [official documentation](https://pypi.org/project/celery_once/) of celery-once for details.
### task priorities

View File

@@ -2,12 +2,11 @@
In this section you find topics useful for app developers.
```eval_rst
.. toctree::
:maxdepth: 1
:::{toctree}
:maxdepth: 1
api/index
celery
core_models
templatetags
```
api/index
celery
core_models
templatetags
:::