Explorar el Código

Merge pull request #54 from weseek/rc/1.0.x

release 1.0.9
Yuki Takei hace 9 años
padre
commit
3d04c54784

+ 5 - 0
CHANGES.md

@@ -1,6 +1,11 @@
 CHANGES
 ========
 
+## 1.0.9
+
+* Feature: Delete user
+* Feature: Upload other than images
+
 ## 1.0.8
 
 * Feature: Ensure to delete page completely

+ 1 - 1
lib/models/page.js

@@ -944,7 +944,7 @@ module.exports = function(crowi) {
   pageSchema.statics.removePageByPath = function(pagePath) {
     var Page = this;
 
-    return Page.findPageByPath(redirectPath)
+    return Page.findPageByPath(pagePath)
       .then(function(pageData) {
         return Page.removePageById(pageData.id);
       });

+ 7 - 3
lib/models/user.js

@@ -245,10 +245,16 @@ module.exports = function(crowi) {
 
   userSchema.methods.statusDelete = function(callback) {
     debug('Delete User', this);
+
+    const now = new Date();
+
     this.status = STATUS_DELETED;
+    this.username = `deleted_at_${now.getTime()}`;
     this.password = '';
+    this.name = '';
     this.email = 'deleted@deleted';
     this.googleId = null;
+    this.isGravatarEnabled = false;
     this.image = null;
     this.save(function(err, userData) {
       return callback(err, userData);
@@ -383,7 +389,7 @@ module.exports = function(crowi) {
   userSchema.statics.findUsersWithPagination = function(options, callback) {
     var sort = options.sort || {status: 1, username: 1, createdAt: 1};
 
-    this.paginate({}, { page: options.page || 1, limit: options.limit || PAGE_ITEMS }, function(err, result) {
+    this.paginate({status: { $ne: STATUS_DELETED }}, { page: options.page || 1, limit: options.limit || PAGE_ITEMS }, function(err, result) {
       if (err) {
         debug('Error on pagination:', err);
         return callback(err, null);
@@ -581,7 +587,6 @@ module.exports = function(crowi) {
 
           newUser.email = email;
           newUser.setPassword(password);
-          newUser.isGravatarEnabled = true;   // Gravatar enabled in default
           newUser.createdAt = Date.now();
           newUser.status = STATUS_INVITED;
 
@@ -658,7 +663,6 @@ module.exports = function(crowi) {
     newUser.email = email;
     newUser.setPassword(password);
     newUser.lang = lang;
-    newUser.isGravatarEnabled = false;
     newUser.createdAt = Date.now();
     newUser.status = decideUserStatusOnRegistration();
 

+ 31 - 2
lib/routes/admin.js

@@ -359,8 +359,37 @@ module.exports = function(crowi, app) {
   };
 
   actions.user.remove = function(req, res) {
-    // 未実装
-    return res.redirect('/admin/users');
+    var id = req.params.id;
+    let username = '';
+
+    return new Promise((resolve, reject) => {
+      User.findById(id, (err, userData) => {
+        username = userData.username;
+        return resolve(userData);
+      });
+    })
+    .then((userData) => {
+      return new Promise((resolve, reject) => {
+        userData.statusDelete((err, userData) => {
+          if (err) {
+            reject(err);
+          }
+          resolve(userData);
+        });
+      });
+    })
+    .then((userData) => {
+      return Page.removePageByPath(`/user/${username}`)
+        .then(() => userData);
+    })
+    .then((userData) => {
+      req.flash('successMessage', `${username} さんのアカウントを削除しました`);
+      return res.redirect('/admin/users');
+    })
+    .catch((err) => {
+      req.flash('errorMessage', '削除に失敗しました。');
+      return res.redirect('/admin/users');
+    });
   };
 
   // これやったときの relation の挙動未確認

+ 2 - 2
lib/util/middlewares.js

@@ -67,7 +67,7 @@ exports.swigFilters = function(app, swig) {
 
   // define a function for uploaded picture
   const getUploadedPictureSrc = function(user) {
-    if (user.image !== undefined) {
+    if (user.image) {
       return user.image;
     }
     else {
@@ -147,7 +147,7 @@ exports.swigFilters = function(app, swig) {
 
     swig.setFilter('picture', function(user) {
       if (!user) {
-        return '';
+        return '/images/userpicture.png';
       }
 
       if (user.isGravatarEnabled === true) {

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "crowi-plus",
-  "version": "1.0.8-RC",
+  "version": "1.0.9-RC",
   "description": "Enhanced Crowi",
   "tags": [
     "wiki",

+ 1 - 4
resource/js/components/User/UserPicture.js

@@ -10,11 +10,8 @@ export default class UserPicture extends React.Component {
       return this.generateGravatarSrc(user);
     }
     // uploaded image
-    else if (user.image && user.image != '/images/userpicture.png') {
-      return user.image;
-    }
     else {
-      return '/images/userpicture.png';
+      return user.image || '/images/userpicture.png';
     }
   }
 

+ 10 - 2
resource/js/legacy/crowi-form.js

@@ -463,12 +463,20 @@ $(function() {
         _csrf: csrfToken
       },
       progressText: '(Uploading file...)',
-      urlText: "\n![file]({filename})\n"
+      urlText: "![file]({filename})\n",
+      allowedTypes: '*'
     };
 
+    attachmentOption.onFileReceived = function(file) {
+      // if not image
+      if (!file.type.match(/^image\/.+$/)) {
+        // modify urlText with 'a' tag
+        this.settings.urlText = `<a href="{filename}">${file.name}</a>\n`;
+      }
+    }
+
     attachmentOption.onFileUploadResponse = function(res) {
       var result = JSON.parse(res.response);
-      console.log(result);
 
       if (result.ok && result.pageCreated) {
         var page = result.page,

+ 1 - 5
resource/js/legacy/crowi.js

@@ -103,11 +103,7 @@ Crowi.userPicture = function (user) {
     return '/images/userpicture.png';
   }
 
-  if (user.image && user.image != '/images/userpicture.png') {
-    return user.image;
-  } else {
-    return '/images/userpicture.png';
-  }
+  return user.image || '/images/userpicture.png';
 };
 
 Crowi.modifyScrollTop = function() {