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

fix: Shared page is not displayed when skipping SSR #9089

Merged
merged 6 commits into from
Sep 12, 2024

Conversation

miya
Copy link
Member

@miya miya commented Sep 10, 2024

Task

  • #153811 [issue] グループのみ閲覧可能なページの共有リンクのコンテンツが表示されない

@miya miya requested a review from yuki-takei September 10, 2024 10:37
@miya miya self-assigned this Sep 10, 2024
Copy link

changeset-bot bot commented Sep 10, 2024

⚠️ No Changeset found

Latest commit: 48ce1f6

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

apps/app/src/server/routes/apiv3/page/index.ts Fixed Show resolved Hide resolved
const relatedPage = await Page.findOne({ _id: getIdForRef(shareLink.relatedPage) });
const pagePopulateDataToShowRevision = await relatedPage?.populateDataToShowRevision();
return res.apiv3({ page: pagePopulateDataToShowRevision });
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この API に shared page を返却する処理が書かれていなかったため getServerSideProps ででやっている相当の処理を追加しました。

参考

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

Copy link
Member

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'));
}
Copy link
Member

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)でよい

Copy link
Member Author

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));

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 });
}
Copy link
Member

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 に任せる

@miya miya changed the title fix: Shared page is not displayed fix: Shared page is not displayed during SSR Sep 11, 2024
@miya miya changed the title fix: Shared page is not displayed during SSR fix: Shared page is not displayed when skipping SSR Sep 11, 2024
}

let page;
let pages;
try {
if (pageId != null) { // prioritized
if (isSharedPage) {
const shareLink = await ShareLink.findOne({ _id: shareLinkId }).populate('relatedPage');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.populate('relatedPage') いらないんじゃない?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要でしたので削除しました

@miya
Copy link
Member Author

miya commented Sep 12, 2024

@mergify queue

Copy link
Contributor

mergify bot commented Sep 12, 2024

queue

🛑 There are no queue conditions matching

There are queue conditions defined in the configuration, but none matches. The pull request has not been embarked.

Details:

  • Queue default:
  • #check-failure = 0
  • check-success ~= ci-app-

mergify bot added a commit that referenced this pull request Sep 12, 2024
@yuki-takei
Copy link
Member

@mergify requeue

Copy link
Contributor

mergify bot commented Sep 12, 2024

requeue

✅ The queue state of this pull request has been cleaned. It can be re-embarked automatically

@yuki-takei
Copy link
Member

@mergify queue

Copy link
Contributor

mergify bot commented Sep 12, 2024

queue

✅ The pull request has been merged automatically

The pull request has been merged automatically at d44cb18

mergify bot added a commit that referenced this pull request Sep 12, 2024
@mergify mergify bot merged commit d44cb18 into master Sep 12, 2024
16 checks passed
@mergify mergify bot deleted the fix/sharing-page-for-grant-5 branch September 12, 2024 11:34
@github-actions github-actions bot mentioned this pull request Sep 12, 2024
@github-actions github-actions bot mentioned this pull request Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

[7.0.16]グループのみ閲覧可能なページの共有リンクのコンテンツが表示されません
2 participants