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

[FIX] Accounts from LinkedIn OAuth without name #6590

Merged
merged 3 commits into from
Apr 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ oauth2@1.1.11
observe-sequence@1.0.15
ordered-dict@1.0.9
ostrio:cookies@2.2.0
pauli:accounts-linkedin@1.3.1
pauli:linkedin@1.3.1
pauli:accounts-linkedin@2.1.2
pauli:linkedin-oauth@1.1.0
peerlibrary:aws-sdk@2.4.9_1
peerlibrary:blocking@0.5.2
percolate:synced-cron@1.3.2
Expand Down
7 changes: 6 additions & 1 deletion packages/rocketchat-ui-login/client/login/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ Template.loginServices.helpers({
}
});

const longinMethods = {
'meteor-developer': 'MeteorDeveloperAccount',
'linkedin': 'LinkedIn'
};

Template.loginServices.events({
'click .external-login'(e) {
if (this.service == null || this.service.service == null) {
Expand All @@ -80,7 +85,7 @@ Template.loginServices.events({
}
});
} else {
const loginWithService = `loginWith${ this.service.service === 'meteor-developer' ? 'MeteorDeveloperAccount' : _.capitalize(this.service.service) }`;
const loginWithService = `loginWith${ longinMethods[this.service.service] || _.capitalize(this.service.service) }`;
const serviceConfig = this.service.clientConfig || {};
return Meteor[loginWithService](serviceConfig, function(error) {
loadingIcon.addClass('hidden');
Expand Down
12 changes: 10 additions & 2 deletions server/lib/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,16 @@ Accounts.onCreateUser(function(options, user = {}) {
user.active = !RocketChat.settings.get('Accounts_ManuallyApproveNewUsers');

if (!user.name) {
if (options.profile && options.profile.name) {
user.name = options.profile.name;
if (options.profile) {
if (options.profile.name) {
user.name = options.profile.name;
} else if (options.profile.firstName && options.profile.lastName) {
Copy link
Member

Choose a reason for hiding this comment

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

can it happen to have the firstName but not the lastName?

If so, it would be better to split the if in two so the user will got at least the firstName

Copy link
Member Author

Choose a reason for hiding this comment

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

Non of our 500+ cases had only firstName, but I'll change

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

// LinkedIn format
user.name = `${ options.profile.firstName } ${ options.profile.lastName }`;
} else if (options.profile.firstName) {
// LinkedIn format
user.name = options.profile.firstName;
}
}
}

Expand Down
22 changes: 19 additions & 3 deletions server/startup/migrations/v091.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
RocketChat.Migrations.add({
version: 91,
up() {
RocketChat.models.Users.find({}, {username: 1, name: 1}).forEach((user) => {
RocketChat.models.Messages.updateAllNamesByUserId(user._id, user.name);
RocketChat.models.Subscriptions.setRealNameForDirectRoomsWithUsername(user.username, user.name);
const query = {
'services.linkedin': {
$exists: 1
},
$or: [{
name: {
$exists: 0
}
}, {
name: null
}]
};

RocketChat.models.Users.find(query, {'services.linkedin.firstName': 1, username: 1}).forEach((user) => {
const name = `${ user.services.linkedin.firstName } ${ user.services.linkedin.lastName }`;

RocketChat.models.Users.setName(user._id, name);
RocketChat.models.Messages.updateAllNamesByUserId(user._id, name);
RocketChat.models.Subscriptions.setRealNameForDirectRoomsWithUsername(user.username, name);
});
}
});