Skip to content

Commit

Permalink
feat(api): add token domain policies endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
peterthomassen committed Mar 2, 2021
1 parent 2512a3b commit c4c6bb8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions api/desecapi/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ def get_fields(self):
return fields


class TokenDomainPolicySerializer(serializers.ModelSerializer):

class Meta:
model = models.TokenDomainPolicy
fields = ('domain', 'perm_dyndns', 'perm_other',)
read_only_fields = ('domain',)


class RequiredOnPartialUpdateCharField(serializers.CharField):
"""
This field is always required, even for partial updates (e.g. using PATCH).
Expand Down
4 changes: 4 additions & 0 deletions api/desecapi/urls/version_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
tokens_router = SimpleRouter()
tokens_router.register(r'', views.TokenViewSet, basename='token')

tokendomainpolicies_router = SimpleRouter()
tokendomainpolicies_router.register(r'', views.TokenDomainPolicyViewSet, basename='token_domain_policies')

auth_urls = [
# User management
path('', views.AccountCreateView.as_view(), name='register'),
Expand All @@ -18,6 +21,7 @@

# Token management
path('tokens/', include(tokens_router.urls)),
path('tokens/<id>/domain_policies/', include(tokendomainpolicies_router.urls))
]

domains_router = SimpleRouter()
Expand Down
11 changes: 11 additions & 0 deletions api/desecapi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ def perform_create(self, serializer):
serializer.save(user=self.request.user)


class TokenDomainPolicyViewSet(viewsets.ModelViewSet):
serializer_class = serializers.TokenDomainPolicySerializer
permission_classes = (IsAuthenticated,)
throttle_scope = 'account_management_passive'

def get_queryset(self):
### TODO token manage permission?
print('============= ID', self.kwargs['id'])
return self.request.user.token_set.get(id=self.kwargs['id']).domain_policies


class DomainViewSet(IdempotentDestroyMixin,
mixins.CreateModelMixin,
mixins.RetrieveModelMixin,
Expand Down

0 comments on commit c4c6bb8

Please sign in to comment.