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

add read only schema to user schema

ryoji-s 2 лет назад
Родитель
Сommit
80f14a2fc7
2 измененных файлов с 15 добавлено и 2 удалено
  1. 13 0
      apps/app/src/server/models/user.js
  2. 2 2
      apps/app/src/server/routes/apiv3/users.js

+ 13 - 0
apps/app/src/server/models/user.js

@@ -68,6 +68,7 @@ module.exports = function(crowi) {
     },
     lastLoginAt: { type: Date },
     admin: { type: Boolean, default: 0, index: true },
+    readOnly: { type: Boolean, default: 0, index: true },
     isInvitationEmailSended: { type: Boolean, default: false },
   }, {
     timestamps: true,
@@ -276,6 +277,18 @@ module.exports = function(crowi) {
     return this.save();
   };
 
+  userSchema.methods.giveReadOnly = async function() {
+    debug('Give read only flag', this);
+    this.readOnly = 1;
+    return this.save();
+  };
+
+  userSchema.methods.removeReadOnly = async function() {
+    debug('Remove read only flag', this);
+    this.readOnly = 0;
+    return this.save();
+  };
+
   userSchema.methods.asyncMakeAdmin = async function(callback) {
     this.admin = 1;
     return this.save();

+ 2 - 2
apps/app/src/server/routes/apiv3/users.js

@@ -576,7 +576,7 @@ module.exports = (crowi) => {
 
     try {
       const userData = await User.findById(id);
-      await userData.makeReadOnly();
+      await userData.giveReadOnly();
 
       const serializedUserData = serializeUserSecurely(userData);
 
@@ -624,7 +624,7 @@ module.exports = (crowi) => {
 
     try {
       const userData = await User.findById(id);
-      await userData.removeFromReadOnly();
+      await userData.removeReadOnly();
 
       const serializedUserData = serializeUserSecurely(userData);