Change custom pipeline since netbox 4.0.0 (#9743)
Due to a Django 5.0 regression, group.user_set does not exist anymore. https://github.com/netbox-community/netbox/discussions/16098 https://github.com/netbox-community/netbox/discussions/16000 Signed-off-by: Manuel Rais <manuel.rais@nousvoir.com>
This commit is contained in:
@ -82,7 +82,7 @@ LOGOUT_REDIRECT_URL = environ.get('LOGOUT_REDIRECT_URL')
|
|||||||
To manage groups in NetBox custom social auth pipelines are required. To create them you have to create the `custom_pipeline.py` file in the NetBox directory with the following content.
|
To manage groups in NetBox custom social auth pipelines are required. To create them you have to create the `custom_pipeline.py` file in the NetBox directory with the following content.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from django.contrib.auth.models import Group
|
from netbox.authentication import Group
|
||||||
|
|
||||||
class AuthFailed(Exception):
|
class AuthFailed(Exception):
|
||||||
pass
|
pass
|
||||||
@ -96,7 +96,7 @@ def add_groups(response, user, backend, *args, **kwargs):
|
|||||||
# Add all groups from oAuth token
|
# Add all groups from oAuth token
|
||||||
for group in groups:
|
for group in groups:
|
||||||
group, created = Group.objects.get_or_create(name=group)
|
group, created = Group.objects.get_or_create(name=group)
|
||||||
group.user_set.add(user)
|
group.users.add(user)
|
||||||
|
|
||||||
def remove_groups(response, user, backend, *args, **kwargs):
|
def remove_groups(response, user, backend, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
@ -114,7 +114,7 @@ def remove_groups(response, user, backend, *args, **kwargs):
|
|||||||
# Delete non oAuth token groups
|
# Delete non oAuth token groups
|
||||||
for delete_group in delete_groups:
|
for delete_group in delete_groups:
|
||||||
group = Group.objects.get(name=delete_group)
|
group = Group.objects.get(name=delete_group)
|
||||||
group.user_set.remove(user)
|
group.users.remove(user)
|
||||||
|
|
||||||
|
|
||||||
def set_roles(response, user, backend, *args, **kwargs):
|
def set_roles(response, user, backend, *args, **kwargs):
|
||||||
|
|||||||
Reference in New Issue
Block a user