Repository navigation
Check the video before the analytics and engagement routes answer for it - #2249
Conversation
🔍 WordPress Plugin Check Report
📊 Report
|
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
0 |
mismatched_plugin_name | Plugin name "GoDAM - Video Hosting for LMS & Online Courses" is different from the name declared in plugin header "GoDAM". |
📁 assets/build/css/main.css (1 warning)
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
0 |
EnqueuedStylesScope | This style is being loaded in all contexts. |
📁 assets/src/libs/analytics.min.js (5 warnings)
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
0 |
EnqueuedScriptsScope | This script is being loaded in all frontend contexts. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880 (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880/2026/11/03/hello-world/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880/sample-page/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880/demo-attachment-post/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead. |
📁 assets/build/js/main.min.js (5 warnings)
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
0 |
EnqueuedScriptsScope | This script is being loaded in all frontend contexts. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880 (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880/2026/11/03/hello-world/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880/sample-page/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880/demo-attachment-post/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead. |
🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check
Analytics: the fetch, history and layer-analytics routes still need the `upload_files` capability and now also need the video to be an attachment of this site that the user can edit, which is what the Media Editor asks before it opens a video. Editors and administrators can edit every attachment, so for them nothing changes; an author reads the analytics of their own videos. Engagement: the video ID the player sends is turned into a GoDAM Central job ID only through an attachment of this site, never taken from the request. A numeric ID is an attachment ID, and `cmmid_<job>` stands for the attachment that carries that job ID. - Reading a video's likes, comments and views, and recording a like or a comment, work only for an attachment that is publicly viewable or that the current user may read. - Reading any other video gives what a video nobody has engaged with gives, and neither Central nor the analytics service is called. Liking or commenting on it is answered with a 403 and nothing is sent. - Deleting or editing a comment finds its job the same way, and still only for the signed-in user's own comments. Tests cover the route permissions per capability and per video, the video lookup, and each engagement route for a public video, a video the user cannot read, another site's job ID, and IDs that are not attachments.
b1d6e87 to
4519faf
Compare
|
Rebased onto
|
Likes, comments and views now follow the same rule as GoDAM's other public routes. A video uploaded while drafting one post and used on a published page counts as public, so its likes and comments show to visitors. The check runs after the job lookup closes, because the helper brackets its own attachment lookup; the hooks stay in pairs and are never nested.
Code reviewResolving the job ID only through an attachment of this site (never trusting the A few things to check: 1. Cost of the lookup on a public, unauthenticated route ( 2. Non-numeric 3. Behaviour change for authors 4. Shape of the “no engagement” response ( 5. Nit Review drafted with Claude. |
The analytics routes now refuse a video the user cannot edit (403), and the Analytics page showed that as "Analytics is temporarily unavailable". It now shows that analytics is only shown for videos you can edit, through the new AnalyticsForbiddenNotice, and keeps the unavailable notice for real outages. Addresses review: #2249 (comment)
|
@rudrakshi-gupta on your comment: 1. Checked, and core already does both. With 2. Checked: every route behind 3. Agreed, fixed in d81682f. When the analytics route refuses the video (403), the page now says "You can't view analytics for this video. Analytics is shown only for videos you can edit." instead of the temporarily-unavailable notice, which stays for real outages. 4. Checked: the player reads it as 5. Checked, and the order can't change the answer. For a |
rudrakshi-gupta
left a comment
There was a problem hiding this comment.
Re-reviewed: the replies check out (core validates video_id as numeric before the permission callback runs, so the absint concern doesn't apply), and d81682f's forbidden notice looks good. LGTM.
Optional nit, non-blocking: isAnalyticsForbidden() matches any 403, but WordPress also returns 403 for an expired REST nonce (rest_cookie_invalid_nonce). After a long-idle tab an Editor would see "You can't view analytics for this video" instead of a reload prompt. Checking error?.data?.code === 'rest_forbidden' would keep the two apart.
Review drafted with Claude.
What changes
Analytics (
inc/classes/rest-api/class-analytics.php): the fetch, history and layer-analytics routes still needupload_files, and now also need the requested video to be an attachment of this site that the user can edit (can_read_video_analytics()), which is what the Media Editor asks before it opens a video. Editors and Administrators can edit every attachment, so nothing changes for them; an Author reads the analytics of their own videos.Engagement (
inc/classes/rest-api/class-engagement.php): the video the player sends is turned into a GoDAM Central job ID only through an attachment of this site, never taken from the request. A numeric ID is an attachment ID;cmmid_<job>stands for the attachment that carries that job (rtgodam_transcoding_job_idor_godam_original_id).rtgodam_can_view_attachment(), the same rule as GoDAM's other public routes (get_visible_transcoder_job_id()). A video uploaded while drafting one post and used on a published page counts as public, so its likes and comments still show.video_not_availableand nothing is sent.Before merging
Done: the switch to
rtgodam_can_view_attachment()(from #2245, now indevelop) is in4dbd3d1. That helper brackets its own attachment lookup, so it runs after the job lookup closes and the lookup hooks are never nested. A new test,test_video_used_on_a_public_page_is_answered, fails on the earlier check and passes now. The Playground results below were run before the switch; the unit tests cover the change.Testing
Throwaway WordPress (Playground; PHP 7.4 + WordPress 6.8 and PHP 8.5 + WordPress 7.1, same results) with the 2.5.0 release plus these files; Central and the analytics service stubbed.
cmmid_)EngagementVideoScopeTest(39 cases) plus updates toAnalyticsRoutePermissionTest,EngagementCommentPrivacyTestandSiteOriginTest; full suite OK (658 tests).AnalyticsForbiddenNotice.test.js(the 403 check and the notice text).phpcsclean;bin/hook-checkchecks pass.Before and after
An Author opens Single Video Analytics for their own video (left) and for a video an Administrator uploaded (right), on godam-dev.local in headless Chrome. This site's analytics service is not running, so the left pane is a real outage: it must keep the "temporarily unavailable" notice. Each step's check is in the caption bar.
▶ Video (8 s): before the fix, at
4dbd3d1. The refused video (403) shows the same "Analytics is temporarily unavailable" notice as the outage.▶ Play the video
▶ Video (11 s): after the fix, at
d81682f. Same steps. The outage still shows "temporarily unavailable"; the refused video (403) shows "You can't view analytics for this video."▶ Play the video
The refused video, before and after (step 3 of each recording; the route answered 403
rest_forbiddenboth times):Not covered here: an Author's own video showing real analytics data, because this site's analytics service is not running. The route side (200 for the Author's own video, 403 for another user's) is in
AnalyticsRoutePermissionTest.Changelog
Worth knowing
cmmid_video with no local attachment (an embed that never went through the GoDAM tab) shows no engagement and refuses likes and comments.rtgodam_enable_engagement_feature(off by default), but the routes are registered on every connected site.QA:
Issue: rtCamp/godam-plugin-wp#77