-
Notifications
You must be signed in to change notification settings - Fork 280
Compute license audit task results during publish workflow #5665
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
base: unstable
Are you sure you want to change the base?
Compute license audit task results during publish workflow #5665
Conversation
AlexVelezLl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @taoerman! Just found a couple of things out of scope
| # 5) Repeat! | ||
| deploy-migrate: | ||
| echo "Nothing to do here!" | ||
| python contentcuration/manage.py backfill_channel_license_audits |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, we don't need to run this migration in the scope of this PR, we will handle it in #5593! 👐
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that we are getting this data from the versionDetail object, we can just remove this whole composable, and extract the information directly on the SubmitToCommunityLibrary side panel component.
| const loading = unref(isLoadingRef); | ||
| if (typeof loading === 'boolean') { | ||
| return loading; | ||
| } | ||
| return !unref(versionDetailRef); | ||
| }), | ||
| isFinished: computed(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we won't need to care about isLoading anymore, as this is the same loading variable than the one we load in the general loading data state.
| includedLicenses, | ||
| checkAndTriggerAudit: checkAndTriggerLicenseAudit, | ||
| } = useLicenseAudit(props.channel, currentChannelVersion); | ||
| } = useLicenseAudit(versionDetail, publishedDataIsLoading, publishedDataIsFinished); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove this call, and compute invalidLicenses and includedLicenses directly here; we won't need the licenseAuditIsLoading and licenseAuditIsFinished properties anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove this command; we will handle this more broadly in #5593
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, after we remove this, we can remove the audit_channel_licenses.py module too!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, apologies for the misdirection, we had already changed the name of these propoerties, so we can keep with the non_distributable_licenses_included and special_permissions_included identifiers! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can revert these changes after reverting the model field renames. Apologies for the confusion 😓
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idem, just flagging that we will also need to revert the rename in this file too.
| channel_version = ChannelVersion.objects.filter( | ||
| id=channel.version_info.id | ||
| ).first() | ||
|
|
||
| if not version_data: | ||
| if not channel_version: | ||
| return Response({}) | ||
|
|
||
| return Response(version_data) | ||
|
|
||
| @action( | ||
| detail=True, | ||
| methods=["post"], | ||
| url_path="audit_licenses", | ||
| url_name="audit-licenses", | ||
| ) | ||
| def audit_licenses(self, request, pk=None) -> Response: | ||
| """ | ||
| Trigger license audit for a channel's community library submission. | ||
| This will check for invalid licenses (All Rights Reserved) and special | ||
| permissions licenses, and update the channel's published_data with audit results. | ||
|
|
||
| :param request: The request object | ||
| :param pk: The ID of the channel | ||
| :return: Response with task_id if task was enqueued | ||
| :rtype: Response | ||
| """ | ||
| channel = self.get_edit_object() | ||
|
|
||
| if not channel.main_tree.published: | ||
| raise ValidationError("Channel must be published to audit licenses") | ||
|
|
||
| async_result = audit_channel_licenses_task.fetch_or_enqueue( | ||
| request.user, channel_id=channel.id, user_id=request.user.id | ||
| ) | ||
| version_data = { | ||
| "id": channel_version.id, | ||
| "version": channel_version.version, | ||
| "resource_count": channel_version.resource_count, | ||
| "kind_count": channel_version.kind_count, | ||
| "size": channel_version.size, | ||
| "date_published": channel_version.date_published, | ||
| "version_notes": channel_version.version_notes, | ||
| "included_languages": channel_version.included_languages, | ||
| "included_licenses": channel_version.included_licenses, | ||
| "included_categories": channel_version.included_categories, | ||
| "non_distributable_included_licenses": ( | ||
| channel_version.non_distributable_included_licenses | ||
| ), | ||
| "included_special_permissions": list( | ||
| channel_version.included_special_permissions.values_list( | ||
| "id", flat=True | ||
| ) | ||
| ), | ||
| } | ||
|
|
||
| return Response({"task_id": async_result.task_id}) | ||
| return Response(version_data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, the way we managed the .values was on purpose. We won't usually need the included_special_permissions, and this may bring too much data, so it'll be better to request these separately with the SpecialPermissionsViewset, so we can just remove this for now, and rely on the SpecialPermissionsViewset request to get this data! Therefore, we can just revert these changes to keep the .values call.
Summary
Move license audit computation into publish flow and store results on ChannelVersion with new field names.
Remove the async audit task, audit endpoint, and published_data usage; update version detail response accordingly.
Add backfill management command for existing published channels and wire it into deploy-migrate.
References
Fixed #5568
Reviewer guidance
Run tests