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

First draft of the apps API #3361

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions bookwyrm/api/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from bookwyrm.models import User
from django.urls import include, path
from django.contrib import admin
from rest_framework import routers, viewsets, generics, permissions, serializers
admin.autodiscover()


# Serializers define the API representation.
class UserSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
permission_classes = [permissions.IsAuthenticated]
model = User
fields = ["url", "username", "email", "is_staff"]


# ViewSets define the view behavior.
class UserViewSet(viewsets.ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer



# Routers provide a way of automatically determining the URL conf.
router = routers.DefaultRouter()
router.register(r"v1/users", UserViewSet)
# router.register(r"v1/apps", AppViewSet)
# client_name, redirect_uris, scopes, website
# router.register(r"v1/apps/verify_credentials", AppViewSet)

# Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browsable API.
urlpatterns = [
path("", include(router.urls)),
path("api-auth/", include("rest_framework.urls", namespace="rest_framework")),
]
17 changes: 17 additions & 0 deletions bookwyrm/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.humanize",
"rest_framework",
"oauth2_provider",
"file_resubmit",
"sass_processor",
Expand Down Expand Up @@ -146,6 +147,22 @@
},
]

REST_FRAMEWORK = {
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
"DEFAULT_PERMISSION_CLASSES": [
# Somehow it does not work with OAuth enabled
# 'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
"rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly",
'rest_framework.permissions.IsAuthenticated',
]
}

OAUTH2_PROVIDER = {
# this is the list of available scopes
'SCOPES': {'read': 'Read scope', 'write': 'Write scope', 'groups': 'Access to your groups'}
}

LOG_LEVEL = env("LOG_LEVEL", "INFO").upper()
# Override aspects of the default handler to our taste
# See https://docs.djangoproject.com/en/3.2/topics/logging/#default-logging-configuration
Expand Down
1 change: 1 addition & 0 deletions bookwyrm/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,7 @@
),
path("guided-tour/<tour>", views.toggle_guided_tour),
re_path(r"^o/", include("oauth2_provider.urls", namespace="oauth2_provider")),
re_path(r"^api/", include("bookwyrm.api.urls")),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

# Serves /static when DEBUG is true.
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ django-csp==3.7
django-imagekit==4.1.0
django-model-utils==4.3.1
django-oauth-toolkit==2.3.0
djangorestframework==3.15.1
django-pgtrigger==4.11.0
django-redis==5.2.0
django-sass-processor==1.2.2
Expand Down
Loading