-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9541 from weseek/fix/159936-unable-to-select-grou…
…p-viewing-permissions fix: Unable to select group viewing permissions
- Loading branch information
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
apps/app/src/server/service/normalize-data/convert-null-to-empty-granted-arrays.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters