Explorar el Código

Merge branch 'master' into fix/page-is-not-rendered-for-guest

Yuki Takei hace 3 años
padre
commit
41443be7c6

+ 8 - 2
.github/workflows/reusable-app-prod.yml

@@ -180,7 +180,7 @@ jobs:
       fail-fast: false
       matrix:
         # List string expressions that is comma separated ids of tests in "test/cypress/integration"
-        spec-group: ['1', '2', '3', '4', '6']
+        spec-group: ['10', '20', '21', '30', '40', '60']
 
     services:
       mongodb:
@@ -239,11 +239,17 @@ jobs:
         cat config/ci/.env.local.for-ci >> .env.production.local
 
     - name: Copy dotenv file for automatic installation
-      if: ${{ matrix.spec-group != '1' }}
+      if: ${{ matrix.spec-group != '10' }}
       working-directory: ./packages/app
       run: |
         cat config/ci/.env.local.for-auto-install >> .env.production.local
 
+    - name: Copy dotenv file for automatic installation with allowing guest mode
+      if: ${{ matrix.spec-group == '21' }}
+      working-directory: ./packages/app
+      run: |
+        cat config/ci/.env.local.for-auto-install-with-allowing-guest >> .env.production.local
+
     - name: Cypress Run
       uses: cypress-io/github-action@v3
       with:

+ 1 - 0
packages/app/config/ci/.env.local.for-auto-install-with-allowing-guest

@@ -0,0 +1 @@
+AUTO_INSTALL_ALLOW_GUEST_MODE=true

+ 5 - 1
packages/app/src/server/crowi/index.js

@@ -400,12 +400,16 @@ Crowi.prototype.autoInstall = function() {
     admin: true,
   };
   const globalLang = this.configManager.getConfig('crowi', 'autoInstall:globalLang');
+  const allowGuestMode = this.configManager.getConfig('crowi', 'autoInstall:allowGuestMode');
   const serverDate = this.configManager.getConfig('crowi', 'autoInstall:serverDate');
 
   const installerService = new InstallerService(this);
 
   try {
-    installerService.install(firstAdminUserToSave, globalLang ?? 'en_US', serverDate);
+    installerService.install(firstAdminUserToSave, globalLang ?? 'en_US', {
+      allowGuestMode,
+      serverDate,
+    });
   }
   catch (err) {
     logger.warn('Automatic installation failed.', err);

+ 6 - 0
packages/app/src/server/service/config-loader.ts

@@ -217,6 +217,12 @@ const ENV_VAR_NAME_TO_CONFIG_INFO = {
     type:    ValueType.STRING,
     default: null,
   },
+  AUTO_INSTALL_ALLOW_GUEST_MODE: {
+    ns:      'crowi',
+    key:     'autoInstall:allowGuestMode',
+    type:    ValueType.BOOLEAN,
+    default: false,
+  },
   AUTO_INSTALL_SERVER_DATE: {
     ns:      'crowi',
     key:     'autoInstall:serverDate',

+ 20 - 8
packages/app/src/server/service/installer.ts

@@ -1,23 +1,30 @@
-import mongoose from 'mongoose';
-import fs from 'graceful-fs';
 import path from 'path';
+
 import ExtensibleCustomError from 'extensible-custom-error';
+import fs from 'graceful-fs';
+import mongoose from 'mongoose';
+
 
+import { Lang } from '~/interfaces/lang';
 import { IPage } from '~/interfaces/page';
 import { IUser } from '~/interfaces/user';
-import { Lang } from '~/interfaces/lang';
 import loggerFactory from '~/utils/logger';
 
 import { generateConfigsForInstalling } from '../models/config';
 
-import SearchService from './search';
 import ConfigManager from './config-manager';
+import SearchService from './search';
 
 const logger = loggerFactory('growi:service:installer');
 
 export class FailedToCreateAdminUserError extends ExtensibleCustomError {
 }
 
+export type AutoInstallOptions = {
+  allowGuestMode?: boolean,
+  serverDate?: Date,
+}
+
 export class InstallerService {
 
   // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -90,16 +97,21 @@ export class InstallerService {
   /**
    * Execute only once for installing application
    */
-  private async initDB(globalLang: Lang): Promise<void> {
+  private async initDB(globalLang: Lang, options?: AutoInstallOptions): Promise<void> {
     const configManager: ConfigManager = this.crowi.configManager;
 
     const initialConfig = generateConfigsForInstalling();
     initialConfig['app:globalLang'] = globalLang;
+
+    if (options?.allowGuestMode) {
+      initialConfig['autoInstall:allowGuestMode'] = true;
+    }
+
     return configManager.updateConfigsInTheSameNamespace('crowi', initialConfig, true);
   }
 
-  async install(firstAdminUserToSave: IUser, globalLang: Lang, initialPagesCreatedAt?: Date): Promise<IUser> {
-    await this.initDB(globalLang);
+  async install(firstAdminUserToSave: IUser, globalLang: Lang, options?: AutoInstallOptions): Promise<IUser> {
+    await this.initDB(globalLang, options);
 
     // TODO typescriptize models/user.js and remove eslint-disable-next-line
     // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -137,7 +149,7 @@ export class InstallerService {
     await Promise.all([rootPage.save(), rootRevision.save()]);
 
     // create initial pages
-    await this.createInitialPages(adminUser, globalLang, initialPagesCreatedAt);
+    await this.createInitialPages(adminUser, globalLang, options?.serverDate);
 
     return adminUser;
   }

+ 1 - 1
packages/app/src/server/service/page.ts

@@ -262,7 +262,7 @@ class PageService {
       authority: IPageDeleteConfigValueToProcessValidation | null,
       recursiveAuthority: IPageDeleteConfigValueToProcessValidation | null,
   ): boolean {
-    const isAdmin = operator.admin;
+    const isAdmin = operator?.admin ?? false;
     const isOperator = operator?._id == null ? false : operator._id.equals(creatorId);
 
     if (isRecursively) {

+ 0 - 0
packages/app/test/cypress/integration/1-install/install.spec.ts → packages/app/test/cypress/integration/10-install/install.spec.ts


+ 0 - 1
packages/app/test/cypress/integration/2-basic-features/access-to-page.spec.ts → packages/app/test/cypress/integration/20-basic-features/access-to-page.spec.ts

@@ -1,4 +1,3 @@
-
 context('Access to page', () => {
   const ssPrefix = 'access-to-page-';
 

+ 0 - 0
packages/app/test/cypress/integration/2-basic-features/use-tools.spec.ts → packages/app/test/cypress/integration/20-basic-features/use-tools.spec.ts


+ 81 - 0
packages/app/test/cypress/integration/21-basic-features-for-guest/access-to-page.spec.ts

@@ -0,0 +1,81 @@
+context('Access to page by guest', () => {
+  const ssPrefix = 'access-to-page-by-guest-';
+
+  beforeEach(() => {
+    // collapse sidebar
+    cy.collapseSidebar(true);
+  });
+
+  it('/Sandbox is successfully loaded', () => {
+    cy.visit('/Sandbox', {  });
+    cy.screenshot(`${ssPrefix}-sandbox`);
+  });
+
+  it('/Sandbox with anchor hash is successfully loaded', () => {
+    cy.visit('/Sandbox#Headers');
+
+    // hide fab
+    cy.getByTestid('grw-fab-container').invoke('attr', 'style', 'display: none');
+
+    cy.screenshot(`${ssPrefix}-sandbox-headers`);
+  });
+
+  it('/Sandbox/Math is successfully loaded', () => {
+    cy.visit('/Sandbox/Math');
+    cy.screenshot(`${ssPrefix}-sandbox-math`);
+  });
+
+  it('/Sandbox with edit is successfully loaded', () => {
+    cy.visit('/Sandbox#edit');
+    cy.screenshot(`${ssPrefix}-sandbox-edit-page`);
+  })
+
+});
+
+
+context('Access to /me page', () => {
+  const ssPrefix = 'access-to-me-page-by-guest-';
+
+  beforeEach(() => {
+    // collapse sidebar
+    cy.collapseSidebar(true);
+  });
+
+  it('/me should be redirected to /login', () => {
+    cy.visit('/me', {  });
+    cy.screenshot(`${ssPrefix}-me`);
+  });
+
+});
+
+
+context('Access to special pages by guest', () => {
+  const ssPrefix = 'access-to-special-pages-by-guest-';
+
+  beforeEach(() => {
+    // collapse sidebar
+    cy.collapseSidebar(true);
+  });
+
+  it('/trash is successfully loaded', () => {
+    cy.visit('/trash', {  });
+    cy.getByTestid('trash-page-list').should('be.visible');
+    cy.screenshot(`${ssPrefix}-trash`);
+  });
+
+  it('/tags is successfully loaded', () => {
+    cy.visit('/tags');
+
+    // open sidebar
+    cy.collapseSidebar(false);
+    // select tags
+    cy.getByTestid('grw-sidebar-nav-primary-tags').click();
+    cy.getByTestid('grw-sidebar-content-tags').should('be.visible');
+    cy.getByTestid('grw-tags-list').should('be.visible');
+    cy.getByTestid('grw-tags-list').contains('You have no tag, You can set tags on pages');
+
+    cy.getByTestid('tags-page').should('be.visible');
+    cy.screenshot(`${ssPrefix}-tags`);
+  });
+
+});

+ 0 - 0
packages/app/test/cypress/integration/3-search/search.spec.ts → packages/app/test/cypress/integration/30-search/search.spec.ts


+ 0 - 0
packages/app/test/cypress/integration/4-admin/access-to-admin-page.spec.ts → packages/app/test/cypress/integration/40-admin/access-to-admin-page.spec.ts


+ 0 - 0
packages/app/test/cypress/integration/5-switch-sidebar-mode/switching-sidebar-mode.spec.ts → packages/app/test/cypress/integration/50-switch-sidebar-mode/switching-sidebar-mode.spec.ts


+ 0 - 0
packages/app/test/cypress/integration/6-home/home.spec.ts → packages/app/test/cypress/integration/60-home/home.spec.ts