-
-
Notifications
You must be signed in to change notification settings - Fork 917
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sources/plex: add property mappings (#10772)
- Loading branch information
Showing
14 changed files
with
1,458 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"""Plex source property mappings API""" | ||
|
||
from rest_framework.viewsets import ModelViewSet | ||
|
||
from authentik.core.api.property_mappings import PropertyMappingFilterSet, PropertyMappingSerializer | ||
from authentik.core.api.used_by import UsedByMixin | ||
from authentik.sources.plex.models import PlexSourcePropertyMapping | ||
|
||
|
||
class PlexSourcePropertyMappingSerializer(PropertyMappingSerializer): | ||
"""PlexSourcePropertyMapping Serializer""" | ||
|
||
class Meta(PropertyMappingSerializer.Meta): | ||
model = PlexSourcePropertyMapping | ||
|
||
|
||
class PlexSourcePropertyMappingFilter(PropertyMappingFilterSet): | ||
"""Filter for PlexSourcePropertyMapping""" | ||
|
||
class Meta(PropertyMappingFilterSet.Meta): | ||
model = PlexSourcePropertyMapping | ||
|
||
|
||
class PlexSourcePropertyMappingViewSet(UsedByMixin, ModelViewSet): | ||
"""PlexSourcePropertyMapping Viewset""" | ||
|
||
queryset = PlexSourcePropertyMapping.objects.all() | ||
serializer_class = PlexSourcePropertyMappingSerializer | ||
filterset_class = PlexSourcePropertyMappingFilter | ||
search_fields = ["name"] | ||
ordering = ["name"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...rces/plex/migrations/0004_groupplexsourceconnection_plexsourcepropertymapping_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Generated by Django 5.0.7 on 2024-08-05 11:29 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("authentik_core", "0039_source_group_matching_mode_alter_group_name_and_more"), | ||
("authentik_sources_plex", "0003_alter_plexsource_plex_token"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="GroupPlexSourceConnection", | ||
fields=[ | ||
( | ||
"groupsourceconnection_ptr", | ||
models.OneToOneField( | ||
auto_created=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
parent_link=True, | ||
primary_key=True, | ||
serialize=False, | ||
to="authentik_core.groupsourceconnection", | ||
), | ||
), | ||
], | ||
options={ | ||
"verbose_name": "Group Plex Source Connection", | ||
"verbose_name_plural": "Group Plex Source Connections", | ||
}, | ||
bases=("authentik_core.groupsourceconnection",), | ||
), | ||
migrations.CreateModel( | ||
name="PlexSourcePropertyMapping", | ||
fields=[ | ||
( | ||
"propertymapping_ptr", | ||
models.OneToOneField( | ||
auto_created=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
parent_link=True, | ||
primary_key=True, | ||
serialize=False, | ||
to="authentik_core.propertymapping", | ||
), | ||
), | ||
], | ||
options={ | ||
"verbose_name": "Plex Source Property Mapping", | ||
"verbose_name_plural": "Plex Source Property Mappings", | ||
}, | ||
bases=("authentik_core.propertymapping",), | ||
), | ||
migrations.RenameModel( | ||
old_name="PlexSourceConnection", | ||
new_name="UserPlexSourceConnection", | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,7 @@ def test_get_user_info(self): | |
self.assertEqual( | ||
api.get_user_info(), | ||
( | ||
{"username": "username", "email": "[email protected]", "name": "title"}, | ||
USER_INFO_RESPONSE, | ||
1234123419, | ||
), | ||
) | ||
|
@@ -82,3 +82,21 @@ def test_check_task(self): | |
mocker.get("https://plex.tv/api/v2/user", exc=RequestException()) | ||
check_plex_token_all() | ||
self.assertTrue(Event.objects.filter(action=EventAction.CONFIGURATION_ERROR).exists()) | ||
|
||
def test_user_base_properties(self): | ||
"""Test user base properties""" | ||
properties = self.source.get_base_user_properties(info=USER_INFO_RESPONSE) | ||
self.assertEqual( | ||
properties, | ||
{ | ||
"username": "username", | ||
"name": "title", | ||
"email": "[email protected]", | ||
}, | ||
) | ||
|
||
def test_group_base_properties(self): | ||
"""Test group base properties""" | ||
for group_id in ["group 1", "group 2"]: | ||
properties = self.source.get_base_group_properties(group_id=group_id) | ||
self.assertEqual(properties, {"name": group_id}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
"""API URLs""" | ||
|
||
from authentik.sources.plex.api.property_mappings import PlexSourcePropertyMappingViewSet | ||
from authentik.sources.plex.api.source import PlexSourceViewSet | ||
from authentik.sources.plex.api.source_connection import PlexSourceConnectionViewSet | ||
from authentik.sources.plex.api.source_connection import ( | ||
GroupPlexSourceConnectionViewSet, | ||
UserPlexSourceConnectionViewSet, | ||
) | ||
|
||
api_urlpatterns = [ | ||
("sources/user_connections/plex", PlexSourceConnectionViewSet), | ||
("propertymappings/source/plex", PlexSourcePropertyMappingViewSet), | ||
("sources/user_connections/plex", UserPlexSourceConnectionViewSet), | ||
("sources/group_connections/plex", GroupPlexSourceConnectionViewSet), | ||
("sources/plex", PlexSourceViewSet), | ||
] |
Oops, something went wrong.