current avatar url
This commit is contained in:
parent
565f7a298f
commit
8890777237
4 changed files with 41 additions and 8 deletions
18
apps/gooyal_oauth2/migrations/0004_application_avatar.py
Normal file
18
apps/gooyal_oauth2/migrations/0004_application_avatar.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 5.1.4 on 2025-03-11 11:01
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('gooyal_oauth2', '0003_accesstoken_token_checksum_refreshtoken_token_family_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='application',
|
||||
name='avatar',
|
||||
field=models.ImageField(blank=True, null=True, upload_to='avatars'),
|
||||
),
|
||||
]
|
||||
|
|
@ -51,6 +51,8 @@ class Application(AbstractApplication):
|
|||
related_name='application'
|
||||
)
|
||||
|
||||
avatar = models.ImageField(upload_to='avatars', null=True, blank=True)
|
||||
|
||||
@property
|
||||
def allowed_scopes(self):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
from django.http import Http404
|
||||
from django.shortcuts import redirect
|
||||
from oauth2_provider.contrib.rest_framework import TokenHasScope
|
||||
from rest_framework import generics
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.permissions import AllowAny
|
||||
from rest_framework.viewsets import ReadOnlyModelViewSet
|
||||
|
||||
from ..models import Application
|
||||
|
|
@ -9,7 +13,7 @@ from ..serializers import ApplicationSerializer
|
|||
|
||||
class ApplicationViewSet(ReadOnlyModelViewSet):
|
||||
serializer_class = ApplicationSerializer
|
||||
lookup_field = 'uuid'
|
||||
# lookup_field = 'uuid'
|
||||
permission_classes = [IsAuthenticatedOrTokenMatchesOASRequirements]
|
||||
required_alternate_scopes = {
|
||||
"GET": [['accounts.applications:list_or_retrieve']],
|
||||
|
|
@ -17,3 +21,12 @@ class ApplicationViewSet(ReadOnlyModelViewSet):
|
|||
def get_queryset(self):
|
||||
user = self.request.user
|
||||
return Application.objects.filter(user=user).all()
|
||||
|
||||
@action(detail=True, permission_classes=[AllowAny])
|
||||
def avatar(self, request, pk=None):
|
||||
app: Application = self.get_object()
|
||||
if app.avatar:
|
||||
return redirect(app.avatar.url)
|
||||
else:
|
||||
raise Http404()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.views import LoginView
|
||||
from django.http import Http404
|
||||
from django.shortcuts import render, redirect
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
|
|
@ -8,6 +9,7 @@ from django.utils.decorators import method_decorator
|
|||
from django.views.generic import DetailView, UpdateView
|
||||
from oauth2_provider.contrib.rest_framework import IsAuthenticatedOrTokenHasScope
|
||||
from rest_framework import generics, status, permissions
|
||||
from rest_framework.permissions import AllowAny
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
|
||||
|
|
@ -40,18 +42,16 @@ class UserDetailView(generics.RetrieveAPIView):
|
|||
}
|
||||
|
||||
class UserCurrentAvatarUrlView(generics.RetrieveAPIView):
|
||||
permission_classes = [IsAuthenticatedOrTokenMatchesOASRequirements]
|
||||
permission_classes = [AllowAny]
|
||||
queryset = User.objects.all()
|
||||
# serializer_class = PublicUserSerializer
|
||||
lookup_field = 'uuid'
|
||||
required_alternate_scopes = {
|
||||
"GET": [["accounts.profile:retrieve"]],
|
||||
}
|
||||
|
||||
def retrieve(self, request, *args, **kwargs):
|
||||
user: User = self.get_object()
|
||||
return redirect(user.avatar.url)
|
||||
# Response(serializer.data)
|
||||
if user.avatar:
|
||||
return redirect(user.avatar.url)
|
||||
else:
|
||||
raise Http404()
|
||||
|
||||
|
||||
class AccountView(generics.RetrieveUpdateAPIView):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue