fix: preserve published legacy help fragments and Companion asset routes
This commit is contained in:
parent
ee5eaea19e
commit
cf4e742f5e
@ -0,0 +1,20 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using PlotDirector.Website.Services;
|
||||
using PlotDirector.Website.ViewModels;
|
||||
namespace PlotDirector.Website.Controllers;
|
||||
|
||||
// Legacy public help-fragment URL, served solely from approved published content.
|
||||
public sealed class PublishedHelpDrawerController(IHelpService help,IHelpMarkdownRenderer markdown):Controller
|
||||
{
|
||||
[HttpGet("/HelpDrawer/Article")]
|
||||
public IActionResult Article(string key)
|
||||
{
|
||||
Response.Headers["X-Robots-Tag"]="noindex, follow";
|
||||
var article=help.GetByContextKey(key);
|
||||
if(article is null)return NotFound();
|
||||
return PartialView("~/Views/Shared/_HelpDrawerArticle.cshtml",new HelpDrawerArticleViewModel
|
||||
{
|
||||
Article=article,RequestedContextKey=key,RenderedHtml=markdown.Render(article.MarkdownContent),RelatedArticles=help.GetRelatedArticles(article)
|
||||
});
|
||||
}
|
||||
}
|
||||
44
PlotDirector.Website/Views/Shared/_HelpDrawerArticle.cshtml
Normal file
44
PlotDirector.Website/Views/Shared/_HelpDrawerArticle.cshtml
Normal file
@ -0,0 +1,44 @@
|
||||
@model HelpDrawerArticleViewModel
|
||||
|
||||
@if (Model.Article is null)
|
||||
{
|
||||
<article class="help-drawer-article">
|
||||
<p class="eyebrow">Help</p>
|
||||
<h2>Help for this feature has not yet been written.</h2>
|
||||
@if (!string.IsNullOrWhiteSpace(Model.RequestedContextKey))
|
||||
{
|
||||
<p class="muted">Context key: @Model.RequestedContextKey</p>
|
||||
}
|
||||
</article>
|
||||
}
|
||||
else
|
||||
{
|
||||
<article class="help-drawer-article">
|
||||
<p class="eyebrow">@Model.Article.Category</p>
|
||||
<h2>@Model.Article.Title</h2>
|
||||
@if (!string.IsNullOrWhiteSpace(Model.Article.QuickSummary))
|
||||
{
|
||||
<p class="lead-text">@Model.Article.QuickSummary</p>
|
||||
}
|
||||
<p>
|
||||
<a href="@Model.Article.Url">Open in Help Centre</a>
|
||||
</p>
|
||||
<div class="help-markdown-body">
|
||||
@Html.Raw(Model.RenderedHtml)
|
||||
</div>
|
||||
@if (Model.RelatedArticles.Any())
|
||||
{
|
||||
<section class="help-related-section">
|
||||
<h3>Related guides</h3>
|
||||
<ul>
|
||||
@foreach (var related in Model.RelatedArticles)
|
||||
{
|
||||
<li>
|
||||
<button type="button" data-help-open="@related.ContextKey">@related.Title</button>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</section>
|
||||
}
|
||||
</article>
|
||||
}
|
||||
@ -46,7 +46,10 @@ with tempfile.TemporaryDirectory(prefix='pd-nginx-qualification-') as directory:
|
||||
r=request(path);assert r.code==308 and r.headers['Location']=='https://app.plotdirector.com'+path;checks.append('legacy browser path/query '+path.split('?')[0])
|
||||
body=b'{"synthetic":"request body preserved"}';r=request('/api/probe?x=y',data=body,headers={'Authorization':'Bearer SYNTHETIC-TEST-ONLY'});payload=json.load(r)
|
||||
assert payload=={'backend':'app','path':'/api/probe?x=y','bodySha256':hashlib.sha256(body).hexdigest(),'authorization':'Bearer SYNTHETIC-TEST-ONLY'};checks.append('legacy API preserves POST body query and bearer header')
|
||||
for path in ['/js/word-companion-host.js?v=legacy','/css/word-companion.css','/android-chrome-192x192.png']:
|
||||
r=request(path);assert r.read()==b'app';checks.append('legacy taskpane asset '+path.split('?')[0])
|
||||
r=request('/hubs/echo',headers={'Connection':'Upgrade','Upgrade':'websocket'});assert r.code==101;checks.append('legacy websocket upgrade reaches application')
|
||||
r=request('/HelpDrawer/Image?file=approved.png');assert r.read()==b'website';r=request('/HelpDrawer/Article?key=projects.overview');assert r.read()==b'website';checks.append('published help images and fragments stay independent of the application')
|
||||
r=request('/Projects',host='app.plotdirector.com');assert r.read()==b'app' and 'noindex' in r.headers['X-Robots-Tag'];checks.append('application host and noindex isolated')
|
||||
assert request('/_deployment/health').code==404 and request('/_deployment/health',host='app.plotdirector.com').code==404;checks.append('health endpoint denied on both public hosts')
|
||||
print(json.dumps({'passed':True,'sandboxOnly':True,'checks':checks},indent=2))
|
||||
|
||||
@ -538,7 +538,9 @@
|
||||
"GET /Help/Article/{contextKey}",
|
||||
"* /writing-problems/{**path} => 308 /problem-solver/{**path}",
|
||||
"POST /problem-solver/answer",
|
||||
"GET /problem-solver?state={protectedHistory}"
|
||||
"GET /problem-solver?state={protectedHistory}",
|
||||
"GET /HelpDrawer/Article?key={publishedContextKey}",
|
||||
"GET /HelpDrawer/Image?file={publishedAsset}"
|
||||
],
|
||||
"crawlerFiles": [
|
||||
"/robots.txt",
|
||||
|
||||
@ -62,11 +62,20 @@ def run(origin,production=False):
|
||||
try:fetch(path)
|
||||
except Exception as e:errors.append(path+': broken internal link/asset '+str(e))
|
||||
_,sitemap,_=fetch('/sitemap.xml');sitemap_urls={u.text for u in ET.fromstring(sitemap).findall('.//{*}loc')}
|
||||
from datetime import datetime,timezone
|
||||
expected_dates={path:datetime.fromisoformat(date.replace('Z','+00:00')).date().isoformat() for path,date in json.loads((root/'PlotDirector.Website/Content/page-modified.json').read_text()).items()}
|
||||
for entry in ET.fromstring(sitemap).findall('{*}url'):
|
||||
path=urllib.parse.urlsplit(entry.find('{*}loc').text).path;modified=entry.find('{*}lastmod')
|
||||
if path in expected_dates and (modified is None or modified.text!=expected_dates[path]):errors.append(path+': content modification date differs')
|
||||
if modified is not None and datetime.fromisoformat(modified.text).date()>datetime.now(timezone.utc).date():errors.append(path+': future modification date')
|
||||
if sitemap_urls!=set(public):errors.append('Sitemap differs from approved Production URL inventory')
|
||||
for path in ['/missing-page-acceptance','/help/missing/missing','/site.webmanifest','/service-worker.js','/hubs/word-companion-follow']:
|
||||
try:fetch(path);errors.append(path+': expected 404')
|
||||
except urllib.error.HTTPError as e:
|
||||
if e.code!=404:errors.append(path+': expected 404 got '+str(e.code))
|
||||
articles=json.loads((root/'PlotDirector.Website/Help/published/articles.json').read_text())
|
||||
sample=articles[0];status,fragment,headers=fetch('/HelpDrawer/Article?key='+urllib.parse.quote(sample['ContextKey']))
|
||||
if status!=200 or sample['Title'] not in fragment.decode() or 'noindex' not in headers.get('X-Robots-Tag',''):errors.append('published legacy help fragment differs')
|
||||
report={'origin':origin,'productionPolicy':production,'baselineUrls':len(public),'renderedPages':len(pages),'internalPaths':len(links),'assets':len(assets),'errors':errors,'passed':not errors}
|
||||
print(json.dumps(report,indent=2));return bool(errors)
|
||||
if __name__=='__main__':
|
||||
|
||||
@ -27,7 +27,8 @@ server {
|
||||
location ~* ^/_deployment(?:/|$) { return 404; }
|
||||
# Request bodies, bearer credentials and websocket upgrades must reach the app.
|
||||
# Browser redirects are insufficient for these legacy integration clients.
|
||||
location ~* ^/(api|hubs|native-companion|word-companion|uploads)(?:/|$) {
|
||||
# Keep taskpane scripts/styles/icons on the same legacy origin during client updates.
|
||||
location ~* ^/(api|hubs|native-companion|word-companion|uploads|css/(?:word-companion|notifications)\.css|js/(?:notifications|word-notifications|word-companion-host(?:\.min)?)\.js|android-chrome-(?:192x192|512x512)\.png|apple-touch-icon\.png)(?:/|$) {
|
||||
proxy_pass http://127.0.0.1:5001;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
@ -38,6 +39,14 @@ server {
|
||||
proxy_read_timeout 120s;
|
||||
add_header X-Robots-Tag "noindex, nofollow" always;
|
||||
}
|
||||
# Published help images belong to the website, even though the legacy URL
|
||||
# contains the former application drawer controller name.
|
||||
location ~* ^/HelpDrawer/(?:Image|Article)$ {
|
||||
proxy_pass http://127.0.0.1:5004;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
location ~* ^/(Acceptance|Account|Admin|Ai|AiAdministration|Analytics|Appearance|Archives|BookRecovery|Books|Chapters|CharacterAttributes|CharacterWorkspace|Characters|ContextNames|ContextNavigation|ContextRelationshipLenses|ContextTools|ContinuityExplorer|DeploymentHealth|Dynamics|Exports|FeatureRequests|FloorPlans|Geography|HelpDiagnostics|HelpDrawer|Imports|IntelligenceReview|IntentAssessment|InvestigationCompanion|LocationWorkspace|Locations|ManageAccount|ManuscriptReader|Maps|NameVerification|Names|NarrativeFocus|NativeChapterSync|NativeCompanion|NativeCompanionAuth|NativeCompanionWorkflow|NativeInstallation|NativeManuscriptCapture|NativePresence|NativeWorkspace|Onboarding|ParagraphManuscript|PlotLineWorkspace|PlotLines|PlotThreads|ProjectCollaborators|ProjectMetrics|ProjectRestorePoints|Projects|RelationshipMap|Scenarios|SceneMetrics|Scenes|SharedFocus|SpatialContext|StoryAssets|StoryBible|StoryCalendar|StoryPoint|StripeWebhook|Timeline|Toolbar|Warnings|WordCompanion|WordCompanionHost|Writer|WriterActivities|WriterAuthoring|WriterInvestigations|WriterPlanning|WriterReview|WriterWord|WriterWork|Writing|WritingActivity|WritingSolverAdmin|WritingSolverReview|WritingSolverWorkspace|admin|intelligence-review|manuscript|onboarding|InvestigationCompanion|problem-solver/workspace|writing-problems/workspace|Home|Pricing/(?:StartTrial|Checkout))(?:/|$) {
|
||||
return 308 https://app.plotdirector.com$request_uri;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user