Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use real name instead of username for messages and direct messages list #3851

Merged
merged 58 commits into from
Apr 4, 2017
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
b30d63b
Start changing usernames to actual names
alexbrazier Jun 14, 2016
eec5ea8
Merge branch 'develop' into feature/display-name
alexbrazier Jun 22, 2016
29f9ceb
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into feat…
alexbrazier Jul 23, 2016
d8a2682
More changes to use actual names instead of usernames
alexbrazier Jul 23, 2016
2c1d6e5
Fix linting error
alexbrazier Jul 23, 2016
b7a6bc8
Restore @ icon for direct messages
alexbrazier Aug 4, 2016
5377d89
Merge remote-tracking branch 'origin' into feature/display-name
alexbrazier Aug 4, 2016
553ab70
Update messages and subscriptions on name change
alexbrazier Aug 5, 2016
9472a6b
Merge branch 'develop' into feature/display-name
alexbrazier Sep 8, 2016
1d3c9c9
Fix issues caused by merge
alexbrazier Sep 8, 2016
fed2c79
Add setting to use real name
alexbrazier Sep 10, 2016
12e0606
Merge branch 'develop' into feature/display-name
alexbrazier Sep 11, 2016
5720b9e
Show real name in spotlight search
alexbrazier Sep 11, 2016
2d0570a
Merge branch 'develop' into feature/display-name
alexbrazier Sep 13, 2016
c436466
Add migration to add user name to messages
alexbrazier Sep 14, 2016
f7c6cf3
Improve messages migration
alexbrazier Sep 14, 2016
14e388c
Update subscriptions in migration
alexbrazier Sep 14, 2016
51f65d9
Improve subscriptions
alexbrazier Sep 14, 2016
bc4200e
Merge branch 'develop' into feature/display-name
alexbrazier Sep 14, 2016
409b279
Make travis happy
alexbrazier Sep 14, 2016
8473f6b
Rename conflicting migration
alexbrazier Sep 15, 2016
39a6379
Merge branch 'develop' into feature/display-name
alexbrazier Sep 15, 2016
557c36b
Merge branch 'develop' into feature/display-name
alexbrazier Sep 21, 2016
89e9cc0
Remove unnecessary else
alexbrazier Sep 21, 2016
a802409
Merge branch 'develop' into feature/display-name
alexbrazier Sep 25, 2016
409f964
Merge branch 'develop' into feature/display-name
alexbrazier Oct 4, 2016
7cfcc21
Merge branch 'develop' into feature/display-name
alexbrazier Oct 19, 2016
e280f58
Fix bug with admin setting not setting name to username
alexbrazier Oct 19, 2016
4040985
Merge branch 'develop' into feature/display-name
alexbrazier Nov 24, 2016
f475c01
Improved full name migration
alexbrazier Nov 24, 2016
20a0fc0
Merge branch 'develop' into feature/display-name
alexbrazier Dec 4, 2016
c3388d9
Merge branch 'develop' into feature/display-name
alexbrazier Dec 7, 2016
c342223
Merge branch 'develop' into feature/display-name
alexbrazier Dec 14, 2016
debcf40
Tidy up and show real name on notifications
alexbrazier Dec 14, 2016
cddb810
Set use real name setting default as false
alexbrazier Dec 20, 2016
7299c03
Merge branch 'develop' into feature/display-name
alexbrazier Dec 20, 2016
439a9bf
Merge branch 'develop' into feature/display-name
alexbrazier Dec 20, 2016
404f758
Merge branch 'develop' into feature/display-name
alexbrazier Jan 11, 2017
253f993
Add missing files with name changes
alexbrazier Jan 11, 2017
7f51161
Eslint
alexbrazier Jan 11, 2017
dad299a
Merge branch 'develop' into feature/display-name
alexbrazier Jan 26, 2017
2c44667
Merge branch 'develop' into feature/display-name
alexbrazier Jan 27, 2017
1fb0123
Use real name in spotlight search
alexbrazier Jan 27, 2017
3d37581
Show username next to real name
alexbrazier Jan 27, 2017
1050044
Show real name in members list
alexbrazier Jan 28, 2017
429d35c
Allow users to be mentioned using real name
alexbrazier Jan 28, 2017
c9bfdc6
Missing semicolon
alexbrazier Jan 28, 2017
f73c018
Merge branch 'develop' into feature/display-name
alexbrazier Feb 8, 2017
ecef03e
Allow searching real name with spotlight
alexbrazier Feb 8, 2017
113e861
Merge branch 'develop' into feature/display-name
alexbrazier Feb 19, 2017
13d0286
Merge branch 'develop' into feature/display-name
alexbrazier Mar 7, 2017
1911e57
Fix unit tests
alexbrazier Mar 8, 2017
f6cc3fb
Fix tests
alexbrazier Mar 8, 2017
7844083
Merge branch 'develop' into feature/display-name
alexbrazier Mar 27, 2017
1dce810
Fix eslint
alexbrazier Mar 27, 2017
1d7c70e
Merge branch 'develop' into feature/display-name
alexbrazier Apr 1, 2017
18fd157
PR changes/fixes
alexbrazier Apr 1, 2017
cf6f43b
Update getUsersOfRoom.js
rodrigok Apr 3, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/rocketchat-cas/cas_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ Accounts.registerLoginHandler(function(options) {
logger.debug('Syncing user attributes');
// Update name
if (int_attrs.name) {
Meteor.users.update(user, { $set: { name: int_attrs.name }});
RocketChat._setRealName(user._id, int_attrs.name);
}

// Update email
Expand Down
5 changes: 4 additions & 1 deletion packages/rocketchat-crowd/server/crowd.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ const CROWD = class CROWD {

syncDataToUser(crowdUser, id) {
const user = {
name: crowdUser.displayname,
username: crowdUser.username,
emails: [{
address : crowdUser.email,
Expand All @@ -95,6 +94,10 @@ const CROWD = class CROWD {
active: crowdUser.active
};

if (crowdUser.displayname) {
RocketChat._setRealName(user._id, crowdUser.displayname);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user._id is not defined right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to id which is defined in the function params

}

Meteor.users.update(id, {
$set: user
});
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,7 @@
"UI_DisplayRoles": "Display Roles",
"UI_Merge_Channels_Groups": "Merge private groups with channels",
"UI_Use_Name_Avatar": "Use full name initials to generate default avatar",
"UI_Use_Real_Name" : "Use Real Name",
"Unarchive": "Unarchive",
"Unblock_User": "Unblock User",
"Unmute_someone_in_room": "Unmute someone in the room",
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-importer-hipchat/server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ Importer.HipChat = class Importer.HipChat extends Importer.Base

getRocketUser: (hipchatId) =>
for user in @users.users when user.user_id is hipchatId
return RocketChat.models.Users.findOneById user.rocketId, { fields: { username: 1 }}
return RocketChat.models.Users.findOneById user.rocketId, { fields: { username: 1, name: 1 }}

convertHipChatMessageToRocketChat: (message) =>
if message?
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-importer-slack/server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ Importer.Slack = class Importer.Slack extends Importer.Base

getRocketUser: (slackId) =>
for user in @users.users when user.id is slackId
return RocketChat.models.Users.findOneById user.rocketId, { fields: { username: 1 }}
return RocketChat.models.Users.findOneById user.rocketId, { fields: { username: 1, name: 1 }}

convertSlackMessageToRocketChat: (message) =>
if message?
Expand Down
6 changes: 5 additions & 1 deletion packages/rocketchat-ldap/server/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,13 @@ syncUserData = function syncUserData(user, ldapUser) {

const userData = getDataToSyncUserData(ldapUser, user);
if (user && user._id && userData) {
logger.debug('setting', JSON.stringify(userData, null, 2));
if (userData.name) {
RocketChat._setRealName(user._id, userData.name);
delete userData.name;
}
Meteor.users.update(user._id, { $set: userData });
user = Meteor.users.findOne({_id: user._id});
logger.debug('setting', JSON.stringify(userData, null, 2));
}

if (RocketChat.settings.get('LDAP_Username_Field') !== '') {
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-lib/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Package.onUse(function(api) {
api.addFiles('server/functions/settings.coffee', 'server');
api.addFiles('server/functions/setUserAvatar.js', 'server');
api.addFiles('server/functions/setUsername.coffee', 'server');
api.addFiles('server/functions/setRealName.coffee', 'server');
api.addFiles('server/functions/setEmail.js', 'server');
api.addFiles('server/functions/unarchiveRoom.js', 'server');
api.addFiles('server/functions/updateMessage.js', 'server');
Expand Down
3 changes: 2 additions & 1 deletion packages/rocketchat-lib/server/functions/addUserToRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ RocketChat.addUserToRoom = function(rid, user, inviter, silenced) {
ts: now,
u: {
_id: inviter._id,
username: inviter.username
username: inviter.username,
name: inviter.name
}
});
} else {
Expand Down
8 changes: 4 additions & 4 deletions packages/rocketchat-lib/server/functions/saveUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ RocketChat.saveUser = function(userId, userData) {
RocketChat.setUsername(userData._id, userData.username);
}

if (userData.name) {
RocketChat.setRealName(userData._id, userData.name);
}

if (userData.email) {
RocketChat.setEmail(userData._id, userData.email);
}
Expand All @@ -152,10 +156,6 @@ RocketChat.saveUser = function(userId, userData) {
$set: {}
};

if (userData.name) {
updateUser.$set.name = userData.name;
}

if (userData.roles) {
updateUser.$set.roles = userData.roles;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ RocketChat.sendMessage = (user, message, room, upsert = false) ->
unless message.ts?
message.ts = new Date()

message.u = _.pick user, ['_id','username']
message.u = _.pick user, ['_id','username', 'name']

if not Match.test(message.msg, String)
message.msg = ''
Expand Down
24 changes: 24 additions & 0 deletions packages/rocketchat-lib/server/functions/setRealName.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
RocketChat._setRealName = (userId, name) ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we convert to JS?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And, why not inside the user's model?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's how setUsername is done, so I just copied that. I think its because it has to make more requests to other models, so it's not self contained within one model.

name = s.trim name
if not userId or not name
return false

user = RocketChat.models.Users.findOneById userId

# User already has desired name, return
if user.name is name
return user

previousName = user.name

if previousName
RocketChat.models.Messages.updateAllNamesByUserId user._id, name
RocketChat.models.Subscriptions.setRealNameForDirectRoomsWithUsername user.username, name

# Set new name
RocketChat.models.Users.setName user._id, name
user.name = name
return user

RocketChat.setRealName = RocketChat.RateLimiter.limitFunction RocketChat._setRealName, 1, 60000,
0: () -> return not Meteor.userId() or not RocketChat.authz.hasPermission(Meteor.userId(), 'edit-other-user-info') # Administrators have permission to change others names, so don't limit those
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
}
if ((userOfMention != null) && canBeNotified(userOfMentionId, 'mobile')) {
RocketChat.Notifications.notifyUser(userOfMention._id, 'notification', {
title: `@${ user.username }`,
title: RocketChat.settings.get('UI_Use_Real_Name') ? user.name : `@${ user.username }`,
text: message.msg,
duration: settings.desktopNotificationDurations[userOfMention._id],
payload: {
Expand Down
6 changes: 5 additions & 1 deletion packages/rocketchat-lib/server/methods/setRealName.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ Meteor.methods({
name = _.trim(name);
}

if (!RocketChat.models.Users.setName(Meteor.userId(), name)) {
if (!RocketChat.setRealName(Meteor.userId(), name)) {
throw new Meteor.Error('error-could-not-change-name', 'Could not change name', { method: 'setRealName' });
}

return name;
}
});

RocketChat.RateLimiter.limitMethod('setRealName', 1, 1000, {
userId: () => true
});
11 changes: 11 additions & 0 deletions packages/rocketchat-lib/server/models/Messages.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,16 @@ RocketChat.models.Messages = new class extends RocketChat.models._Base

return @update query, update

updateAllNamesByUserId: (userId, name) ->
query =
'u._id': userId

update =
$set:
"u.name": name

return @update query, update, { multi: true }

updateUserStarById: (_id, userId, starred) ->
query =
_id: _id
Expand Down Expand Up @@ -380,6 +390,7 @@ RocketChat.models.Messages = new class extends RocketChat.models._Base
u:
_id: user._id
username: user.username
name: user.name
groupable: false

_.extend record, extraData
Expand Down
11 changes: 11 additions & 0 deletions packages/rocketchat-lib/server/models/Subscriptions.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,17 @@ class ModelSubscriptions extends RocketChat.models._Base

return @update query, update, { multi: true }

setRealNameForDirectRoomsWithUsername: (username, name) ->
query =
name: username
t: "d"

update =
$set:
fname: name

return @update query, update, { multi: true }

setNameForDirectRoomsWithOldName: (oldName, name) ->
query =
name: oldName
Expand Down
11 changes: 9 additions & 2 deletions packages/rocketchat-lib/server/models/Users.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class ModelUsers extends RocketChat.models._Base

return @find query, options

findByActiveUsersUsernameExcept: (searchTerm, exceptions = [], options = {}) ->
findByActiveUsersExcept: (searchTerm, exceptions = [], options = {}) ->
if not _.isArray exceptions
exceptions = [ exceptions ]

Expand All @@ -118,7 +118,14 @@ class ModelUsers extends RocketChat.models._Base
$and: [
{
active: true
username: termRegex
$or: [
{
username: termRegex
}
{
name: termRegex
}
]
}
{
username: { $nin: exceptions }
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-lib/server/startup/settings.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ RocketChat.settings.addGroup 'Layout', ->
@add 'UI_DisplayRoles', true, { type: 'boolean', public: true }
@add 'UI_Merge_Channels_Groups', true, { type: 'boolean', public: true }
@add 'UI_Use_Name_Avatar', false, { type: 'boolean', public: true }
@add 'UI_Use_Real_Name', false, { type: 'boolean', public: true }


RocketChat.settings.addGroup 'Logs', ->
Expand Down
7 changes: 3 additions & 4 deletions packages/rocketchat-lib/startup/defaultRoomTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ RocketChat.roomTypes.add('c', 10, {
},

roomName(roomData) {
return roomData.name;
return { name: roomData.name };
},

condition() {
Expand Down Expand Up @@ -64,8 +64,7 @@ RocketChat.roomTypes.add('d', 20, {
},

roomName(roomData) {
const room = ChatSubscription.findOne({ rid: roomData._id }, { fields: { name: 1 } });
return room && room.name;
return ChatSubscription.findOne({ rid: roomData._id }, { fields: { name: 1, fname: 1 } });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when room is undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

roomData or the returned result of ChatSubscription? Is there a case where it might be undefined?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably will not happen

},

condition() {
Expand Down Expand Up @@ -100,7 +99,7 @@ RocketChat.roomTypes.add('p', 30, {
},

roomName(roomData) {
return roomData.name;
return { name: roomData.name };
},

condition() {
Expand Down
5 changes: 4 additions & 1 deletion packages/rocketchat-livechat/server/lib/Livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ RocketChat.Livechat = {

userId = existingUser._id;
} else {
updateUser.$set.name = name;

const userData = {
username,
Expand Down Expand Up @@ -156,6 +155,10 @@ RocketChat.Livechat = {
];
}

if (name) {
RocketChat._setRealName(userId, name);
}

Meteor.users.update(userId, updateUser);

return userId;
Expand Down
5 changes: 5 additions & 0 deletions packages/rocketchat-theme/client/imports/base.less
Original file line number Diff line number Diff line change
Expand Up @@ -2495,6 +2495,11 @@ label.required::after {
display: inline-block;
}
}

.secondary-name {
color: #666666;
font-size: 15px;
}
}

.message-popup-position {
Expand Down
Loading