Skip to content

Commit

Permalink
Merge pull request #16269 from twstokes/feature/set-and-change-author
Browse files Browse the repository at this point in the history
Set author display name on Post / Page creation, send author changes to API.
  • Loading branch information
guarani authored Apr 20, 2021
2 parents 602c45a + 7c5e6e6 commit 517cf29
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def wordpress_ui
end

def wordpress_kit
pod 'WordPressKit', '~> 4.31.0'
# pod 'WordPressKit', '~> 4.31.0'
pod 'WordPressKit', :git => 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', :tag => '4.32.0-beta.1'
# pod 'WordPressKit', :git => 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', :tag => ''
# pod 'WordPressKit', :git => 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', :branch => ''
# pod 'WordPressKit', :git => 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', :commit => ''
Expand Down
17 changes: 11 additions & 6 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ DEPENDENCIES:
- SVProgressHUD (= 2.2.5)
- WordPress-Editor-iOS (~> 1.19.4)
- WordPressAuthenticator (~> 1.36.0)
- WordPressKit (~> 4.31.0)
- WordPressKit (from `https://github.com/wordpress-mobile/WordPressKit-iOS.git`, tag `4.32.0-beta.1`)
- WordPressMocks (~> 0.0.9)
- WordPressShared (~> 1.16.0)
- WordPressUI (~> 1.10.0)
Expand All @@ -511,8 +511,6 @@ DEPENDENCIES:
SPEC REPOS:
https://github.com/wordpress-mobile/cocoapods-specs.git:
- WordPressAuthenticator
- WordPressKit
- WordPressUI
trunk:
- 1PasswordExtension
- Alamofire
Expand Down Expand Up @@ -554,6 +552,7 @@ SPEC REPOS:
- WordPress-Editor-iOS
- WordPressMocks
- WordPressShared
- WordPressUI
- WPMediaPicker
- wpxmlrpc
- ZendeskCommonUISDK
Expand Down Expand Up @@ -651,6 +650,9 @@ EXTERNAL SOURCES:
:git: https://github.com/wordpress-mobile/gutenberg-mobile.git
:submodules: true
:tag: v1.51.0
WordPressKit:
:git: https://github.com/wordpress-mobile/WordPressKit-iOS.git
:tag: 4.32.0-beta.1
Yoga:
:podspec: https://raw.githubusercontent.com/wordpress-mobile/gutenberg-mobile/v1.51.0/third-party-podspecs/Yoga.podspec.json

Expand All @@ -666,6 +668,9 @@ CHECKOUT OPTIONS:
:git: https://github.com/wordpress-mobile/gutenberg-mobile.git
:submodules: true
:tag: v1.51.0
WordPressKit:
:git: https://github.com/wordpress-mobile/WordPressKit-iOS.git
:tag: 4.32.0-beta.1

SPEC CHECKSUMS:
1PasswordExtension: f97cc80ae58053c331b2b6dc8843ba7103b33794
Expand Down Expand Up @@ -747,10 +752,10 @@ SPEC CHECKSUMS:
WordPress-Aztec-iOS: 870c93297849072aadfc2223e284094e73023e82
WordPress-Editor-iOS: 068b32d02870464ff3cb9e3172e74234e13ed88c
WordPressAuthenticator: 21d96070b30c4ce6b98de52c05779d27c2f9b399
WordPressKit: 4282eb0b5f55415210a77c7bb8739d8ad00cb4c1
WordPressKit: 9ff7c4280955ec7662aae59d72763ae5eb4dea98
WordPressMocks: 903d2410f41a09fb2e0a1b44ad36ad80310570fb
WordPressShared: 0f7f10e96f8354d64f951c223ae61e8de7495a46
WordPressUI: 7735014eb5a518a8346b1179b36ba77abcb49ee5
WordPressUI: 8c754c252a9f36fa32a4c588e9cdeb0d7d8dbe07
WPMediaPicker: d5ae9a83cd5cc0e4de46bfc1c59120aa86658bc3
wpxmlrpc: bf55a43a7e710bd2a4fb8c02dfe83b1246f14f13
Yoga: c920bf12bf8146aa5cd118063378c2cf5682d16c
Expand All @@ -763,6 +768,6 @@ SPEC CHECKSUMS:
ZendeskSupportSDK: e100a7a0a1bb5d7d43abbde3338727d985a4986d
ZIPFoundation: e27423c004a5a1410c15933407747374e7c6cb6e

PODFILE CHECKSUM: c7e42bbb17e1c3b6f9084b2b877a074028064b0a
PODFILE CHECKSUM: 412fa67638670c44b777190edc1769865f3d07b8

COCOAPODS: 1.10.0
6 changes: 6 additions & 0 deletions WordPress/Classes/Models/AbstractPost.m
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,12 @@ - (BOOL)hasLocalChanges
return YES;
}

if ((self.authorID != original.authorID)
&& (![self.authorID isEqual:original.authorID]))
{
return YES;
}

return NO;
}

Expand Down
9 changes: 9 additions & 0 deletions WordPress/Classes/Services/PostService.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ - (Post *)createPostForBlog:(Blog *)blog {
post.postFormat = blog.settings.defaultPostFormat;
post.postType = Post.typeDefaultIdentifier;

BlogAuthor *author = [blog getAuthorWithId:blog.userID];
post.authorID = author.userID ?: blog.account.userID;
post.author = author.displayName ?: blog.account.displayName;

[blog.managedObjectContext obtainPermanentIDsForObjects:@[post] error:nil];
NSAssert(![post.objectID isTemporaryID], @"The new post for this blog must have a permanent ObjectID");

Expand All @@ -74,6 +78,10 @@ - (Page *)createPageForBlog:(Blog *)blog {
page.date_created_gmt = [NSDate date];
page.remoteStatus = AbstractPostRemoteStatusSync;

BlogAuthor *author = [blog getAuthorWithId:blog.userID];
page.authorID = author.userID ?: blog.account.userID;
page.author = author.displayName ?: blog.account.displayName;

[blog.managedObjectContext obtainPermanentIDsForObjects:@[page] error:nil];
NSAssert(![page.objectID isTemporaryID], @"The new page for this blog must have a permanent ObjectID");

Expand Down Expand Up @@ -924,6 +932,7 @@ - (RemotePost *)remotePostWithPost:(AbstractPost *)post
remotePost.password = post.password;
remotePost.type = @"post";
remotePost.authorAvatarURL = post.authorAvatarURL;
remotePost.authorID = post.authorID;
remotePost.excerpt = post.mt_excerpt;
remotePost.slug = post.wp_slug;

Expand Down
20 changes: 20 additions & 0 deletions WordPress/WordPressTest/PostTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -519,4 +519,24 @@ class PostTests: XCTestCase {

XCTAssertFalse(revision.hasLocalChanges())
}

/// When changing an authorID hasLocalChanges returns true
func testLocalChangesWhenAuthorIsChanged() {
let post = newTestPost()
post.authorID = 1
let revision = post.createRevision()
revision.authorID = 2

XCTAssertTrue(revision.hasLocalChanges())
}

/// When setting the same authorID hasLocalChanges returns false
func testLocalChangesWhenAuthorIsTheSame() {
let post = newTestPost()
post.authorID = 1
let revision = post.createRevision()
revision.authorID = 1

XCTAssertFalse(revision.hasLocalChanges())
}
}

0 comments on commit 517cf29

Please sign in to comment.