|
45 | 45 | from pulp_rpm.app.tasks.signing import signed_add_and_remove |
46 | 46 |
|
47 | 47 |
|
48 | | -class RpmRepositoryViewSet(RepositoryViewSet, ModifyRepositoryActionMixin, RolesMixin): |
| 48 | +class RpmModifyRepositoryActionMixin(ModifyRepositoryActionMixin): |
| 49 | + modify_task = signed_add_and_remove |
| 50 | + |
| 51 | + @extend_schema( |
| 52 | + description="Trigger an asynchronous task to create a new repository version.", |
| 53 | + summary="Modify Repository Content", |
| 54 | + responses={202: AsyncOperationResponseSerializer}, |
| 55 | + ) |
| 56 | + @action(detail=True, methods=["post"], serializer_class=RepositoryAddRemoveContentSerializer) |
| 57 | + def modify(self, request, pk): |
| 58 | + add_content_units = request.data.get("add_content_units", []) |
| 59 | + package_ids = [extract_pk(href) for href in add_content_units if "/packages/" in href] |
| 60 | + repository = self.get_object() |
| 61 | + |
| 62 | + if add_content_units and repository.package_signing_service: |
| 63 | + ondemand_ca = ContentArtifact.objects.filter( |
| 64 | + content_id__in=package_ids, artifact__isnull=True |
| 65 | + ) |
| 66 | + if ondemand_ca.count() > 0: |
| 67 | + raise DRFValidationError( |
| 68 | + _("Cannot add on-demand content to repo with set package signing service.") |
| 69 | + ) |
| 70 | + |
| 71 | + return super().modify(request, pk) |
| 72 | + |
| 73 | + |
| 74 | +class RpmRepositoryViewSet(RepositoryViewSet, RpmModifyRepositoryActionMixin, RolesMixin): |
49 | 75 | """ |
50 | 76 | A ViewSet for RpmRepository. |
51 | 77 | """ |
@@ -249,49 +275,6 @@ def sync(self, request, pk): |
249 | 275 | ) |
250 | 276 | return OperationPostponedResponse(result, request) |
251 | 277 |
|
252 | | - @extend_schema( |
253 | | - description="Trigger an asynchronous task to create a new repository version.", |
254 | | - summary="Modify Repository Content", |
255 | | - responses={202: AsyncOperationResponseSerializer}, |
256 | | - ) |
257 | | - @action(detail=True, methods=["post"], serializer_class=RepositoryAddRemoveContentSerializer) |
258 | | - def modify(self, request, pk): |
259 | | - """ |
260 | | - Queues a task that creates a new RepositoryVersion by adding and removing content units |
261 | | -
|
262 | | - Also handles signing if the repo has a package signing service and fingerprint set. |
263 | | - """ |
264 | | - repository = self.get_object() |
265 | | - serializer = self.get_serializer(data=request.data) |
266 | | - serializer.is_valid(raise_exception=True) |
267 | | - |
268 | | - add_content_units = serializer.validated_data.get("add_content_units", []) |
269 | | - if add_content_units and repository.package_signing_service: |
270 | | - ondemand_ca = ContentArtifact.objects.filter( |
271 | | - content_id__in=add_content_units, artifact__isnull=True |
272 | | - ) |
273 | | - if ondemand_ca.count() > 0: |
274 | | - raise DRFValidationError( |
275 | | - _("Cannot add on-demand content to repo with set package signing service.") |
276 | | - ) |
277 | | - |
278 | | - if "base_version" in request.data: |
279 | | - base_version_pk = self.get_resource(request.data["base_version"], RepositoryVersion).pk |
280 | | - else: |
281 | | - base_version_pk = None |
282 | | - |
283 | | - task = dispatch( |
284 | | - signed_add_and_remove, |
285 | | - exclusive_resources=[repository], |
286 | | - kwargs={ |
287 | | - "repository_pk": pk, |
288 | | - "base_version_pk": base_version_pk, |
289 | | - "add_content_units": add_content_units, |
290 | | - "remove_content_units": serializer.validated_data.get("remove_content_units", []), |
291 | | - }, |
292 | | - ) |
293 | | - return OperationPostponedResponse(task, request) |
294 | | - |
295 | 278 |
|
296 | 279 | class RpmRepositoryVersionViewSet(RepositoryVersionViewSet): |
297 | 280 | """ |
|
0 commit comments