diff --git a/PlotDirector.Website/Controllers/PublishedHelpDrawerController.cs b/PlotDirector.Website/Controllers/PublishedHelpDrawerController.cs new file mode 100644 index 0000000..f47ede2 --- /dev/null +++ b/PlotDirector.Website/Controllers/PublishedHelpDrawerController.cs @@ -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) + }); + } +} diff --git a/PlotDirector.Website/Views/Shared/_HelpDrawerArticle.cshtml b/PlotDirector.Website/Views/Shared/_HelpDrawerArticle.cshtml new file mode 100644 index 0000000..91ad0bf --- /dev/null +++ b/PlotDirector.Website/Views/Shared/_HelpDrawerArticle.cshtml @@ -0,0 +1,44 @@ +@model HelpDrawerArticleViewModel + +@if (Model.Article is null) +{ +
+

Help

+

Help for this feature has not yet been written.

+ @if (!string.IsNullOrWhiteSpace(Model.RequestedContextKey)) + { +

Context key: @Model.RequestedContextKey

+ } +
+} +else +{ +
+

@Model.Article.Category

+

@Model.Article.Title

+ @if (!string.IsNullOrWhiteSpace(Model.Article.QuickSummary)) + { +

@Model.Article.QuickSummary

+ } +

+ Open in Help Centre +

+
+ @Html.Raw(Model.RenderedHtml) +
+ @if (Model.RelatedArticles.Any()) + { + + } +
+} diff --git a/Tests/nginx_compatibility.py b/Tests/nginx_compatibility.py index f833cf0..084f1ae 100644 --- a/Tests/nginx_compatibility.py +++ b/Tests/nginx_compatibility.py @@ -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)) diff --git a/Tests/public-urls.json b/Tests/public-urls.json index 99f4f26..cbe11bd 100644 --- a/Tests/public-urls.json +++ b/Tests/public-urls.json @@ -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", diff --git a/Tests/verify.py b/Tests/verify.py index 89b8381..ffda04e 100644 --- a/Tests/verify.py +++ b/Tests/verify.py @@ -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__': diff --git a/Tools/Deployment/production/nginx-website.conf b/Tools/Deployment/production/nginx-website.conf index b73d2f1..06a0eda 100644 --- a/Tools/Deployment/production/nginx-website.conf +++ b/Tools/Deployment/production/nginx-website.conf @@ -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; }