Skip to content

Conversation

@taoerman
Copy link
Member

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

@AlexVelezLl AlexVelezLl self-assigned this Jan 27, 2026
Copy link
Member

@AlexVelezLl AlexVelezLl left a 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
Copy link
Member

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! 👐

Copy link
Member

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.

Comment on lines +33 to +39
const loading = unref(isLoadingRef);
if (typeof loading === 'boolean') {
return loading;
}
return !unref(versionDetailRef);
}),
isFinished: computed(() => {
Copy link
Member

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);
Copy link
Member

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.

Copy link
Member

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

Copy link
Member

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!

Copy link
Member

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! :)

Copy link
Member

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 😓

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

Copy link
Member

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.

Comment on lines +903 to +931
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)
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compute license audit task results during publish workflow

2 participants