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

refs 126902: add grantUserGroupIdModel to PageOperation.options

Futa Arai 2 лет назад
Родитель
Сommit
359146fca3

+ 12 - 0
apps/app/src/migrations/20230717141157-set-granted-group-model-value.js

@@ -11,6 +11,7 @@ module.exports = {
 
     mongoose.connect(getMongoUri(), mongoOptions);
     const pageCollection = await db.collection('pages');
+    const pageOperationCollection = await db.collection('pageoperations');
 
     // Set the model type of grantedGroup to UserGroup
     // for Pages that were created before ExternalUserGroup was introduced
@@ -18,6 +19,12 @@ module.exports = {
       { grantedGroupModel: null },
       { $set: { grantedGroupModel: 'UserGroup' } },
     );
+    // Set the model type of grantUserGroupIdModel to UserGroup
+    // for PageOperations that were created before ExternalUserGroup was introduced
+    pageOperationCollection.updateMany(
+      { 'options.grantUserGroupIdModel': null },
+      { $set: { 'options.grantUserGroupIdModel': 'UserGroup' } },
+    );
 
     logger.info('Migration has successfully applied');
   },
@@ -27,11 +34,16 @@ module.exports = {
 
     mongoose.connect(getMongoUri(), mongoOptions);
     const pageCollection = await db.collection('pages');
+    const pageOperationCollection = await db.collection('pageoperations');
 
     pageCollection.updateMany(
       { grantedGroupModel: 'UserGroup' },
       { $set: { grantedGroupModel: null } },
     );
+    pageOperationCollection.updateMany(
+      { 'options.grantUserGroupIdModel': 'UserGroup' },
+      { $set: { 'options.grantUserGroupIdModel': null } },
+    );
 
     logger.info('Migration has been successfully rollbacked');
   },

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

@@ -25,6 +25,7 @@ export type IUserForResuming = {
 export type IOptionsForUpdate = {
   grant?: PageGrant,
   grantUserGroupId?: ObjectIdLike,
+  grantUserGroupIdModel?: string,
   isSyncRevisionToHackmd?: boolean,
   overwriteScopesOfDescendants?: boolean,
 };
@@ -32,6 +33,7 @@ export type IOptionsForUpdate = {
 export type IOptionsForCreate = {
   format?: string,
   grantUserGroupId?: ObjectIdLike,
+  grantUserGroupIdModel?: string,
   grant?: PageGrant,
   overwriteScopesOfDescendants?: boolean,
   isSynchronously?: boolean,

+ 7 - 1
apps/app/src/server/models/page-operation.ts

@@ -79,7 +79,13 @@ const optionsSchemaForResuming = new Schema<IOptionsForResuming>({
   updateMetadata: { type: Boolean },
   prevDescendantCount: { type: Number },
   grant: { type: Number },
-  grantUserGroupId: { type: ObjectId },
+  grantUserGroupId: { type: ObjectId, refPath: 'grantedGroupModel' },
+  grantUserGroupIdModel: {
+    type: String,
+    enum: ['UserGroup', 'ExternalUserGroup'],
+    required: true,
+    default: 'UserGroup',
+  },
   format: { type: String },
   isSyncRevisionToHackmd: { type: Boolean },
   overwriteScopesOfDescendants: { type: Boolean },