feat(access): Add multi-tennant manager
manager filters results to that of data from the organizations the users is part of. !42 #124
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: django ITSM Models
|
||||
description: No Fuss Computings Centurion ERP device model
|
||||
title: Centurion ERP Models
|
||||
description: No Fuss Computings Centurion ERP Models development documentation.
|
||||
date: 2024-06-16
|
||||
template: project.html
|
||||
about: https://gitlab.com/nofusscomputing/infrastructure/configuration-management/centurion_erp
|
||||
@ -18,3 +18,5 @@ Models within Centurion ERP:
|
||||
- [History Save](./core_history_save.md)
|
||||
|
||||
- [Organization Permission Checking](./access_organization_permission_checking.md)
|
||||
|
||||
- [Tenancy Object](./tenancy_object.md)
|
||||
|
@ -0,0 +1,25 @@
|
||||
---
|
||||
title: Tenancy Object
|
||||
description: No Fuss Computings Centurion ERP tenancy object API Documentation
|
||||
date: 2024-07-15
|
||||
template: project.html
|
||||
about: https://gitlab.com/nofusscomputing/infrastructure/configuration-management/centurion_erp
|
||||
---
|
||||
|
||||
This page contains the Tenancy Object API Documentation.
|
||||
|
||||
|
||||
## Tenancy Object Model Abstract class
|
||||
|
||||
::: app.access.models.TenancyObject
|
||||
options:
|
||||
inherited_members: true
|
||||
heading_level: 3
|
||||
|
||||
|
||||
## Tenancy Object Manager
|
||||
|
||||
::: app.access.models.TenancyManager
|
||||
options:
|
||||
inherited_members: true
|
||||
heading_level: 3
|
@ -15,7 +15,7 @@ All forms must meet the following requirements:
|
||||
|
||||
- is defined as a class
|
||||
|
||||
- inherits from `core.forms.common.CommonModelForm` _[docs](./api/form.md)_
|
||||
- inherits from [`core.forms.common.CommonModelForm`](./api/form.md)
|
||||
|
||||
- contains a `Meta` sub-class with following parameters:
|
||||
|
||||
@ -23,6 +23,6 @@ All forms must meet the following requirements:
|
||||
|
||||
- `model`
|
||||
|
||||
- Any additional filtering is done as part of an `__init__` method that also calls the super-class `__inti__` first
|
||||
- Any additional filtering is done as part of an `__init__` method that also calls the super-class [`__init__`](./api/form.md) first
|
||||
|
||||
- Any filtering of a field `queryset` is to filter the existing `queryset` not redefine it. i.e. `field[<field name>].queryset.filter()`
|
||||
- Any filtering of a fields `queryset` is to filter the existing `queryset` not redefine it. i.e. `field[<field name>].queryset = field[<field name>].queryset.filter()`
|
||||
|
@ -8,8 +8,10 @@ about: https://gitlab.com/nofusscomputing/infrastructure/configuration-managemen
|
||||
|
||||
This section of the documentation contains different items related to the development of this application. The target audience is anyone whom wishes to develop any part of the application.
|
||||
|
||||
Centurion ERP is a Django Application. We have added a lot of little tid bits that aid in the development process. i.e. abstract classes, tests etc. This allows for decreased development times as items that are common are what could easily be considered templated with the only additional requirement is to add that objests differences.
|
||||
|
||||
## Handy links
|
||||
|
||||
## Areas of the code
|
||||
|
||||
- [Application API Documentation](./api/index.md)
|
||||
|
||||
|
@ -8,12 +8,20 @@ about: https://gitlab.com/nofusscomputing/infrastructure/configuration-managemen
|
||||
|
||||
Models within Centurion ERP are how the data is structured within the database. This page contains documentation pertinent to the development of the models for use with Centurion ERP.
|
||||
|
||||
All models within Centurion ERP are what we call a "Tenancy Object." A tenancy object is a model that takes advantage of the multi-tenancy features of Centurion ERP.
|
||||
|
||||
|
||||
## Requirements
|
||||
|
||||
All models must meet the following requirements:
|
||||
|
||||
- inherits from `app.access.models.TenancyObject` and `django.db.models.Model`
|
||||
- inherits from [`app.access.models.TenancyObject`](./api/models/tenancy_object.md)
|
||||
|
||||
!!! tip
|
||||
There is no requirement to include class [`app.core.mixin.history_save.SaveHistory`](./api/models/core_history_save.md) for inheritence as this class is already included within class [`app.access.models.TenancyObject`](./api/models/tenancy_object.md).
|
||||
|
||||
!!! note
|
||||
If there is a specific use case for the object not to be a tenancy object, this will need to be discussed with a maintainer.
|
||||
|
||||
- class has `__str__` method defined to return that is used to return a default value if no field is specified.
|
||||
|
||||
@ -23,41 +31,14 @@ All models must meet the following requirements:
|
||||
|
||||
- `help_text`
|
||||
|
||||
- No `queryset` is to return data that the user has not got access to. _see [queryset()](./api/models/tenancy_object.md#tenancy-object-manager)_
|
||||
|
||||
|
||||
## Docs to clean up
|
||||
|
||||
!!! note
|
||||
The below documentation is still to be developed. As such what is written below may be incorrect.
|
||||
|
||||
|
||||
## Model Setup
|
||||
|
||||
Any item you wish to be multi-tenant, ensure within your model you include the tenancy model abstract class. The class includes a field called `organization` which links directly to the organization model and is used by the tenancy permission check.
|
||||
|
||||
``` python title="<your app name>/models.py"
|
||||
|
||||
from access.models import TenancyObject
|
||||
|
||||
class YourObject(TenancyObject):
|
||||
...
|
||||
|
||||
```
|
||||
|
||||
|
||||
### Add history to model
|
||||
|
||||
The tracking of changes can be added to a model by including the `SaveHistory` mixin from `core.mixin.history_save` to the model.
|
||||
|
||||
``` python
|
||||
|
||||
from core.mixin.history_save import SaveHistory
|
||||
|
||||
class MyModel(SaveHistory):
|
||||
|
||||
.....
|
||||
|
||||
```
|
||||
|
||||
for items that have a parent item, modification will need to be made to the mixin by adding the relevant check and setting the relevant keys.
|
||||
|
||||
``` python
|
||||
|
Reference in New Issue
Block a user