From f9036e2a6f77d0699fc689344d7225373b6a34b7 Mon Sep 17 00:00:00 2001 From: Zheyu Shen Date: Sun, 11 Nov 2018 12:03:37 -0500 Subject: [PATCH] Update groups members' title when changing group name (#6939) * Update groups members' title when changing group name * Fix eslint --- src/groups/update.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/groups/update.js b/src/groups/update.js index c389590f5d..982cdec03d 100644 --- a/src/groups/update.js +++ b/src/groups/update.js @@ -6,6 +6,7 @@ var winston = require('winston'); var plugins = require('../plugins'); var utils = require('../utils'); var db = require('../database'); +var user = require('../user'); module.exports = function (Groups) { @@ -213,6 +214,27 @@ module.exports = function (Groups) { return callback(new Error('[[error:group-already-exists]]')); } async.series([ + // set each member's groupTitle + function (next) { + async.waterfall([ + function (next) { + Groups.getMembers(oldName, 0, -1, next); + }, + function (uids, next) { + async.each(uids, function (uid, next) { + async.waterfall([ + function (next) { + user.getUserData(uid, next); + }, + function (userData, next) { + var newTitleArray = userData.groupTitleArray.map(oldTitle => (oldTitle === oldName ? newName : oldTitle)); + user.setUserField(uid, 'groupTitle', JSON.stringify(newTitleArray), next); + }, + ], next); + }, next); + }, + ], next); + }, async.apply(db.setObjectField, 'group:' + oldName, 'name', newName), async.apply(db.setObjectField, 'group:' + oldName, 'slug', utils.slugify(newName)), async.apply(db.deleteObjectField, 'groupslug:groupname', group.slug),