Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: further work #383

Merged
merged 10 commits into from
Nov 8, 2024
4 changes: 2 additions & 2 deletions app/access/serializers/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class OrganizationBaseSerializer(serializers.ModelSerializer):

display_name = serializers.SerializerMethodField('get_display_name')

def get_display_name(self, item):
def get_display_name(self, item) -> str:

return str( item )

Expand Down Expand Up @@ -44,7 +44,7 @@ class OrganizationModelSerializer(OrganizationBaseSerializer):

_urls = serializers.SerializerMethodField('get_url')

def get_url(self, item):
def get_url(self, item) -> dict:

return {
'_self': reverse("v2:_api_v2_organization-detail", request=self._context['view'].request, kwargs={'pk': item.pk}),
Expand Down
6 changes: 3 additions & 3 deletions app/access/serializers/team_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ class TeamUserBaseSerializer(serializers.ModelSerializer):

display_name = serializers.SerializerMethodField('get_display_name')

def get_display_name(self, item):
def get_display_name(self, item) -> str:

return str( item )

url = serializers.SerializerMethodField('get_url')

def get_url(self, item):
def get_url(self, item) -> str:

return reverse(
"v2:_api_v2_organization_team_user-detail",
Expand Down Expand Up @@ -53,7 +53,7 @@ class TeamUserModelSerializer(TeamUserBaseSerializer):

_urls = serializers.SerializerMethodField('get_url')

def get_url(self, item):
def get_url(self, item) -> dict:

return {
'_self': reverse(
Expand Down
6 changes: 3 additions & 3 deletions app/access/serializers/teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ class TeamBaseSerializer(serializers.ModelSerializer):

display_name = serializers.SerializerMethodField('get_display_name')

def get_display_name(self, item):
def get_display_name(self, item) -> str:

return str( item )

url = serializers.SerializerMethodField('get_url')

def get_url(self, item):
def get_url(self, item) -> str:

return reverse(
"v2:_api_v2_organization_team-detail",
Expand Down Expand Up @@ -57,7 +57,7 @@ class TeamModelSerializer(TeamBaseSerializer):

_urls = serializers.SerializerMethodField('get_url')

def get_url(self, item):
def get_url(self, item) -> dict:

return {
'_self': reverse(
Expand Down
52 changes: 51 additions & 1 deletion app/access/viewsets/team.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from drf_spectacular.utils import extend_schema, extend_schema_view, OpenApiResponse
from drf_spectacular.utils import extend_schema, extend_schema_view, OpenApiParameter, OpenApiResponse

from access.serializers.teams import (
Team,
Expand All @@ -15,6 +15,13 @@
create=extend_schema(
summary = 'Create a team within this organization',
description='',
parameters = [
OpenApiParameter(
name = 'organization_id',
location = 'path',
type = int
),
],
responses = {
200: OpenApiResponse(description='Allready exists', response=TeamViewSerializer),
201: OpenApiResponse(description='Created', response=TeamViewSerializer),
Expand All @@ -25,6 +32,18 @@
destroy = extend_schema(
summary = 'Delete a team from this organization',
description = '',
parameters = [
OpenApiParameter(
name = 'id',
location = 'path',
type = int
),
OpenApiParameter(
name = 'organization_id',
location = 'path',
type = int
),
],
responses = {
204: OpenApiResponse(description=''),
403: OpenApiResponse(description='User is missing delete permissions'),
Expand All @@ -33,6 +52,13 @@
list = extend_schema(
summary = 'Fetch all teams from this organization',
description='',
parameters = [
OpenApiParameter(
name = 'organization_id',
location = 'path',
type = int
),
],
responses = {
200: OpenApiResponse(description='', response=TeamViewSerializer),
403: OpenApiResponse(description='User is missing view permissions'),
Expand All @@ -41,6 +67,18 @@
retrieve = extend_schema(
summary = 'Fetch a single team from this organization',
description='',
parameters = [
OpenApiParameter(
name = 'id',
location = 'path',
type = int
),
OpenApiParameter(
name = 'organization_id',
location = 'path',
type = int
),
],
responses = {
200: OpenApiResponse(description='', response=TeamViewSerializer),
403: OpenApiResponse(description='User is missing view permissions'),
Expand All @@ -50,6 +88,18 @@
partial_update = extend_schema(
summary = 'Update a team within this organization',
description = '',
parameters = [
OpenApiParameter(
name = 'id',
location = 'path',
type = int
),
OpenApiParameter(
name = 'organization_id',
location = 'path',
type = int
),
],
responses = {
200: OpenApiResponse(description='', response=TeamViewSerializer),
# 201: OpenApiResponse(description='Created', response=OrganizationViewSerializer),
Expand Down
77 changes: 76 additions & 1 deletion app/access/viewsets/team_user.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from drf_spectacular.utils import extend_schema, extend_schema_view, OpenApiResponse
from drf_spectacular.utils import extend_schema, extend_schema_view, OpenApiParameter, OpenApiResponse

from access.serializers.team_user import (
TeamUsers,
Expand All @@ -14,6 +14,18 @@
create=extend_schema(
summary = 'Create a user within this team',
description='',
parameters = [
OpenApiParameter(
name = 'organization_id',
location = 'path',
type = int
),
OpenApiParameter(
name = 'team_id',
location = 'path',
type = int
),
],
responses = {
# 200: OpenApiResponse(description='Allready exists', response=TeamUserViewSerializer),
201: OpenApiResponse(description='Created', response=TeamUserViewSerializer),
Expand All @@ -24,6 +36,23 @@
destroy = extend_schema(
summary = 'Delete a user from this team',
description = '',
parameters = [
OpenApiParameter(
name = 'id',
location = 'path',
type = int
),
OpenApiParameter(
name = 'organization_id',
location = 'path',
type = int
),
OpenApiParameter(
name = 'team_id',
location = 'path',
type = int
),
],
responses = {
204: OpenApiResponse(description=''),
403: OpenApiResponse(description='User is missing delete permissions'),
Expand All @@ -32,6 +61,18 @@
list = extend_schema(
summary = 'Fetch all users from this team',
description='',
parameters = [
OpenApiParameter(
name = 'organization_id',
location = 'path',
type = int
),
OpenApiParameter(
name = 'team_id',
location = 'path',
type = int
),
],
responses = {
200: OpenApiResponse(description='', response=TeamUserViewSerializer),
403: OpenApiResponse(description='User is missing view permissions'),
Expand All @@ -40,6 +81,23 @@
retrieve = extend_schema(
summary = 'Fetch a single user from this team',
description='',
parameters = [
OpenApiParameter(
name = 'id',
location = 'path',
type = int
),
OpenApiParameter(
name = 'organization_id',
location = 'path',
type = int
),
OpenApiParameter(
name = 'team_id',
location = 'path',
type = int
),
],
responses = {
200: OpenApiResponse(description='', response=TeamUserViewSerializer),
403: OpenApiResponse(description='User is missing view permissions'),
Expand All @@ -49,6 +107,23 @@
partial_update = extend_schema(
summary = 'Update a user within this team',
description = '',
parameters = [
OpenApiParameter(
name = 'id',
location = 'path',
type = int
),
OpenApiParameter(
name = 'organization_id',
location = 'path',
type = int
),
OpenApiParameter(
name = 'team_id',
location = 'path',
type = int
),
],
responses = {
200: OpenApiResponse(description='', response=TeamUserViewSerializer),
# 201: OpenApiResponse(description='Created', response=OrganizationViewSerializer),
Expand Down
14 changes: 14 additions & 0 deletions app/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@

from api.models.tokens import AuthToken

# scheme.py
from drf_spectacular.extensions import OpenApiAuthenticationExtension

class TokenScheme(OpenApiAuthenticationExtension):
target_class = "api.auth.TokenAuthentication"
name = "TokenAuthentication"

def get_security_definition(self, auto_schema):
return {
"type": "apiKey",
"in": "header",
"name": "Token Authorization",
"description": "Token-based authentication with required prefix 'Token'",
}


class TokenAuthentication(BaseAuthentication):
Expand Down
Loading
Loading