Просмотр исходного кода

Code improvement

https://youtrack.weseek.co.jp/issue/GW-7759
- Remove unused appContainer from AdminCustomizeContainer
- Remove unused constants and methods that related to upload profile image from PersonalContainer
- Remove currentBrandLogo
- Return isDefaultLogo and customizedLogoSrc and adjust the implementation in GrowiNavbar
- Set WIKI_PAGE as default value of attachmentType in createAttachment method
- Adjust upload and remove brand logo route in customize-settings
mudana 3 лет назад
Родитель
Сommit
46feb7a1c4

+ 1 - 2
packages/app/src/client/services/AdminCustomizeContainer.js

@@ -14,10 +14,9 @@ const logger = loggerFactory('growi:services:AdminCustomizeContainer');
  */
 export default class AdminCustomizeContainer extends Container {
 
-  constructor(appContainer) {
+  constructor() {
     super();
 
-    this.appContainer = appContainer;
     this.dummyCurrentTheme = 0;
     this.dummyCurrentThemeForError = 1;
 

+ 0 - 25
packages/app/src/client/services/PersonalContainer.js

@@ -1,16 +1,12 @@
 import { Container } from 'unstated';
 
-import { AttachmentType } from '~/server/interfaces/attachment';
 import loggerFactory from '~/utils/logger';
 
-import { apiPost } from '../util/apiv1-client';
 import { apiv3Get, apiv3Put } from '../util/apiv3-client';
 
 // eslint-disable-next-line no-unused-vars
 const logger = loggerFactory('growi:services:PersonalContainer');
 
-const DEFAULT_IMAGE = '/images/icons/user.svg';
-
 /**
  * Service container for personal settings page (PersonalSettings.jsx)
  * @extends {Container} unstated Container
@@ -30,8 +26,6 @@ export default class PersonalContainer extends Container {
       isEmailPublished: false,
       lang: 'en_US',
       isGravatarEnabled: false,
-      isUploadedPicture: false,
-      uploadedPictureSrc: this.getUploadedPictureSrc(this.appContainer.currentUser),
       externalAccounts: [],
       apiToken: '',
       slackMemberId: '',
@@ -70,25 +64,6 @@ export default class PersonalContainer extends Container {
     }
   }
 
-  /**
-   * define a function for uploaded picture
-   */
-  getUploadedPictureSrc(user) {
-    if (user == null) {
-      return DEFAULT_IMAGE;
-    }
-    if (user.image) {
-      this.setState({ isUploadedPicture: true });
-      return user.image;
-    }
-    if (user.imageAttachment != null) {
-      this.setState({ isUploadedPicture: true });
-      return user.imageAttachment.filePathProxied;
-    }
-
-    return DEFAULT_IMAGE;
-  }
-
   /**
    * retrieve external accounts that linked me
    */

+ 0 - 1
packages/app/src/components/Admin/Customize/CustomizeLogoSetting.tsx

@@ -51,7 +51,6 @@ const CustomizeLogoSetting = (): JSX.Element => {
       const response = await apiv3Put('/customize-setting/customize-logo', {
         isDefaultLogo,
         customizedLogoSrc,
-        currentBrandLogo: (!isDefaultLogo && customizedLogoSrc != null) ? customizedLogoSrc : null,
       });
       const { customizedParams } = response.data;
       setIsDefaultLogo(customizedParams.isDefaultLogo);

+ 3 - 2
packages/app/src/components/Navbar/GrowiNavbar.tsx

@@ -122,16 +122,17 @@ const GrowiNavbar = (props) => {
 
   const { appContainer } = props;
   const {
-    crowi, isSearchServiceConfigured, currentBrandLogo,
+    crowi, isSearchServiceConfigured, isDefaultLogo, customizedLogoSrc,
   } = appContainer.config;
   const { data: isDeviceSmallerThanMd } = useIsDeviceSmallerThanMd();
   const { data: isSearchPage } = useIsSearchPage();
+  const logoSrc = (!isDefaultLogo && customizedLogoSrc !== null) ? customizedLogoSrc : null;
   return (
     <>
       {/* Brand Logo  */}
       <div className="navbar-brand mr-0">
         <a className="grw-logo d-block" href="/">
-          <GrowiNavbarLogo logoSrc={...currentBrandLogo} />
+          <GrowiNavbarLogo logoSrc={...logoSrc} />
         </a>
       </div>
 

+ 2 - 1
packages/app/src/server/models/config.ts

@@ -245,7 +245,8 @@ schema.statics.getLocalconfig = function(crowi) {
     globalLang: crowi.configManager.getConfig('crowi', 'app:globalLang'),
     pageLimitationL: crowi.configManager.getConfig('crowi', 'customize:showPageLimitationL'),
     pageLimitationXL: crowi.configManager.getConfig('crowi', 'customize:showPageLimitationXL'),
-    currentBrandLogo: crowi.configManager.getConfig('crowi', 'customize:currentBrandLogo'),
+    isDefaultLogo: crowi.configManager.getConfig('crowi', 'customize:isDefaultLogo'),
+    customizedLogoSrc: crowi.configManager.getConfig('crowi', 'customize:customizedLogoSrc'),
     isSidebarDrawerMode: crowi.configManager.getConfig('crowi', 'customize:isSidebarDrawerMode'),
     isSidebarClosedAtDockMode: crowi.configManager.getConfig('crowi', 'customize:isSidebarClosedAtDockMode'),
   };

+ 2 - 11
packages/app/src/server/routes/apiv3/customize-setting.js

@@ -156,7 +156,6 @@ module.exports = (crowi) => {
     logo: [
       body('isDefaultLogo').isBoolean().optional({ nullable: true }),
       body('customizedLogoSrc').isString().optional({ nullable: true }),
-      body('currentBrandLogo').isString().optional({ nullable: true }),
     ],
   };
 
@@ -677,13 +676,12 @@ module.exports = (crowi) => {
   router.put('/customize-logo', apiLimiter, loginRequiredStrictly, adminRequired, csrf, validator.logo, apiV3FormValidator, async(req, res) => {
 
     const {
-      isDefaultLogo, customizedLogoSrc, currentBrandLogo,
+      isDefaultLogo, customizedLogoSrc,
     } = req.body;
 
     const requestParams = {
       'customize:isDefaultLogo': isDefaultLogo,
       'customize:customizedLogoSrc': customizedLogoSrc,
-      'customize:currentBrandLogo': currentBrandLogo,
     };
     try {
       await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
@@ -728,13 +726,10 @@ module.exports = (crowi) => {
       let attachment;
       try {
         attachment = await attachmentService.createAttachment(file, req.user, null, AttachmentType.BRAND_LOGO);
-        const isDefaultLogo = await crowi.configManager.getConfig('crowi', 'customize:isDefaultLogo');
         const attachmentConfigParams = {
           'customize:customizedLogoSrc': attachment.filePathProxied,
         };
-        if (!isDefaultLogo) {
-          attachmentConfigParams['customize:currentBrandLogo'] = attachment.filePathProxied;
-        }
+
         await crowi.configManager.updateConfigsInTheSameNamespace('crowi', attachmentConfigParams);
       }
       catch (err) {
@@ -755,15 +750,11 @@ module.exports = (crowi) => {
       }
 
       try {
-        const isDefaultLogo = await crowi.configManager.getConfig('crowi', 'customize:isDefaultLogo');
         await attachmentService.removeAllAttachments(attachments);
         // update attachmentId immediately
         const attachmentConfigParams = {
           'customize:customizedLogoSrc': null,
         };
-        if (!isDefaultLogo) {
-          attachmentConfigParams['customize:currentBrandLogo'] = null;
-        }
         await crowi.configManager.updateConfigsInTheSameNamespace('crowi', attachmentConfigParams);
       }
       catch (err) {

+ 3 - 1
packages/app/src/server/service/attachment.js

@@ -1,5 +1,7 @@
 import loggerFactory from '~/utils/logger';
 
+import { AttachmentType } from '../interfaces/attachment';
+
 const fs = require('fs');
 
 const mongoose = require('mongoose');
@@ -16,7 +18,7 @@ class AttachmentService {
     this.crowi = crowi;
   }
 
-  async createAttachment(file, user, pageId = null, attachmentType = null) {
+  async createAttachment(file, user, pageId = null, attachmentType = AttachmentType.WIKI_PAGE) {
     const { fileUploadService } = this.crowi;
 
     // check limit