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

Merge remote-tracking branch 'origin/master' into imprv/private-wiki-only

# Conflicts:
#	src/server/service/acl.js
Yuki Takei 6 лет назад
Родитель
Сommit
305e78b11b

+ 5 - 1
CHANGES.md

@@ -1,6 +1,10 @@
 # CHANGES
 
-## 3.5.1-RC
+## 3.5.2-RC
+
+* 
+
+## 3.5.1
 
 ### BREAKING CHANGES
 

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "growi",
-  "version": "3.5.1-RC",
+  "version": "3.5.2-RC",
   "description": "Team collaboration software using markdown",
   "tags": [
     "wiki",

+ 2 - 0
resource/cdn-manifests.js

@@ -28,6 +28,8 @@ module.exports = {
         + 'gh/highlightjs/cdn-release@9.13.0/build/languages/scss.min.js,'
         + 'gh/highlightjs/cdn-release@9.13.0/build/languages/typescript.min.js,'
         + 'gh/highlightjs/cdn-release@9.13.0/build/languages/yaml.min.js,'
+        + 'gh/highlightjs/cdn-release@9.13.0/build/languages/swift.min.js,'
+        + 'gh/highlightjs/cdn-release@9.13.0/build/languages/kotlin.min.js,'
         + 'npm/highlightjs-line-numbers.js@2.6.0/dist/highlightjs-line-numbers.min.js',
       args: {
         async: true,

+ 1 - 1
src/server/models/config.js

@@ -189,7 +189,7 @@ module.exports = function(crowi) {
         NO_CDN: env.NO_CDN || null,
       },
       recentCreatedLimit: crowi.configManager.getConfig('crowi', 'customize:showRecentCreatedNumber'),
-      isAclEnabled: !crowi.aclService.getIsPublicWikiOnly(),
+      isAclEnabled: crowi.aclService.isAclEnabled(),
       globalLang: crowi.configManager.getConfig('crowi', 'app:globalLang'),
     };
 

+ 2 - 2
src/server/routes/admin.js

@@ -636,7 +636,7 @@ module.exports = function(crowi, app) {
   actions.userGroup = {};
   actions.userGroup.index = function(req, res) {
     const page = parseInt(req.query.page) || 1;
-    const isAclEnabled = !aclService.getIsPublicWikiOnly();
+    const isAclEnabled = aclService.isAclEnabled();
     const renderVar = {
       userGroups: [],
       userGroupRelations: new Map(),
@@ -901,7 +901,7 @@ module.exports = function(crowi, app) {
     }
 
     const form = req.form.settingForm;
-    if (aclService.getIsPublicWikiOnly()) {
+    if (!aclService.isAclEnabled()) {
       const guestMode = form['security:restrictGuestMode'];
       if (guestMode === 'Deny') {
         req.form.errors.push('Private Wikiへの設定変更はできません。');

+ 9 - 10
src/server/service/acl.js

@@ -16,24 +16,23 @@ class AclService {
     };
   }
 
-  getIsPublicWikiOnly() {
-    const publicWikiOnly = process.env.PUBLIC_WIKI_ONLY;
-    return !!publicWikiOnly;
-  }
+  isAclEnabled() {
+    const isPublicWikiOnly = this.configManager.getConfig('crowi', 'security:isPublicWikiOnly');
+    const isPrivateWikiOnly = this.configManager.getConfig('crowi', 'security:isPrivateWikiOnly');
 
-  getIsPrivateWikiOnly() {
-    const privateWikiOnly = process.env.PRIVATE_WIKI_ONLY;
-    return !!privateWikiOnly;
+    return !(isPublicWikiOnly || isPrivateWikiOnly);
   }
 
   getIsGuestAllowedToRead() {
+    const isPublicWikiOnly = this.configManager.getConfig('crowi', 'security:isPublicWikiOnly');
+    const isPrivateWikiOnly = this.configManager.getConfig('crowi', 'security:isPrivateWikiOnly');
+
     // return false if private wiki mode
-    if (this.getIsPrivateWikiOnly()) {
+    if (isPrivateWikiOnly) {
       return false;
     }
-
     // return true if puclic wiki mode
-    if (this.getIsPublicWikiOnly()) {
+    if (isPublicWikiOnly) {
       return true;
     }
 

+ 12 - 0
src/server/service/config-loader.js

@@ -134,6 +134,18 @@ const ENV_VAR_NAME_TO_CONFIG_INFO = {
     type:    TYPES.NUMBER,
     default: Infinity,
   },
+  PUBLIC_WIKI_ONLY: {
+    ns:      'crowi',
+    key:     'security:isPublicWikiOnly',
+    type:    TYPES.BOOLEAN,
+    default: false,
+  },
+  PRIVATE_WIKI_ONLY: {
+    ns:      'crowi',
+    key:     'security:isPrivateWikiOnly',
+    type:    TYPES.BOOLEAN,
+    default: false,
+  },
   SAML_USES_ONLY_ENV_VARS_FOR_SOME_OPTIONS: {
     ns:      'crowi',
     key:     'security:passport-saml:useOnlyEnvVarsForSomeOptions',

+ 27 - 20
src/test/models/user.test.js

@@ -10,40 +10,47 @@ describe('User', () => {
 
   beforeAll(async(done) => {
     crowi = await getInstance();
-    done();
-  });
-
-  beforeEach(async(done) => {
     User = mongoose.model('User');
+
+    // remove all
+    await Promise.all([
+      User.remove({}),
+    ]);
+
+    await User.create({
+      name: 'Example for User Test',
+      username: 'usertest',
+      email: 'usertest@example.com',
+      password: 'usertestpass',
+      lang: 'en',
+    });
+
     done();
   });
 
   describe('Create and Find.', () => {
     describe('The user', () => {
-      test('should created', (done) => {
-        User.createUserByEmailAndPassword('Aoi Miyazaki', 'aoi', 'aoi@example.com', 'hogefuga11', 'en', (err, userData) => {
+      test('should created with createUserByEmailAndPassword', (done) => {
+        User.createUserByEmailAndPassword('Example2 for User Test', 'usertest2', 'usertest2@example.com', 'usertest2pass', 'en', (err, userData) => {
           expect(err).toBeNull();
           expect(userData).toBeInstanceOf(User);
+          expect(userData.name).toBe('Example2 for User Test');
           done();
         });
       });
 
-      test('should be found by findUserByUsername', (done) => {
-        User.findUserByUsername('aoi')
-          .then((userData) => {
-            expect(userData).toBeInstanceOf(User);
-            done();
-          });
+      test('should be found by findUserByUsername', async() => {
+        const user = await User.findUserByUsername('usertest');
+        expect(user).toBeInstanceOf(User);
+        expect(user.name).toBe('Example for User Test');
       });
 
-      test('should be found by findUsersByPartOfEmail', (done) => {
-        User.findUsersByPartOfEmail('ao', {})
-          .then((userData) => {
-            expect(userData).toBeInstanceOf(Array);
-            expect(userData[0]).toBeInstanceOf(User);
-            expect(userData[0].email).toEqual('aoi@example.com');
-            done();
-          });
+      test('should be found by findUsersByPartOfEmail', async() => {
+        const users = await User.findUsersByPartOfEmail('usert', {});
+        expect(users).toBeInstanceOf(Array);
+        expect(users.length).toBe(2);
+        expect(users[0]).toBeInstanceOf(User);
+        expect(users[1]).toBeInstanceOf(User);
       });
     });
   });