Skip to content
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

Videopress: Request upload token with correct user #39796

Open
wants to merge 7 commits into
base: trunk
Choose a base branch
from

Conversation

vykes-mac
Copy link
Contributor

@vykes-mac vykes-mac commented Oct 17, 2024

Fixes Automattic/wp-calypso#72900

Proposed changes:

Currently the generated token use for uploading videos does not take the user uploading the video into account but always use the blog owner as the user. This causes the blog owner to be attached as the author for every video that's uploaded. This affects audits as the activity log shows incorrect author on the video upload. See the issue for more information

  • Send the user requesting the upload token so that the upload token endpoint returns the correct user token.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Does this pull request change what data or activity we track or use?

Testing instructions:

  • You will need to apply this diff D165318-code to your sandbox.
  • On your Atomic site add another user B who is not the blog owner
  • User Jetpack Beta tester to apply this branch to your site.
  • Upload a video with User B and verify that the correct author attached to the video is User B
  • Do the same with User A or blog owner and verify the same
  • Also verify that the activity log is showing the correct user that uploads the video

image

Copy link
Contributor

github-actions bot commented Oct 17, 2024

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Choose a review path based on your changes:
    • A. Team Review: add the "[Status] Needs Team Review" label
      • For most changes, including minor cross-team impacts.
      • Example: Updating a team-specific component or a small change to a shared library.
    • B. Crew Review: add the "[Status] Needs Review" label
      • For significant changes to core functionality.
      • Example: Major updates to a shared library or complex features.
    • C. Both: Start with Team, then request Crew
      • For complex changes or when you need extra confidence.
      • Example: Refactor affecting multiple systems.
  3. Get at least one approval before merging.

Still unsure? Reach out in #jetpack-developers for guidance!

Copy link
Contributor

github-actions bot commented Oct 17, 2024

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin, and enable the update/get-upload-token-for-user branch.

  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack update/get-upload-token-for-user
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@vykes-mac vykes-mac changed the title Update/get upload token for user Videopress: Request upload token with correct user Nov 1, 2024
@vykes-mac vykes-mac marked this pull request as ready for review November 1, 2024 22:56
@vykes-mac vykes-mac self-assigned this Nov 1, 2024
@vykes-mac vykes-mac added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. [Status] Needs Team Review labels Nov 1, 2024
Copy link
Member

@p-jackson p-jackson left a comment

Choose a reason for hiding this comment

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

I'm not super familiar with VideoPress so I've been playing around with it and reading the docs to figure out how it's supposed to work.

Upload a video with User B and verify that the correct author attached to the video is User B

VideoPress seems to change the concept of an uploaded media file belonging to a particular user. The docs mention special considerations about roles (only admins can properly manage videos), and if you look at the VideoPress dashboard at /wp-admin/admin.php?page=jetpack-videopress it doesn't mention anything about the "owner" of a piece of media—unlike the usual media gallery.

No owner info here
CleanShot 2024-11-04 at 23 04 00@2x

And no owner info here
CleanShot 2024-11-04 at 23 04 35@2x

Unlike videos uploaded without VideoPress
CleanShot 2024-11-04 at 23 11 21@2x

That's because I believe VideoPress keeps your media files elsewhere; off your site. You can confirm this with a call to wp post list --post_type=attachment . The CDN where we keep videos mustn't have finegrained ownership metadata.

So I think the idea from #72900 of trying to correct the metadata so it has the "correct" owner isn't the right approach. It doesn't seem compatible with VideoPress.
We can of course still have the activity log record the user who does the uploading correctly. But in that case maybe we should keep using the JETPACK__ANY_USER_TOKEN to do the upload and then find a way to record the activity log correctly as an independent thing.

@@ -205,8 +205,7 @@ public function wp_ajax_videopress_get_upload_token() {
);

$endpoint = "sites/{$video_blog_id}/media/token";
$result = Client::wpcom_json_api_request_as_blog( $endpoint, Client::WPCOM_JSON_API_VERSION, $args );

$result = Client::wpcom_json_api_request_as_blog( $endpoint, Client::WPCOM_JSON_API_VERSION, $args, array( 'external_user_id' => get_current_user_id() ) );
Copy link
Member

Choose a reason for hiding this comment

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

I left a comment on D165318-code for why this external_user_id isn't always going to be enough to generate a user-specific token.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to pass that external_user_id property? There's an already existing Client::wpcom_json_api_request_as_user method we can use to pass the user id.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we need to pass that external_user_id property? There's an already existing Client::wpcom_json_api_request_as_user method we can use to pass the user id.

For some reason when this function is used it fails with error You must be logged-in to get an upload token , I suspect because the upload endpoint is an older endpoint it might need some additional configuration for it to work. wanted to get eyes on the PR for discussion so didn't look into it too much. can revisit it.

@vykes-mac
Copy link
Contributor Author

That's because I believe VideoPress keeps your media files elsewhere; off your site. You can confirm this with a call to wp post list --post_type=attachment . The CDN where we keep videos mustn't have finegrained ownership metadata.

So I think the idea from #72900 of trying to correct the metadata so it has the "correct" owner isn't the right approach. It doesn't seem compatible with VideoPress.
We can of course still have the activity log record the user who does the uploading correctly. But in that case maybe we should keep using the JETPACK__ANY_USER_TOKEN to do the upload and then find a way to record the activity log correctly as an independent thing.

If I'm understanding you correctly the metadata we are referencing here is not necessarily the video metadata but the post meta data.

When a video is uploaded a post type attachment is created on the jetpack site using Jetpack_Media_Sync::upload_media That is the information displayed here
image

The user token is used for that xml_rpc call to create the attachment on the jetpack blog. This way the correct author is associated with the creation of the attachment post_type and not so much the videopress video metadata.

Hope we are on the same page 😅

@jeherve jeherve requested a review from a team November 5, 2024 10:12
@jeherve jeherve added [Feature] VideoPress A feature to help you upload and insert videos on your site. [Type] Bug When a feature is broken and / or not performing as intended labels Nov 5, 2024
@jeherve
Copy link
Member

jeherve commented Nov 5, 2024

Related: #39034

@CGastrell
Copy link
Contributor

CGastrell commented Nov 21, 2024

Thanks for taking the time to dig into this!

At this point you know better what the flows are and if you feel this is the right approach, I'll trust you with it. That said, I can only think about what this means in terms of licensing: a user paying for VP immediately attaches the license to a blog and allows all (capable) users to upload videos. I do like this, just noting that we need to be able to track down users (or uploads) by a given token that, in turn, can be tracked down to the license owner. Not a problem, just something to keep in mind.

@vykes-mac if you update (merge or rebase) I'll give it one last spin, but I also encourage you to go forth and try to super test this with as many edge cases as you can think of :) Ping me!

@vykes-mac
Copy link
Contributor Author

@CGastrell I did a rebase, you can perform some test!

@CGastrell
Copy link
Contributor

CGastrell commented Nov 25, 2024

@CGastrell I did a rebase, you can perform some test!

Testing from an AT site running this build, I'm getting very mixed results. Simply editing a post and uploading a video produces the wrong activity author and then some bunch of follow up activities, also with mixed authors:

This was a single video upload with user B (later seen as yabranh), but the activity claims I did it with user A (cgastrell):
image

When that "multiple users" thing is uncollapsed, I see this:
image
image

Anything I might have done wrong? Is this expected @vykes-mac ?

@vykes-mac
Copy link
Contributor Author

@CGastrell I did a rebase, you can perform some test!

Testing from an AT site running this build, I'm getting very mixed results. Simply editing a post and uploading a video produces the wrong activity author and then some bunch of follow up activities, also with mixed authors:

This was a single video upload with user B (later seen as yabranh), but the activity claims I did it with user A (cgastrell):

image

When that "multiple users" thing is uncollapsed, I see this:

image image

Anything I might have done wrong? Is this expected @vykes-mac ?

Interesting 🤔, I know there are some thumbnails generated when uploading a video that will be logged as the primary owner but the video upload itself should be logged as uploaded by user B. The accompanied diff is applied to your sandbox ?

@CGastrell
Copy link
Contributor

The accompanied diff is applied to your sandbox ?

Yes.

@kraftbj kraftbj added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. [Status] Needs Team Review labels Dec 12, 2024
@kraftbj
Copy link
Contributor

kraftbj commented Dec 12, 2024

Removing this out of the review queue. @vykes-mac - I've updated the branch to trunk. Can you get this back around to the team for review (if ready) etc? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] VideoPress A feature to help you upload and insert videos on your site. [Package] VideoPress [Status] In Progress [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! [Type] Bug When a feature is broken and / or not performing as intended
Projects
None yet
6 participants