Browse Source

Fixed logic

Taichi Masuyama 4 years ago
parent
commit
0419ebb529

+ 18 - 20
packages/app/src/components/Admin/Security/SecuritySetting.jsx

@@ -65,26 +65,24 @@ class SecuritySetting extends React.Component {
             <div className="dropdown-menu" aria-labelledby="dropdownMenuButton">
               {
                 isRecursiveDeletion
-                && (
-                  <button
-                    className="dropdown-item"
-                    type="button"
-                    onClick={() => { setState(PageDeleteConfigValue.Inherit) }}
-                  >
-                    {t('security_setting.inherit')}
-                  </button>
-                )
-              }
-              {
-                !isRecursiveDeletion && (
-                  <button
-                    className="dropdown-item"
-                    type="button"
-                    onClick={() => { setState(PageDeleteConfigValue.Anyone) }}
-                  >
-                    {t('security_setting.anyone')}
-                  </button>
-                )
+                  ? (
+                    <button
+                      className="dropdown-item"
+                      type="button"
+                      onClick={() => { setState(PageDeleteConfigValue.Inherit) }}
+                    >
+                      {t('security_setting.inherit')}
+                    </button>
+                  )
+                  : (
+                    <button
+                      className="dropdown-item"
+                      type="button"
+                      onClick={() => { setState(PageDeleteConfigValue.Anyone) }}
+                    >
+                      {t('security_setting.anyone')}
+                    </button>
+                  )
               }
               <button
                 className="dropdown-item"

+ 1 - 4
packages/app/src/interfaces/page-delete-config.ts

@@ -6,10 +6,7 @@ export const PageDeleteConfigValue = {
 } as const;
 export type PageDeleteConfigValue = typeof PageDeleteConfigValue[keyof typeof PageDeleteConfigValue];
 
-export type PageDeleteConfigValueToProcessValidation =
-  Exclude<PageDeleteConfigValue, typeof PageDeleteConfigValue.Inherit>;
-export type PageRecursiveDeleteConfigValueToProcessValidation =
-  Exclude<PageDeleteConfigValue, typeof PageDeleteConfigValue.Inherit | typeof PageDeleteConfigValue.Anyone>;
+export type PageDeleteConfigValueToProcessValidation = Exclude<PageDeleteConfigValue, typeof PageDeleteConfigValue.Inherit>;
 
 export const PageSingleDeleteConfigValue = {
   Anyone: 'anyOne', // must be "anyOne" (not "anyone") for backward compatibility

+ 11 - 9
packages/app/src/server/service/page.ts

@@ -23,7 +23,7 @@ import { Ref } from '~/interfaces/common';
 import { HasObjectId } from '~/interfaces/has-object-id';
 import { SocketEventName, UpdateDescCountRawData } from '~/interfaces/websocket';
 import {
-  PageDeleteConfigValue, PageDeleteConfigValueToProcessValidation, PageRecursiveDeleteConfigValueToProcessValidation,
+  PageDeleteConfigValue, PageDeleteConfigValueToProcessValidation,
 } from '~/interfaces/page-delete-config';
 import PageOperation, { PageActionStage, PageActionType } from '../models/page-operation';
 import ActivityDefine from '../util/activityDefine';
@@ -241,20 +241,22 @@ class PageService {
       creatorId: ObjectIdLike,
       operator,
       isRecursively: boolean,
-      authority: PageDeleteConfigValueToProcessValidation,
-      recursiveAuthority: PageRecursiveDeleteConfigValueToProcessValidation,
+      authority: PageDeleteConfigValueToProcessValidation | null,
+      recursiveAuthority: PageDeleteConfigValueToProcessValidation | null,
   ): boolean {
     const isAdmin = operator.admin;
     const isOperator = operator?._id == null ? false : operator._id.equals(creatorId);
 
-    if (isAdmin) {
-      return true;
+    if (isRecursively) {
+      return this.compareDeleteConfig(isAdmin, isOperator, recursiveAuthority);
     }
 
-    if (isRecursively) {
-      if (recursiveAuthority === PageDeleteConfigValue.AdminAndAuthor && isOperator) {
-        return true;
-      }
+    return this.compareDeleteConfig(isAdmin, isOperator, authority);
+  }
+
+  private compareDeleteConfig(isAdmin: boolean, isOperator: boolean, authority: PageDeleteConfigValueToProcessValidation | null): boolean {
+    if (isAdmin) {
+      return true;
     }
 
     if (authority === PageDeleteConfigValue.Anyone || authority == null) {