Skip to content

Commit 5759e04

Browse files
authored
Merge pull request #18414 from wordpress-mobile/issue/18277-video-length-restrictions
Video length restrictions are not applicable to self hosted sites
2 parents 2bfb8ee + 5612535 commit 5759e04

5 files changed

Lines changed: 76 additions & 9 deletions

File tree

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
19.8
22
-----
3+
* [**] Self hosted sites are not restricted by video length during media uploads [https://github.com/wordpress-mobile/WordPress-iOS/pull/18414]
34
* [*] [internal] My Site Dashboard: Made some changes to the code architecture of the dashboard. The majority of the changes are related to the posts cards. It should have no visible changes but could cause regressions. Please test it by creating/trashing drafts and scheduled posts and testing that they appear correctly on the dashboard. [#18405]
45
* [*] [internal] Quick Start: Refactored some code related to the tasks displayed in the Quick Start Card and the Quick Start modal. It should have no visible changes but could cause regressions. [#18395]
56

WordPress/Classes/Services/Stories/WPMediaPicker+MediaPicker.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class WPMediaPickerForKanvas: WPNavigationMediaPickerViewController, MediaPicker
5252

5353
let mediaPickerDelegate = MediaPickerDelegate(kanvasDelegate: delegate,
5454
presenter: tabBar,
55-
shouldDisableLongVideos: !blog.hasPaidPlan)
55+
blog: blog)
5656
let options = WPMediaPickerOptions()
5757
options.allowCaptureOfMedia = false
5858

@@ -85,17 +85,15 @@ class MediaPickerDelegate: NSObject, WPMediaPickerViewControllerDelegate {
8585

8686
private weak var kanvasDelegate: KanvasMediaPickerViewControllerDelegate?
8787
private weak var presenter: UIViewController?
88-
89-
private let shouldDisableLongVideos: Bool
90-
88+
private let blog: Blog
9189
private var cancellables = Set<AnyCancellable>()
9290

9391
init(kanvasDelegate: KanvasMediaPickerViewControllerDelegate,
9492
presenter: UIViewController,
95-
shouldDisableLongVideos: Bool = false) {
93+
blog: Blog) {
9694
self.kanvasDelegate = kanvasDelegate
9795
self.presenter = presenter
98-
self.shouldDisableLongVideos = shouldDisableLongVideos
96+
self.blog = blog
9997
}
10098

10199
func mediaPickerControllerDidCancel(_ picker: WPMediaPickerViewController) {
@@ -175,7 +173,7 @@ class MediaPickerDelegate: NSObject, WPMediaPickerViewControllerDelegate {
175173
}
176174

177175
func mediaPickerController(_ picker: WPMediaPickerViewController, shouldShowOverlayViewForCellFor asset: WPMediaAsset) -> Bool {
178-
picker != self && asset.exceedsFreeSitesAllowance() && shouldDisableLongVideos
176+
picker != self && !blog.canUploadAsset(asset)
179177
}
180178

181179
func mediaPickerControllerShouldShowCustomHeaderView(_ picker: WPMediaPickerViewController) -> Bool {
@@ -209,7 +207,7 @@ class MediaPickerDelegate: NSObject, WPMediaPickerViewControllerDelegate {
209207
}
210208

211209
func mediaPickerController(_ picker: WPMediaPickerViewController, shouldSelect asset: WPMediaAsset) -> Bool {
212-
if picker != self, asset.exceedsFreeSitesAllowance(), shouldDisableLongVideos {
210+
if picker != self, !blog.canUploadAsset(asset) {
213211
presentVideoLimitExceededFromPicker(on: picker)
214212
return false
215213
}

WordPress/Classes/Utility/Media/Blog+VideoLimits.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ extension Blog {
22

33
/// returns true if the blog is allowed to upload the given asset, true otherwise
44
func canUploadAsset(_ asset: WPMediaAsset) -> Bool {
5-
hasPaidPlan || !asset.exceedsFreeSitesAllowance()
5+
return canUploadAsset(asset.exceedsFreeSitesAllowance())
6+
}
7+
8+
public func canUploadAsset(_ assetExceedsFreeSitesAllowance: Bool) -> Bool {
9+
return hasPaidPlan || !isHostedAtWPcom || !assetExceedsFreeSitesAllowance
610
}
711
}

WordPress/WordPress.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,6 +2419,7 @@
24192419
DC8F61F727032B3F0087AC5D /* TimeZoneFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC8F61F627032B3F0087AC5D /* TimeZoneFormatter.swift */; };
24202420
DC8F61F827032B3F0087AC5D /* TimeZoneFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC8F61F627032B3F0087AC5D /* TimeZoneFormatter.swift */; };
24212421
DC8F61FC2703321F0087AC5D /* TimeZoneFormatterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC8F61FB2703321F0087AC5D /* TimeZoneFormatterTests.swift */; };
2422+
DCC662512810915D00962D0C /* BlogVideoLimitsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCC662502810915D00962D0C /* BlogVideoLimitsTests.swift */; };
24222423
E100C6BB1741473000AE48D8 /* WordPress-11-12.xcmappingmodel in Sources */ = {isa = PBXBuildFile; fileRef = E100C6BA1741472F00AE48D8 /* WordPress-11-12.xcmappingmodel */; };
24232424
E10290741F30615A00DAC588 /* Role.swift in Sources */ = {isa = PBXBuildFile; fileRef = E10290731F30615A00DAC588 /* Role.swift */; };
24242425
E102B7901E714F24007928E8 /* RecentSitesService.swift in Sources */ = {isa = PBXBuildFile; fileRef = E102B78F1E714F24007928E8 /* RecentSitesService.swift */; };
@@ -7182,6 +7183,7 @@
71827183
DC76668226FD9AC9009254DD /* TimeZoneTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TimeZoneTableViewCell.swift; sourceTree = "<group>"; };
71837184
DC8F61F627032B3F0087AC5D /* TimeZoneFormatter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimeZoneFormatter.swift; sourceTree = "<group>"; };
71847185
DC8F61FB2703321F0087AC5D /* TimeZoneFormatterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimeZoneFormatterTests.swift; sourceTree = "<group>"; };
7186+
DCC662502810915D00962D0C /* BlogVideoLimitsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlogVideoLimitsTests.swift; sourceTree = "<group>"; };
71857187
E100C6BA1741472F00AE48D8 /* WordPress-11-12.xcmappingmodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcmappingmodel; path = "WordPress-11-12.xcmappingmodel"; sourceTree = "<group>"; };
71867188
E10290731F30615A00DAC588 /* Role.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Role.swift; sourceTree = "<group>"; };
71877189
E102B78F1E714F24007928E8 /* RecentSitesService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecentSitesService.swift; sourceTree = "<group>"; };
@@ -8331,6 +8333,7 @@
83318333
FF8CD624214184EE00A33A8D /* MediaAssetExporterTests.swift */,
83328334
08F8CD3A1EBD2D020049D0C0 /* MediaURLExporterTests.swift */,
83338335
08E77F461EE9D72F006F9515 /* MediaThumbnailExporterTests.swift */,
8336+
DCC662502810915D00962D0C /* BlogVideoLimitsTests.swift */,
83348337
);
83358338
name = Media;
83368339
sourceTree = "<group>";
@@ -19489,6 +19492,7 @@
1948919492
73B6693A21CAD960008456C3 /* ErrorStateViewTests.swift in Sources */,
1949019493
8BD34F0927D144FF005E931C /* BlogDashboardStateTests.swift in Sources */,
1949119494
1759F1721FE017F20003EC81 /* QueueTests.swift in Sources */,
19495+
DCC662512810915D00962D0C /* BlogVideoLimitsTests.swift in Sources */,
1949219496
3F1AD48123FC87A400BB1375 /* BlogDetailsViewController+MeButtonTests.swift in Sources */,
1949319497
08F8CD3B1EBD2D020049D0C0 /* MediaURLExporterTests.swift in Sources */,
1949419498
D81C2F6220F89632002AE1F1 /* EditCommentActionTests.swift in Sources */,
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import XCTest
2+
3+
class BlogVideoLimitsTests: XCTestCase {
4+
5+
private var blog: Blog!
6+
private var contextManager: TestContextManager!
7+
private var context: NSManagedObjectContext!
8+
9+
override func setUpWithError() throws {
10+
contextManager = TestContextManager()
11+
context = contextManager.newDerivedContext()
12+
blog = NSEntityDescription.insertNewObject(forEntityName: "Blog", into: context) as? Blog
13+
blog.url = Constants.blogURL
14+
blog.xmlrpc = Constants.blogURL
15+
}
16+
17+
override func tearDownWithError() throws {
18+
blog = nil
19+
}
20+
21+
func testCanUploadAssetPaidPlan() throws {
22+
// Given a blog
23+
// When blog has a paid plan
24+
blog.hasPaidPlan = true
25+
26+
// Then it can upload assets irrespective of allowance
27+
XCTAssertTrue(blog.canUploadAsset(true))
28+
XCTAssertTrue(blog.canUploadAsset(false))
29+
}
30+
31+
func testCanUploadAssetWPCom() throws {
32+
// Given a blog
33+
// When blog is on WPCom and not paid
34+
blog.isHostedAtWPcom = true
35+
blog.hasPaidPlan = false
36+
37+
// Then it can upload assets when allowance not exceeded
38+
XCTAssertTrue(blog.canUploadAsset(false))
39+
40+
// Then it cannot upload assets when allowance exceeded
41+
XCTAssertFalse(blog.canUploadAsset(true))
42+
}
43+
44+
func testCanUploadAssetSelfHosted() throws {
45+
// Given a blog
46+
// When blog is not on WPCom and not paid
47+
blog.isHostedAtWPcom = false
48+
blog.hasPaidPlan = false
49+
50+
// Then it can upload assets irrespective of allowance
51+
XCTAssertTrue(blog.canUploadAsset(true))
52+
XCTAssertTrue(blog.canUploadAsset(false))
53+
}
54+
}
55+
56+
private extension BlogVideoLimitsTests {
57+
enum Constants {
58+
static let blogURL: String = "http://wordpress.com"
59+
}
60+
}

0 commit comments

Comments
 (0)