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

feat: Allow remote editor for WPCOM sites #24170

Draft
wants to merge 6 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ExperimentalFeaturesDataProvider: ExperimentalFeaturesViewModel.DataProvid
FeatureFlag.authenticateUsingApplicationPassword,
FeatureFlag.newGutenberg,
FeatureFlag.newGutenbergThemeStyles,
FeatureFlag.newGutenbergPlugins,
]

private let flagStore = FeatureFlagOverrideStore()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,10 @@ class NewGutenbergViewController: UIViewController, PostEditor, PublishingEditor
self.navigationBarManager = navigationBarManager ?? PostEditorNavigationBarManager()

let selfHostedApiUrl = post.blog.url(withPath: "wp-json/")
let isSelfHosted = !post.blog.isHostedAtWPcom && !post.blog.isAtomic()
let siteApiRoot = post.blog.isAccessibleThroughWPCom() && !isSelfHosted ? post.blog.wordPressComRestApi()?.baseURL.absoluteString : selfHostedApiUrl
let isWPComSite = post.blog.isHostedAtWPcom || post.blog.isAtomic()
let siteApiRoot = post.blog.isAccessibleThroughWPCom() && isWPComSite ? post.blog.wordPressComRestApi()?.baseURL.absoluteString : selfHostedApiUrl
let siteId = post.blog.dotComID?.stringValue
let siteDomain = post.blog.primaryDomainAddress
let authToken = post.blog.authToken ?? ""
var authHeader = "Bearer \(authToken)"

Expand All @@ -139,7 +140,14 @@ class NewGutenbergViewController: UIViewController, PostEditor, PublishingEditor
}
}

let siteApiNamespace = post.blog.dotComID != nil && !isSelfHosted && applicationPassword == nil ? "sites/\(siteId ?? "")" : ""
// Must provide both namespace forms to detect usages of both forms in third-party code
var siteApiNamespace: [String] = []
if isWPComSite {
if let siteId {
siteApiNamespace.append("sites/\(siteId)")
}
siteApiNamespace.append("sites/\(siteDomain)")
}

var conf = EditorConfiguration(
title: post.postTitle ?? "",
Expand All @@ -151,10 +159,19 @@ class NewGutenbergViewController: UIViewController, PostEditor, PublishingEditor
conf.siteURL = post.blog.url ?? ""
conf.siteApiRoot = siteApiRoot ?? ""
conf.siteApiNamespace = siteApiNamespace
conf.namespaceExcludedPaths = ["/wpcom/v2/following/recommendations", "/wpcom/v2/following/mine"]
conf.authHeader = authHeader

conf.themeStyles = FeatureFlag.newGutenbergThemeStyles.enabled
conf.plugins = FeatureFlag.newGutenbergPlugins.enabled && isSelfHosted
// Limited to Simple sites until application password auth is supported
conf.plugins = FeatureFlag.newGutenbergPlugins.enabled && post.blog.isHostedAtWPcom

if !post.blog.isSelfHosted {
let siteType: String = post.blog.isHostedAtWPcom ? "simple" : "atomic"
conf.webViewGlobals = [
WebViewGlobal(name: "_currentSiteType", value: .string(siteType))
]
}

self.editorViewController = GutenbergKit.EditorViewController(configuration: conf)

Expand Down