9
9
from django .shortcuts import get_object_or_404
10
10
from django .template .loader import render_to_string
11
11
from rest_framework import decorators , permissions , status , viewsets
12
+ from rest_framework .mixins import CreateModelMixin , UpdateModelMixin
12
13
from rest_framework .parsers import JSONParser , MultiPartParser
13
14
from rest_framework .renderers import BaseRenderer , JSONRenderer
14
15
from rest_framework .response import Response
21
22
from readthedocs .projects .models import Domain , Project
22
23
from readthedocs .storage import build_commands_storage
23
24
24
- from ..permissions import APIPermission , APIRestrictedPermission , IsOwner
25
+ from ..permissions import APIRestrictedPermission , IsOwner
25
26
from ..serializers import (
26
27
BuildAdminReadOnlySerializer ,
27
28
BuildAdminSerializer ,
@@ -117,14 +118,17 @@ def list(self, *args, **kwargs):
117
118
)
118
119
119
120
120
- class UserSelectViewSet (viewsets .ModelViewSet ):
121
+ class UserSelectViewSet (viewsets .ReadOnlyModelViewSet ):
121
122
122
123
"""
123
124
View set that varies serializer class based on request user credentials.
124
125
125
126
Viewsets using this class should have an attribute `admin_serializer_class`,
126
127
which is a serializer that might have more fields that only admin/staff
127
128
users require. If the user is staff, this class will be returned instead.
129
+
130
+ By default read-only endpoints will be allowed,
131
+ to allow write endpoints, inherit from the proper ``rest_framework.mixins.*`` classes.
128
132
"""
129
133
130
134
def get_serializer_class (self ):
@@ -143,11 +147,11 @@ def get_queryset(self):
143
147
return self .model .objects .api (self .request .user )
144
148
145
149
146
- class ProjectViewSet (DisableListEndpoint , UserSelectViewSet ):
150
+ class ProjectViewSet (DisableListEndpoint , UpdateModelMixin , UserSelectViewSet ):
147
151
148
152
"""List, filter, etc, Projects."""
149
153
150
- permission_classes = [APIPermission ]
154
+ permission_classes = [APIRestrictedPermission ]
151
155
renderer_classes = (JSONRenderer ,)
152
156
serializer_class = ProjectSerializer
153
157
admin_serializer_class = ProjectAdminSerializer
@@ -196,7 +200,7 @@ def canonical_url(self, request, **kwargs):
196
200
})
197
201
198
202
199
- class VersionViewSet (DisableListEndpoint , UserSelectViewSet ):
203
+ class VersionViewSet (DisableListEndpoint , UpdateModelMixin , UserSelectViewSet ):
200
204
201
205
permission_classes = [APIRestrictedPermission ]
202
206
renderer_classes = (JSONRenderer ,)
@@ -209,7 +213,7 @@ class VersionViewSet(DisableListEndpoint, UserSelectViewSet):
209
213
)
210
214
211
215
212
- class BuildViewSet (DisableListEndpoint , UserSelectViewSet ):
216
+ class BuildViewSet (DisableListEndpoint , UpdateModelMixin , UserSelectViewSet ):
213
217
permission_classes = [APIRestrictedPermission ]
214
218
renderer_classes = (JSONRenderer , PlainTextBuildRenderer )
215
219
model = Build
@@ -297,7 +301,7 @@ def reset(self, request, **kwargs):
297
301
return Response (status = status .HTTP_204_NO_CONTENT )
298
302
299
303
300
- class BuildCommandViewSet (DisableListEndpoint , UserSelectViewSet ):
304
+ class BuildCommandViewSet (DisableListEndpoint , CreateModelMixin , UserSelectViewSet ):
301
305
parser_classes = [JSONParser , MultiPartParser ]
302
306
permission_classes = [APIRestrictedPermission ]
303
307
renderer_classes = (JSONRenderer ,)
0 commit comments