|
109 | 109 | DraftRegistrationDetailLegacySerializer, |
110 | 110 | NodeContributorsSerializer, |
111 | 111 | NodeContributorDetailSerializer, |
| 112 | + NodeContributorsUpdateSerializer, |
112 | 113 | NodeInstitutionsRelationshipSerializer, |
113 | 114 | NodeContributorsCreateSerializer, |
114 | 115 | NodeViewOnlyLinkSerializer, |
@@ -434,11 +435,16 @@ class NodeContributorsList(BaseContributorList, bulk_views.BulkUpdateJSONAPIView |
434 | 435 | def get_resource(self): |
435 | 436 | return self.get_node() |
436 | 437 |
|
| 438 | + def get_object(self): |
| 439 | + return self.get_node() |
| 440 | + |
437 | 441 | # overrides ListBulkCreateJSONAPIView, BulkUpdateJSONAPIView, BulkDeleteJSONAPIView |
438 | 442 | def get_serializer_class(self): |
439 | 443 | """ |
440 | 444 | Use NodeContributorDetailSerializer which requires 'id' |
441 | 445 | """ |
| 446 | + if self.request.method == 'PATCH' and self.request.query_params.get('copy_contributors_from_parent_project'): |
| 447 | + return NodeContributorsUpdateSerializer |
442 | 448 | if self.request.method == 'PUT' or self.request.method == 'PATCH' or self.request.method == 'DELETE': |
443 | 449 | return NodeContributorDetailSerializer |
444 | 450 | elif self.request.method == 'POST': |
@@ -499,6 +505,18 @@ def get_serializer_context(self): |
499 | 505 | context['default_email'] = 'default' |
500 | 506 | return context |
501 | 507 |
|
| 508 | + def patch(self, request, *args, **kwargs): |
| 509 | + """ |
| 510 | + Override the default patch behavior to handle the special case |
| 511 | + of updating contributors by copying contributors from the parent project. |
| 512 | + """ |
| 513 | + if request.query_params.get('copy_contributors_from_parent_project'): |
| 514 | + instance = self.get_object() |
| 515 | + serializer = self.get_serializer_class()(instance, data=request.data) |
| 516 | + serializer.is_valid(raise_exception=True) |
| 517 | + serializer.save() |
| 518 | + return Response(serializer.data, status=200) |
| 519 | + return super().patch(request, *args, **kwargs) |
502 | 520 |
|
503 | 521 | class NodeContributorDetail(BaseContributorDetail, generics.RetrieveUpdateDestroyAPIView, NodeMixin, UserMixin): |
504 | 522 | """The documentation for this endpoint can be found [here](https://developer.osf.io/#operation/nodes_contributors_read). |
|
0 commit comments