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

Merge pull request #8053 from weseek/imprv/129539-129839-change-to-IGrantedGroup

Imprv/129539 129839 change to i granted group
Ryoji Shimizu 2 лет назад
Родитель
Сommit
744fda7945

+ 2 - 2
apps/app/src/components/SavePageControls/GrantSelector/GrantSelector.tsx

@@ -1,7 +1,7 @@
 import React, { useCallback, useState } from 'react';
 
 import { isPopulated } from '@growi/core';
-import type { GroupType, GrantedGroup } from '@growi/core';
+import type { GroupType, IGrantedGroup } from '@growi/core';
 import { useTranslation } from 'next-i18next';
 import {
   UncontrolledDropdown,
@@ -85,7 +85,7 @@ export const GrantSelector = (props: Props): JSX.Element => {
     }
   }, [onUpdateGrant, showSelectGroupModal]);
 
-  const groupListItemClickHandler = useCallback((grantGroup: GrantedGroup) => {
+  const groupListItemClickHandler = useCallback((grantGroup: IGrantedGroup) => {
     if (onUpdateGrant != null && isPopulated(grantGroup.item)) {
       onUpdateGrant({ grant: 5, grantedGroups: [{ id: grantGroup.item._id, name: grantGroup.item.name, type: grantGroup.type }] });
     }

+ 2 - 2
apps/app/src/interfaces/page-operation.ts

@@ -1,4 +1,4 @@
-import type { GrantedGroup } from '@growi/core';
+import type { IGrantedGroup } from '@growi/core';
 
 export const PageActionType = {
   Create: 'Create',
@@ -34,6 +34,6 @@ export type OptionsToSave = {
   slackChannels: string;
   grant: number;
   pageTags: string[] | null;
-  grantUserGroupIds?: GrantedGroup[];
+  grantUserGroupIds?: IGrantedGroup[];
   isSyncRevisionToHackmd?: boolean;
 };

+ 4 - 4
apps/app/src/server/models/interfaces/page-operation.ts

@@ -1,4 +1,4 @@
-import { PageGrant, type GrantedGroup } from '@growi/core';
+import { PageGrant, type IGrantedGroup } from '@growi/core';
 
 import { ObjectIdLike } from '../../interfaces/mongoose-utils';
 
@@ -9,7 +9,7 @@ export type IPageForResuming = {
   parent?: ObjectIdLike,
   grant?: number,
   grantedUsers?: ObjectIdLike[],
-  grantedGroups: GrantedGroup[],
+  grantedGroups: IGrantedGroup[],
   descendantCount: number,
   status?: number,
   revision?: ObjectIdLike,
@@ -23,14 +23,14 @@ export type IUserForResuming = {
 
 export type IOptionsForUpdate = {
   grant?: PageGrant,
-  grantUserGroupIds?: GrantedGroup[],
+  grantUserGroupIds?: IGrantedGroup[],
   isSyncRevisionToHackmd?: boolean,
   overwriteScopesOfDescendants?: boolean,
 };
 
 export type IOptionsForCreate = {
   format?: string,
-  grantUserGroupIds?: GrantedGroup[],
+  grantUserGroupIds?: IGrantedGroup[],
   grant?: PageGrant,
   overwriteScopesOfDescendants?: boolean,
   isSynchronously?: boolean,

+ 1 - 1
apps/app/src/server/models/obsolete-page.js

@@ -688,7 +688,7 @@ export const getPageSchema = (crowi) => {
   /**
    * transfer pages grant to specified user group
    * @param {Page[]} pages
-   * @param {GrantedGroup} transferToUserGroup
+   * @param {IGrantedGroup} transferToUserGroup
    */
   pageSchema.statics.transferPagesToGroup = async function(pages, transferToUserGroup) {
     const userGroupModel = transferToUserGroup.type === GroupType.userGroup ? UserGroup : ExternalUserGroup;

+ 2 - 2
apps/app/src/server/models/page.ts

@@ -5,7 +5,7 @@ import nodePath from 'path';
 
 import {
   type IPage,
-  type GrantedGroup,
+  type IGrantedGroup,
   GroupType, type HasObjectId,
 } from '@growi/core';
 import { isPopulated } from '@growi/core/dist/interfaces';
@@ -1046,7 +1046,7 @@ schema.methods.calculateAndUpdateLatestRevisionBodyLength = async function(this:
 
 export type PageCreateOptions = {
   format?: string
-  grantUserGroupIds?: GrantedGroup[],
+  grantUserGroupIds?: IGrantedGroup[],
   grant?: number
   overwriteScopesOfDescendants?: boolean
 }

+ 6 - 6
apps/app/src/server/service/page-grant.ts

@@ -1,5 +1,5 @@
 import {
-  type GrantedGroup,
+  type IGrantedGroup,
   PageGrant, type PageGrantCanBeOnTree,
 } from '@growi/core';
 import {
@@ -28,7 +28,7 @@ const LIMIT_FOR_MULTIPLE_PAGE_OP = 20;
 type ComparableTarget = {
   grant: number,
   grantedUserIds?: ObjectIdLike[],
-  grantedGroupIds?: GrantedGroup[],
+  grantedGroupIds?: IGrantedGroup[],
   applicableUserIds?: ObjectIdLike[],
   applicableGroupIds?: ObjectIdLike[],
 };
@@ -43,7 +43,7 @@ type ComparableAncestor = {
 type ComparableDescendants = {
   isPublicExist: boolean,
   grantedUserIds: ObjectIdLike[],
-  grantedGroupIds: GrantedGroup[],
+  grantedGroupIds: IGrantedGroup[],
 };
 
 /**
@@ -214,7 +214,7 @@ class PageGrantService {
    * @returns Promise<ComparableAncestor>
    */
   private async generateComparableTarget(
-      grant, grantedUserIds: ObjectIdLike[] | undefined, grantedGroupIds: GrantedGroup[] | undefined, includeApplicable: boolean,
+      grant, grantedUserIds: ObjectIdLike[] | undefined, grantedGroupIds: IGrantedGroup[] | undefined, includeApplicable: boolean,
   ): Promise<ComparableTarget> {
     if (includeApplicable) {
       const Page = mongoose.model('Page') as unknown as PageModel;
@@ -419,7 +419,7 @@ class PageGrantService {
    */
   async isGrantNormalized(
       // eslint-disable-next-line max-len
-      user, targetPath: string, grant, grantedUserIds?: ObjectIdLike[], grantedGroupIds?: GrantedGroup[], shouldCheckDescendants = false, includeNotMigratedPages = false,
+      user, targetPath: string, grant, grantedUserIds?: ObjectIdLike[], grantedGroupIds?: IGrantedGroup[], shouldCheckDescendants = false, includeNotMigratedPages = false,
   ): Promise<boolean> {
     if (isTopPage(targetPath)) {
       return true;
@@ -599,7 +599,7 @@ class PageGrantService {
   }
 
   async generateUpdateGrantInfoToOverwriteDescendants(
-      operator, updateGrant: PageGrantCanBeOnTree, grantGroupIds?: GrantedGroup[],
+      operator, updateGrant: PageGrantCanBeOnTree, grantGroupIds?: IGrantedGroup[],
   ): Promise<UpdateGrantInfo> {
     let updateGrantInfo: UpdateGrantInfo | null = null;
 

+ 5 - 5
apps/app/src/server/service/page.ts

@@ -3,7 +3,7 @@ import { Readable, Writable } from 'stream';
 
 import type {
   Ref, HasObjectId, IUserHasId,
-  IPage, IPageInfo, IPageInfoAll, IPageInfoForEntity, IPageWithMeta, GrantedGroup,
+  IPage, IPageInfo, IPageInfoAll, IPageInfoForEntity, IPageWithMeta, IGrantedGroup,
 } from '@growi/core';
 import { PageGrant, PageStatus } from '@growi/core';
 import {
@@ -2362,7 +2362,7 @@ class PageService {
   }
 
 
-  async handlePrivatePagesForGroupsToDelete(groupsToDelete, action, transferToUserGroup: GrantedGroup, user) {
+  async handlePrivatePagesForGroupsToDelete(groupsToDelete, action, transferToUserGroup: IGrantedGroup, user) {
     const Page = this.crowi.model('Page');
     const pages = await Page.find({
       grantedGroups: {
@@ -3533,7 +3533,7 @@ class PageService {
     pageDocument.status = Page.STATUS_PUBLISHED;
   }
 
-  private async validateAppliedScope(user, grant, grantUserGroupIds: GrantedGroup[]) {
+  private async validateAppliedScope(user, grant, grantUserGroupIds: IGrantedGroup[]) {
     if (grant === PageGrant.GRANT_USER_GROUP && grantUserGroupIds == null) {
       throw new Error('grantUserGroupIds is not specified');
     }
@@ -3554,7 +3554,7 @@ class PageService {
       grantData: {
         grant: number,
         grantedUserIds?: ObjectIdLike[],
-        grantUserGroupIds?: GrantedGroup[],
+        grantUserGroupIds?: IGrantedGroup[],
       },
       shouldValidateGrant: boolean,
       user?,
@@ -3886,7 +3886,7 @@ class PageService {
    * @param {UserDocument} user
    * @param options
    */
-  async updateGrant(page, user, grantData: {grant: PageGrant, grantedGroups: GrantedGroup[]}): Promise<PageDocument> {
+  async updateGrant(page, user, grantData: {grant: PageGrant, grantedGroups: IGrantedGroup[]}): Promise<PageDocument> {
     const { grant, grantedGroups } = grantData;
 
     const options = {

+ 2 - 2
apps/app/src/server/service/user-group.ts

@@ -1,4 +1,4 @@
-import type { IUser, GrantedGroup } from '@growi/core';
+import type { IUser, IGrantedGroup } from '@growi/core';
 import { Model } from 'mongoose';
 
 import { ObjectIdLike } from '~/server/interfaces/mongoose-utils';
@@ -114,7 +114,7 @@ class UserGroupService {
   }
 
   async removeCompletelyByRootGroupId(
-      deleteRootGroupId, action, user, transferToUserGroup?: GrantedGroup,
+      deleteRootGroupId, action, user, transferToUserGroup?: IGrantedGroup,
       userGroupModel: Model<UserGroupDocument> & UserGroupModel = UserGroup,
       userGroupRelationModel: Model<UserGroupRelationDocument> & UserGroupRelationModel = UserGroupRelation,
   ) {

+ 2 - 2
apps/app/src/server/util/granted-group.ts

@@ -1,8 +1,8 @@
-import { type GrantedGroup, GroupType } from '@growi/core';
+import { type IGrantedGroup, GroupType } from '@growi/core';
 
 import { ObjectIdLike } from '../interfaces/mongoose-utils';
 
-export const divideByType = (grantedGroups: GrantedGroup[] | null): {
+export const divideByType = (grantedGroups: IGrantedGroup[] | null): {
   grantedUserGroups: ObjectIdLike[];
   grantedExternalUserGroups: ObjectIdLike[];
 } => {

+ 2 - 2
apps/app/test/integration/service/v5.non-public-page.test.ts

@@ -1,5 +1,5 @@
 /* eslint-disable no-unused-vars */
-import { GroupType, type GrantedGroup } from '@growi/core';
+import { GroupType, type IGrantedGroup } from '@growi/core';
 import mongoose from 'mongoose';
 
 import { ExternalGroupProviderType } from '../../../src/features/external-user-group/interfaces/external-user-group';
@@ -101,7 +101,7 @@ describe('PageService page operations with non-public pages', () => {
   };
 
   // normalize for result comparison
-  const normalizeGrantedGroups = (grantedGroups: GrantedGroup[]) => {
+  const normalizeGrantedGroups = (grantedGroups: IGrantedGroup[]) => {
     return grantedGroups.map((group) => {
       const itemId = typeof group.item === 'string' ? group.item : group.item._id;
       return { item: itemId, type: group.type };

+ 2 - 2
packages/core/src/interfaces/page.ts

@@ -10,7 +10,7 @@ import type {
 export const GroupType = { userGroup: 'UserGroup', externalUserGroup: 'ExternalUserGroup' } as const;
 export type GroupType = typeof GroupType[keyof typeof GroupType];
 
-export type GrantedGroup = {
+export type IGrantedGroup = {
   type: GroupType,
   item: Ref<IUserGroup>,
 }
@@ -29,7 +29,7 @@ export type IPage = {
   isEmpty: boolean,
   grant: PageGrant,
   grantedUsers: Ref<IUser>[],
-  grantedGroups: GrantedGroup[],
+  grantedGroups: IGrantedGroup[],
   lastUpdateUser: Ref<IUser>,
   liker: Ref<IUser>[],
   commentCount: number