itizawa %!s(int64=6) %!d(string=hai) anos
pai
achega
b96caf0699

+ 2 - 3
src/client/js/services/AdminUsersContainer.js

@@ -108,9 +108,8 @@ export default class AdminUsersContainer extends Container {
    * @return {string} username
    */
   async deactivateUser(userId) {
-    // const response = await this.appContainer.apiv3.put(`/users/${userId}/activate`);
-    // const { username } = response.data.userData;
-    const username = 'gest';
+    const response = await this.appContainer.apiv3.put(`/users/${userId}/deactivate`);
+    const { username } = response.data.userData;
     return username;
   }
 

+ 2 - 4
src/server/models/user.js

@@ -313,7 +313,7 @@ module.exports = function(crowi) {
     return userEvent.emit('activated', userData);
   };
 
-  userSchema.methods.statusSuspend = function(callback) {
+  userSchema.methods.statusSuspend = async function() {
     debug('Suspend User', this);
     this.status = STATUS_SUSPENDED;
     if (this.email === undefined || this.email === null) { // migrate old data
@@ -325,9 +325,7 @@ module.exports = function(crowi) {
     if (this.username === undefined || this.usename === null) { // migrate old data
       this.username = '-';
     }
-    this.save((err, userData) => {
-      return callback(err, userData);
-    });
+    return this.save();
   };
 
   userSchema.methods.statusDelete = async function() {

+ 1 - 0
src/server/routes/admin.js

@@ -491,6 +491,7 @@ module.exports = function(crowi, app) {
     });
   };
 
+  // TODO delete
   actions.user.suspend = function(req, res) {
     const id = req.params.id;
 

+ 14 - 0
src/server/routes/apiv3/users.js

@@ -166,6 +166,20 @@ module.exports = (crowi) => {
       return res.apiv3Err(new ErrorV3(err));
     }
   });
+  // TODO swagger
+  router.put('/:id/deactivate', loginRequiredStrictly, adminRequired, csrf, async(req, res) => {
+    const { id } = req.params;
+
+    try {
+      const userData = await User.findById(id);
+      await userData.statusSuspend();
+      return res.apiv3({ userData });
+    }
+    catch (err) {
+      logger.error('Error', err);
+      return res.apiv3Err(new ErrorV3(err));
+    }
+  });
   /**
    * @swagger
    *