Skip to content

Commit

Permalink
Merge pull request #9541 from weseek/fix/159936-unable-to-select-grou…
Browse files Browse the repository at this point in the history
…p-viewing-permissions

fix: Unable to select group viewing permissions
  • Loading branch information
mergify[bot] authored Jan 9, 2025
2 parents 3f4b773 + ac27a76 commit cc7a2bc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { IPageHasId } from '@growi/core';
import mongoose from 'mongoose';

import { type PageModel } from '~/server/models/page';

export const convertNullToEmptyGrantedArrays = async(): Promise<void> => {
const Page = mongoose.model<IPageHasId, PageModel>('Page');

const requests = [
{
updateMany: {
// Matches documents where field is null or nonexistent
// https://www.mongodb.com/docs/manual/tutorial/query-for-null-fields/#equality-filter
filter: { grantedUsers: null },
update: {
$set: { grantedUsers: [] },
},
},
},
{
updateMany: {
filter: { grantedGroups: null },
update: {
$set: { grantedGroups: [] },
},
},
},
];

await Page.bulkWrite(requests);
};
2 changes: 2 additions & 0 deletions apps/app/src/server/service/normalize-data/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { normalizeExpiredAtForThreadRelations } from '~/features/openai/server/services/normalize-data';
import loggerFactory from '~/utils/logger';

import { convertNullToEmptyGrantedArrays } from './convert-null-to-empty-granted-arrays';
import { convertRevisionPageIdToObjectId } from './convert-revision-page-id-to-objectid';
import { renameDuplicateRootPages } from './rename-duplicate-root-pages';

Expand All @@ -10,6 +11,7 @@ export const normalizeData = async(): Promise<void> => {
await renameDuplicateRootPages();
await convertRevisionPageIdToObjectId();
await normalizeExpiredAtForThreadRelations();
await convertNullToEmptyGrantedArrays();

logger.info('normalizeData has been executed');
return;
Expand Down

0 comments on commit cc7a2bc

Please sign in to comment.