-
Notifications
You must be signed in to change notification settings - Fork 220
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
fix: Shared page is not displayed when skipping SSR #9089
Conversation
|
const relatedPage = await Page.findOne({ _id: getIdForRef(shareLink.relatedPage) }); | ||
const pagePopulateDataToShowRevision = await relatedPage?.populateDataToShowRevision(); | ||
return res.apiv3({ page: pagePopulateDataToShowRevision }); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この API に shared page を返却する処理が書かれていなかったため getServerSideProps ででやっている相当の処理を追加しました。
参考
growi/apps/app/src/pages/share/[[...path]].page.tsx
Lines 235 to 241 in 8fc33a0
const Page = crowi.model('Page'); | |
const relatedPage = await Page.findOne({ _id: getIdForRef(shareLink.relatedPage) }); | |
// determine whether skip SSR | |
const ssrMaxRevisionBodyLength = crowi.configManager.getConfig('crowi', 'app:ssrMaxRevisionBodyLength'); | |
props.skipSSR = await skipSSR(relatedPage, ssrMaxRevisionBodyLength); | |
// populate | |
props.shareLinkRelatedPage = await relatedPage.populateDataToShowRevision(props.skipSSR); // shouldExcludeBody = skipSSR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revision の populate はこの下の try-catch block に任せる
const { | ||
pageId, path, findAll, revisionId, | ||
pageId, path, findAll, revisionId, shareLinkId, | ||
} = req.query; | ||
|
||
if (pageId == null && path == null) { | ||
return res.apiv3Err(new ErrorV3('Either parameter of path or pageId is required.', 'invalid-request')); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validation が足りない
- (pageId or path) と shareLinkId を同時に指定できてはいけない
- shareLinkId が存在する時は pageId or path は指定されていてはいけない(400 を返す)
- isSharedPage が true なら、shareLinkId は not null でなければならない
- さもなくば
ShareLink.findOne()
によって取れてはいけないデータが取れてしまう - middleware で保証されているのであれば、res.apiv3Err を返す必要はなく、単に 500 (throw new Error)でよい
- さもなくば
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(pageId or path) と shareLinkId を同時に指定できてはいけない
certify-shared-page middleware では有効な shareLinkId かどうかを判断するために shareLinkId と pageId を取得する必要があるので validation の条件を以下のように修正しました
const isValid = (shareLinkId != null && pageId != null && path == null) || (shareLinkId == null && (pageId != null || path != null));
growi/apps/app/src/server/middlewares/certify-shared-page.js
Lines 9 to 13 in e7a94cb
const pageId = req.query.pageId || req.body.pageId || null; | |
const shareLinkId = req.query.shareLinkId || req.body.shareLinkId || null; | |
if (pageId == null || shareLinkId == null) { | |
return next(); | |
} |
isSharedPage が true なら、shareLinkId は not null でなければならない
こちらは修正しました。
const relatedPage = await Page.findOne({ _id: getIdForRef(shareLink.relatedPage) }); | ||
const pagePopulateDataToShowRevision = await relatedPage?.populateDataToShowRevision(); | ||
return res.apiv3({ page: pagePopulateDataToShowRevision }); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revision の populate はこの下の try-catch block に任せる
} | ||
|
||
let page; | ||
let pages; | ||
try { | ||
if (pageId != null) { // prioritized | ||
if (isSharedPage) { | ||
const shareLink = await ShareLink.findOne({ _id: shareLinkId }).populate('relatedPage'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.populate('relatedPage')
いらないんじゃない?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要でしたので削除しました
@mergify queue |
🛑 There are no queue conditions matchingThere are queue conditions defined in the configuration, but none matches. The pull request has not been embarked. Details:
|
@mergify requeue |
✅ The queue state of this pull request has been cleaned. It can be re-embarked automatically |
@mergify queue |
✅ The pull request has been merged automaticallyThe pull request has been merged automatically at d44cb18 |
Task