Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Unable to select group viewing permissions #9541

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filter: { 
  $or: [
    { grantedGroups: null },
    { grantedGroups: { $exists: false } }
  ]
}

にしないと、フィールドが存在しない場合は filter に引っかからないんじゃないかな

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

item: null は null or 存在しないフィールドにマッチするようです。(手元で動作確認もしました)

The { item : null } query matches documents that either contain the item field whose value is null or that do not contain the item field.

https://www.mongodb.com/docs/manual/tutorial/query-for-null-fields/#equality-filter

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
Loading