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

Limit video uploads on free sites #17689

Merged
merged 21 commits into from
Dec 21, 2021

Conversation

Gio2018
Copy link
Contributor

@Gio2018 Gio2018 commented Dec 20, 2021

This PR prevents videos longer than 5 minutes to be uploaded on free sites. This applies to captured or selected videos from:

  • My Site - Media
  • Editor (posts and pages)
  • Stories

Notes:

  • Video upload from "Other Apps" was already disabled, for videos of any duration, before this PR
  • On Stories, there was an existing video limit of 29 seconds: this has not been changed

Fixes #NA

To test:

Pre requisites:

  • make sure to have local files both on device and from other apps (e.g Files) videos that are longer than 5 minutes.
  • Tip: to use shorter videos (this is particularly useful when testing the capture), you can temporary tweak the following code (WPMediaAsset+VideoLimits.swift)
    let maximumVideoDurationForFreeSites: CGFloat = 300
    choosing a shorter value than 5 minutes (e.g. 5 seconds)
  1. Go to My site and make sure to select a site with a free plan
  2. Go to Media
  3. Tap on the + (top right corner)
  4. Tap on "Take Photo or Video"
  5. Record a video longer that the maximum allowed duration
  6. Tap on "Use video"
  7. Make sure the "Video not uploaded" (see screenshot below) alert is shown, and no video is added to the media library
  8. Record a video shorter than the maximum allowed duration, and make sure it can be uploaded instead.
  9. Tap on + again
  10. Tap on "Choose from My Device"
  11. Make sure that videos longer than the maximum allowed duration are greyed out and cannot be selected. Also, make sure that the "Selection not allowed" alert appears (see screenshot below)
  12. Optional (this was not changed in this PR): tap on "Other apps", and make sure that video files (of any duration) are still greyed out and cannot be uploaded.
  13. Go back and tap on the blue Floating Action Button (FAB)
  14. Select "Story Post"
  15. Tap on the icon in the lower left corner and repeat step 11
  16. Optional (this was not changed in this PR): record a story video and make sure the max duration of 29 seconds applies
  17. Go back and either tap again on the FAB and then "Blog Post" to create a new post, or edit an existing post from the "Posts" section
  18. Repeat steps 4 to 12 (you can either add multiple video blocks or tap "Add Video" on a video block that has no media yet, to display the selection options)
  19. Go back and either create a new page from the FAB or edit an existing one from the "Pages" section
  20. Repeat step 18
  21. Repeat the steps 2 to 20 on a paid site, and make sure you can upload videos of any duration
Captured video too long Selected video too long Choose video
!

Regression Notes

  1. Potential unintended areas of impact
    Limited impact: these changes impact the video upload sections in media, Gutenberg and Stories

  2. What I did to test those areas of impact (or what existing automated tests I relied on)
    Test all the impacted cases, both with free and paid plans

  3. What automated tests I added (or what prevented me from doing so)
    None

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding unit tests for my changes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

Giorgio Ruscigno added 13 commits December 16, 2021 12:10
…a does not exceed video limit duration, if it's a video
…a do not exceed video limit duration, if it's a video
…o exceeds the allowed duration on free sites
…videos that cannot be selected in the media picker
…do not exceed allowed duration on free sites
…new video limits for free sites to WP Stories
@peril-wordpress-mobile
Copy link

peril-wordpress-mobile bot commented Dec 20, 2021

You can trigger an installable build for these changes by visiting CircleCI here.

@peril-wordpress-mobile
Copy link

peril-wordpress-mobile bot commented Dec 20, 2021

You can trigger optional UI/connected tests for these changes by visiting CircleCI here.

Copy link
Contributor

@frosty frosty left a comment

Choose a reason for hiding this comment

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

For the most part, this is working really well! I tested across the Media library, blog post editor, and stories editor. I'm seeing one issue where I think the logic is wrong where we're using a guard statement, which wouldn't let me upload a video to my paid blog.

My other main comment is that we're duplicating a snippet of logic across many places to check if we can upload an asset, so perhaps we should extract that somewhere central.

The newly added files also need adding to the Jetpack target, as it's currently failing to build.

/// - Parameters:
/// - viewController: presenting UIViewController
/// - title: title of the alert
private func persentVideoLimitsAlert(on viewController: UIViewController, title: String) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick, typo: persent -> present

extension GutenbergMediaPickerHelper: WPMediaPickerViewControllerDelegate {

func mediaPickerController(_ picker: WPMediaPickerViewController, didFinishPicking assets: [WPMediaAsset]) {
invokeMediaPickerCallback(asset: assets)
picker.dismiss(animated: true, completion: nil)
if picker == self.cameraPicker,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can omit all uses of self in this method.

Comment on lines 139 to 140
asset.exceedsFreeSitesAllowance() &&
!post.blog.hasPaidPlan
Copy link
Contributor

Choose a reason for hiding this comment

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

We're repeating this bit of logic in three places in this class – perhaps we should create a smaller helper method?

func canUploadAsset(_ asset: WPMediaAsset, for blog: Blog) -> Bool {
    asset.exceeedsFreeSitesAllowance() && !blog.hasPaidPlan
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Or thinking about it, we're using this same bit of logic across a whole range of classes multiple times. Perhaps we should move it onto Blog? canUploadAsset(_ asset: WPMediaAsset)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes perfect sense @frosty ! Only one minor change to the above snippet, I think the condition for a blog that can upload video assets should be (if we put it in Blog):

func canUploadAsset(_ asset: WPMediaAsset) -> Bool {
    hasPaidPlan || !asset.exceedsFreeSitesAllowance()
}

does it sound right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, that makes sense to me!

return
guard let media = media as? PHAsset,
!media.exceedsFreeSitesAllowance(),
!blog.hasPaidPlan else {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this logic isn't correct. I'm seeing a case where media is exceeding the free sizes allowance, but the blog has a paid plan, but I'm not allowed to upload it. We only want to present the limit if both the media exceeds the limit and the blog doesn't have a paid plan.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching this @frosty ! This is one more case where your suggestion to extract the canUploadAsset method comes in handy.

Giorgio Ruscigno added 4 commits December 20, 2021 11:02
@Gio2018 Gio2018 requested a review from frosty December 20, 2021 17:47
@Gio2018
Copy link
Contributor Author

Gio2018 commented Dec 20, 2021

Thanks for reviewing @frosty ! PR is ready for another pass, whenever you can.

Copy link
Contributor

@frosty frosty left a comment

Choose a reason for hiding this comment

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

Great changes! Just one small typo, and one question but otherwise let's :shipit:

@@ -0,0 +1,7 @@
extension Blog {

/// returns true if the blog is allowed upload the given asset, true otherwise
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick allowed _to_ upload
Also, false otherwise! :)

picker !== cameraPicker &&
asset.exceedsFreeSitesAllowance() &&
!post.blog.hasPaidPlan
!post.blog.canUploadAsset(asset)
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 still need to check if it's not the camera picker here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, thanks for catching this!!

@roundhill
Copy link
Contributor

Does this just check for the video length, or does it also check that the file size is less than 100MB? Reason I'm asking is that it is much easier for us to check the file size at the api endpoint rather than the file length, so it'd be good to tell the user in the app that their files should be under 100MB.

@Gio2018
Copy link
Contributor Author

Gio2018 commented Dec 21, 2021

Does this just check for the video length, or does it also check that the file size is less than 100MB? Reason I'm asking is that it is much easier for us to check the file size at the api endpoint rather than the file length, so it'd be good to tell the user in the app that their files should be under 100MB.

Hey @roundhill , we are only checking duration.

The main reason is that users can control duration much more than size, especially with newer devices allowing 4K videos. Potentially there could be shorter videos that exceed the size and longer ones that do not. Also, the current UI of both the media picker and the camera capture do not provide info about the size. This could probably be changed, but we'd need to investigate and do a separate project for this.

Giorgio Ruscigno added 3 commits December 20, 2021 18:18
@Gio2018 Gio2018 merged commit 3f8ba8f into develop Dec 21, 2021
@Gio2018 Gio2018 deleted the issue/limit-video-uploads-on-free-sites branch December 21, 2021 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants