Skip to content

Commit

Permalink
cleaner account_owner
Browse files Browse the repository at this point in the history
  • Loading branch information
aaxelb committed Dec 1, 2023
1 parent 9bc0f70 commit d28b9ea
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
4 changes: 4 additions & 0 deletions addon_service/authorized_storage_account/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ class Meta:

class JSONAPIMeta:
resource_name = "authorized-storage-accounts"

@property
def account_owner(self):
return self.external_account.owner # TODO: prefetch/select_related
9 changes: 2 additions & 7 deletions addon_service/authorized_storage_account/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from rest_framework_json_api.relations import (
HyperlinkedRelatedField,
ResourceRelatedField,
SerializerMethodResourceRelatedField,
)
from rest_framework_json_api.utils import get_resource_type_from_model

Expand All @@ -19,10 +18,9 @@

class AuthorizedStorageAccountSerializer(serializers.HyperlinkedModelSerializer):
url = serializers.HyperlinkedIdentityField(view_name=f"{RESOURCE_NAME}-detail")
account_owner = SerializerMethodResourceRelatedField(
model=InternalUser,
account_owner = HyperlinkedRelatedField(
many=False,
method_name="_get_account_owner",
queryset=InternalUser.objects.all(),
related_link_view_name=f"{RESOURCE_NAME}-related",
)
external_storage_service = ResourceRelatedField(
Expand Down Expand Up @@ -55,6 +53,3 @@ class Meta:
"default_root_folder",
"external_storage_service",
]

def _get_account_owner(self, instance: AuthorizedStorageAccount):
return instance.external_account.owner # TODO: prefetch/select_related
7 changes: 7 additions & 0 deletions addon_service/internal_user/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
from django.db import models

from addon_service.authorized_storage_account.models import AuthorizedStorageAccount
from addon_service.common.base_model import AddonsServiceBaseModel


class InternalUser(AddonsServiceBaseModel):
user_uri = models.URLField(unique=True, db_index=True, null=False)

@property
def authorized_storage_accounts(self):
return AuthorizedStorageAccount.objects.filter(
external_account__owner=self,
)

class Meta:
verbose_name = "Internal User"
verbose_name_plural = "Internal Users"
Expand Down
2 changes: 1 addition & 1 deletion addon_service/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def _urls_for_viewsets(*viewsets):
"""returns urlpatterns for a viewset that corresponds to a resource type
"""returns urlpatterns for viewsets that each correspond to a resource type
includes patterns for jsonapi-style relationships
"""
Expand Down

0 comments on commit d28b9ea

Please sign in to comment.