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: Custom logo not displayed on shared page #7205

Merged

Conversation

miya
Copy link
Member

@miya miya commented Jan 4, 2023

Task

#112434 [GROWI][Next.js] カスタムロゴ設定した状態で、任意のページのsharelink にアクセスすると、ロゴが表示されない
#112474 修正

@miya miya requested a review from yuki-takei January 4, 2023 05:57
@miya miya self-assigned this Jan 4, 2023
if (isBlandLogo) {
req.isSharedPage = true;
return next();
}
Copy link
Member Author

Choose a reason for hiding this comment

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

attachmentType が BRAND_LOGO の attachment は relatedPage が null となるため、42 行目以降の処理は不要にして、shared page で表示できるようにしました。

Copy link
Member

Choose a reason for hiding this comment

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

  • brand logo かどうかの判定ロジックは Attachment model or service に持っていく
  • req.isSharedPage = true; セットするのは不自然
    • そもそも shared page からのアクセスだろうがそれ以外からのアクセスだろうが、brand logo は pass させたいわけだから
    • certifyBrandLogo middleware をつくるか、または /attachment/brand-logo route を作っちゃうか

@miya miya temporarily deployed to VRT January 4, 2023 06:16 — with GitHub Actions Inactive
if (isBlandLogo) {
req.isSharedPage = true;
return next();
}
Copy link
Member

Choose a reason for hiding this comment

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

  • brand logo かどうかの判定ロジックは Attachment model or service に持っていく
  • req.isSharedPage = true; セットするのは不自然
    • そもそも shared page からのアクセスだろうがそれ以外からのアクセスだろうが、brand logo は pass させたいわけだから
    • certifyBrandLogo middleware をつくるか、または /attachment/brand-logo route を作っちゃうか

@miya miya temporarily deployed to VRT January 4, 2023 10:06 — with GitHub Actions Inactive
@@ -106,6 +107,8 @@ module.exports = function(crowi, app) {
app.post('/_api/admin/import/qiita' , loginRequiredStrictly , adminRequired , csrfProtection, addActivity, admin.api.importDataFromQiita);
app.post('/_api/admin/import/testQiitaAPI' , loginRequiredStrictly , adminRequired , csrfProtection, addActivity, admin.api.testQiitaAPI);

app.get('/attachment/brand-logo/:id([0-9a-z]{24})' , certifyBrandLogo, loginRequired, attachment.api.get);
Copy link
Member Author

@miya miya Jan 4, 2023

Choose a reason for hiding this comment

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

メンテナスモード時に考慮して API を新設しました

別 PR の FB に対応したものになります
#7204 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

/attachment/brand-logo 固定でいいね

Copy link
Member Author

Choose a reason for hiding this comment

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

固定にしました

next();
};

};
Copy link
Member Author

Choose a reason for hiding this comment

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

  • Brand logo か判断するための express middleware
  • loginRequired を通過させるための変数 isBrandLogo を追加しました

Copy link
Member

Choose a reason for hiding this comment

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

id ではなく type で取得する
(BRAND_LOGO type のドキュメントは1つしか存在しないはず)

Copy link
Member Author

Choose a reason for hiding this comment

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

修正しました

Copy link
Member

Choose a reason for hiding this comment

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

route を分けたからここでの存在確認いらないね。
この middleware は無条件で req.isBrandLogo = true をセットしていい。

attachment が存在しなかったら attachment.api.getBrandLogo が 404 を返す

Copy link
Member Author

Choose a reason for hiding this comment

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

修正しました

@@ -718,7 +718,7 @@ module.exports = (crowi) => {
try {
attachment = await attachmentService.createAttachment(file, req.user, null, AttachmentType.BRAND_LOGO);
const attachmentConfigParams = {
'customize:customizedLogoSrc': attachment.filePathProxied,
'customize:customizedLogoSrc': attachment.brandLogoFilePathProxied,
Copy link
Member Author

Choose a reason for hiding this comment

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

/attachment/brand-logo/{filePath} で保存されるように修正しました

Copy link
Member

Choose a reason for hiding this comment

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

/attachment/brand-logo 固定でいいね

Copy link
Member Author

Choose a reason for hiding this comment

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

固定にしたので、customize:customizedLogoSrc は廃止にしました

@miya miya requested a review from yuki-takei January 4, 2023 10:23
@miya miya temporarily deployed to VRT January 4, 2023 10:36 — with GitHub Actions Inactive
next();
};

};
Copy link
Member

Choose a reason for hiding this comment

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

id ではなく type で取得する
(BRAND_LOGO type のドキュメントは1つしか存在しないはず)

@@ -51,6 +51,10 @@ module.exports = function(crowi) {
return `/attachment/${this._id}`;
});

attachmentSchema.virtual('brandLogoFilePathProxied').get(function() {
return `/attachment/brand-logo/${this._id}`;
});
Copy link
Member

Choose a reason for hiding this comment

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

不要

@@ -718,7 +718,7 @@ module.exports = (crowi) => {
try {
attachment = await attachmentService.createAttachment(file, req.user, null, AttachmentType.BRAND_LOGO);
const attachmentConfigParams = {
'customize:customizedLogoSrc': attachment.filePathProxied,
'customize:customizedLogoSrc': attachment.brandLogoFilePathProxied,
Copy link
Member

Choose a reason for hiding this comment

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

/attachment/brand-logo 固定でいいね

@@ -106,6 +107,8 @@ module.exports = function(crowi, app) {
app.post('/_api/admin/import/qiita' , loginRequiredStrictly , adminRequired , csrfProtection, addActivity, admin.api.importDataFromQiita);
app.post('/_api/admin/import/testQiitaAPI' , loginRequiredStrictly , adminRequired , csrfProtection, addActivity, admin.api.testQiitaAPI);

app.get('/attachment/brand-logo/:id([0-9a-z]{24})' , certifyBrandLogo, loginRequired, attachment.api.get);
Copy link
Member

Choose a reason for hiding this comment

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

/attachment/brand-logo 固定でいいね

@miya miya temporarily deployed to VRT January 4, 2023 17:38 — with GitHub Actions Inactive
next();
};

};
Copy link
Member Author

Choose a reason for hiding this comment

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

修正しました

packages/app/src/stores/context.tsx Show resolved Hide resolved
@miya miya temporarily deployed to VRT January 4, 2023 18:29 — with GitHub Actions Inactive
@@ -77,6 +79,11 @@ class AttachmentService {
return;
}

async isBrandLogoExist() {
const Attachment = this.crowi.model('Attachment');
return await Attachment.findOne({ attachmentType: AttachmentType.BRAND_LOGO }) != null;
Copy link
Member

Choose a reason for hiding this comment

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

count が 1 以上かどうかというクエリにしてください

Copy link
Member Author

Choose a reason for hiding this comment

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

修正しました

@@ -63,7 +63,8 @@ function GrowiApp({ Component, pageProps }: GrowiAppProps): JSX.Element {
useSiteUrl(commonPageProps.siteUrl);
useConfidential(commonPageProps.confidential);
useGrowiVersion(commonPageProps.growiVersion);
useCustomizedLogoSrc(commonPageProps.customizedLogoSrc);
useIsDefaultLogo(commonPageProps.isDefaultLogo);
useIsCustomizedLogoUploaded(commonPageProps.isCustomizedLogoUploaded);
Copy link
Member

Choose a reason for hiding this comment

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

ここは元のままでいい

Copy link
Member Author

@miya miya Jan 6, 2023

Choose a reason for hiding this comment

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

「デフォルトロゴが選択されているかどうか」と 「カスタムロゴがアップロードされているかどうか」は別問題なのでこのままにしました。useCustomizedLogoSrc (カスタムロゴのソース) と useIsCustomizedLogoUploaded (カスタムロゴがアップロードされているかどうかの boolean ) の使われ方はほぼ同じで、フロントエンドで src を使う必要がないので後者を残しました。


return (
<nav id="grw-navbar" className={`navbar grw-navbar ${styles['grw-navbar']} navbar-expand navbar-dark sticky-top mb-0 px-0`}>
{/* Brand Logo */}
<div className="navbar-brand mr-0">
<Link href="/" prefetch={false}>
<a className="grw-logo d-block">
<GrowiNavbarLogo logoSrc={customizedLogoSrc}/>
<GrowiNavbarLogo isDefaultLogo={isDefaultLogo} isCustomizedLogoUploaded={isCustomizedLogoUploaded}/>
Copy link
Member

Choose a reason for hiding this comment

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

ここは元のままでいい

Copy link
Member Author

Choose a reason for hiding this comment

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

isDefaultLogo だけで判断できるようにしました

currentUser,
isDefaultLogo,
isCustomizedLogoUploaded,
Copy link
Member

Choose a reason for hiding this comment

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

  • customizedLogoSrc props は元に戻し、DB から取得した src を入れる

@miya miya temporarily deployed to VRT January 6, 2023 08:06 — with GitHub Actions Inactive
@miya miya temporarily deployed to VRT January 6, 2023 09:14 — with GitHub Actions Inactive
@miya miya requested a review from yuki-takei January 6, 2023 09:14
next();
};

};
Copy link
Member

Choose a reason for hiding this comment

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

route を分けたからここでの存在確認いらないね。
この middleware は無条件で req.isBrandLogo = true をセットしていい。

attachment が存在しなかったら attachment.api.getBrandLogo が 404 を返す

@miya miya requested a review from yuki-takei January 6, 2023 10:49
@miya miya temporarily deployed to VRT January 6, 2023 11:13 — with GitHub Actions Inactive
@reg-suit
Copy link

reg-suit bot commented Jan 6, 2023

reg-suit detected visual differences.

Check this report, and review them.

🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴

🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵🔵

What do the circles mean? The number of circles represent the number of changed images.
🔴 : Changed items, ⚪ : New items, ⚫ : Deleted items, and 🔵 Passed items

How can I change the check status? If reviewers approve this PR, the reg context status will be green automatically.

@yuki-takei yuki-takei merged commit 8ffc924 into master Jan 6, 2023
@yuki-takei yuki-takei deleted the fix/112474-custom-logo-not-displayed-on-shared-page branch January 6, 2023 11:19
@github-actions github-actions bot mentioned this pull request Jan 6, 2023
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.

None yet

2 participants