Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
Browse files Browse the repository at this point in the history
…nto view-logs

* 'develop' of https://github.com/RocketChat/Rocket.Chat: (31 commits)
  Fixed componentes width (#17322)
  [IMPROVE] Administration -> Mailer Rewrite to React. (#17191)
  Regression: Storybook  added flowrouter group mock (#17321)
  [NEW] Feature/custom oauth mail field and interpolation for mapped fields (#15690)
  [FIX] "Invalid Invite" message when registration is disabled (#17226)
  [FIX] Red color error outline is not removed after password update (#16536)
  [FIX] Change wording to start DM from info panel (#8799)
  New hooks for RouterContext (#17305)
  [FIX] SAML assertion signature enforcement (#17278)
  [FIX] LDAP users lose session on refresh (#17302)
  [NEW] Add MMS support to Voxtelesys (#17217)
  [FIX] Popover component doesn't have scroll (#17198)
  [FIX] Omnichannel SMS / WhatsApp integration errors due to missing location data (#17288)
  [FIX] User search on directory not working correctly (#17299)
  [FIX] Can not save Unread Tray Icon Alert user preference (#16288) (#16313)
  [FIX] Variable rendering problem on Import recent history page (#15997)
  [FIX] Admin panel custom sounds, multiple sound playback fix and added single play/pause button (#16215)
  [FIX] Discussions created from inside DMs were not working (#17282)
  [FIX] translation for nl (#16742)
  [FIX] No maxlength defined for custom user status (#16534)
  ...
  • Loading branch information
dudizilla committed Apr 16, 2020
2 parents 41f0195 + b644572 commit 960d7dd
Show file tree
Hide file tree
Showing 86 changed files with 1,392 additions and 405 deletions.
3 changes: 3 additions & 0 deletions .storybook/mocks/meteor.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ export const check = () => {};

export const FlowRouter = {
route: () => {},
group: () => ({
route: () => {},
}),
};

export const BlazeLayout = {};
Expand Down
1 change: 1 addition & 0 deletions app/api/server/lib/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export async function findAdminRooms({ uid, filter, types = [], pagination: { of
unmuted: 1,
ro: 1,
default: 1,
favorite: 1,
featured: 1,
topic: 1,
msgs: 1,
Expand Down
2 changes: 1 addition & 1 deletion app/api/server/v1/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ API.v1.addRoute('channels.setDefault', { authRequired: true }, {
}

Meteor.runAsUser(this.userId, () => {
Meteor.call('saveRoomSettings', findResult._id, 'default', this.bodyParams.default.toString());
Meteor.call('saveRoomSettings', findResult._id, 'default', ['true', '1'].includes(this.bodyParams.default.toString().toLowerCase()));
});

return API.v1.success({
Expand Down
5 changes: 4 additions & 1 deletion app/channel-settings/server/methods/saveRoomSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { saveRoomTokenpass } from '../functions/saveRoomTokens';
import { saveStreamingOptions } from '../functions/saveStreamingOptions';
import { RoomSettingsEnum, roomTypes } from '../../../utils';

const fields = ['featured', 'roomName', 'roomTopic', 'roomAnnouncement', 'roomCustomFields', 'roomDescription', 'roomType', 'readOnly', 'reactWhenReadOnly', 'systemMessages', 'default', 'joinCode', 'tokenpass', 'streamingOptions', 'retentionEnabled', 'retentionMaxAge', 'retentionExcludePinned', 'retentionFilesOnly', 'retentionOverrideGlobal', 'encrypted'];
const fields = ['featured', 'roomName', 'roomTopic', 'roomAnnouncement', 'roomCustomFields', 'roomDescription', 'roomType', 'readOnly', 'reactWhenReadOnly', 'systemMessages', 'default', 'joinCode', 'tokenpass', 'streamingOptions', 'retentionEnabled', 'retentionMaxAge', 'retentionExcludePinned', 'retentionFilesOnly', 'retentionOverrideGlobal', 'encrypted', 'favorite'];
Meteor.methods({
saveRoomSettings(rid, settings, value) {
const userId = Meteor.userId();
Expand Down Expand Up @@ -221,6 +221,9 @@ Meteor.methods({
case 'encrypted':
Rooms.saveEncryptedById(rid, value);
break;
case 'favorite':
Rooms.saveFavoriteById(rid, value.favorite, value.defaultValue);
break;
}
});

Expand Down
175 changes: 49 additions & 126 deletions app/custom-oauth/server/custom_oauth_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { HTTP } from 'meteor/http';
import { ServiceConfiguration } from 'meteor/service-configuration';
import _ from 'underscore';

import { normalizers, fromTemplate, renameInvalidProperties } from './transform_helpers';
import { mapRolesFromSSO, updateRolesFromSSO } from './oauth_helpers';
import { Logger } from '../../logger';
import { Users } from '../../models';
Expand All @@ -17,107 +18,6 @@ const logger = new Logger('CustomOAuth');
const Services = {};
const BeforeUpdateOrCreateUserFromExternalService = [];

const normalizers = {
// Set 'id' to '_id' for any sources that provide it
_id(identity) {
if (identity._id && !identity.id) {
identity.id = identity._id;
}
},

// Fix for Reddit
redit(identity) {
if (identity.result) {
return identity.result;
}
},

// Fix WordPress-like identities having 'ID' instead of 'id'
wordpress(identity) {
if (identity.ID && !identity.id) {
identity.id = identity.ID;
}
},

// Fix Auth0-like identities having 'user_id' instead of 'id'
user_id(identity) {
if (identity.user_id && !identity.id) {
identity.id = identity.user_id;
}
},

characterid(identity) {
if (identity.CharacterID && !identity.id) {
identity.id = identity.CharacterID;
}
},

// Fix Dataporten having 'user.userid' instead of 'id'
dataporten(identity) {
if (identity.user && identity.user.userid && !identity.id) {
if (identity.user.userid_sec && identity.user.userid_sec[0]) {
identity.id = identity.user.userid_sec[0];
} else {
identity.id = identity.user.userid;
}
identity.email = identity.user.email;
}
},

// Fix for Xenforo [BD]API plugin for 'user.user_id; instead of 'id'
xenforo(identity) {
if (identity.user && identity.user.user_id && !identity.id) {
identity.id = identity.user.user_id;
identity.email = identity.user.user_email;
}
},

// Fix general 'phid' instead of 'id' from phabricator
phabricator(identity) {
if (identity.phid && !identity.id) {
identity.id = identity.phid;
}
},

// Fix Keycloak-like identities having 'sub' instead of 'id'
kaycloak(identity) {
if (identity.sub && !identity.id) {
identity.id = identity.sub;
}
},

// Fix OpenShift identities where id is in 'metadata' object
openshift(identity) {
if (!identity.id && identity.metadata && identity.metadata.uid) {
identity.id = identity.metadata.uid;
identity.name = identity.fullName;
}
},

// Fix general 'userid' instead of 'id' from provider
userid(identity) {
if (identity.userid && !identity.id) {
identity.id = identity.userid;
}
},

// Fix Nextcloud provider
nextcloud(identity) {
if (!identity.id && identity.ocs && identity.ocs.data && identity.ocs.data.id) {
identity.id = identity.ocs.data.id;
identity.name = identity.ocs.data.displayname;
identity.email = identity.ocs.data.email;
}
},

// Fix when authenticating from a meteor app with 'emails' field
meteor(identity) {
if (!identity.email && (identity.emails && Array.isArray(identity.emails) && identity.emails.length >= 1)) {
identity.email = identity.emails[0].address ? identity.emails[0].address : undefined;
}
},
};

export class CustomOAuth {
constructor(name, options) {
logger.debug('Init CustomOAuth', name, options);
Expand Down Expand Up @@ -174,6 +74,7 @@ export class CustomOAuth {
this.tokenSentVia = options.tokenSentVia;
this.identityTokenSentVia = options.identityTokenSentVia;
this.usernameField = (options.usernameField || '').trim();
this.emailField = (options.emailField || '').trim();
this.nameField = (options.nameField || '').trim();
this.avatarField = (options.avatarField || '').trim();
this.mergeUsers = options.mergeUsers;
Expand Down Expand Up @@ -334,6 +235,10 @@ export class CustomOAuth {
identity.username = this.getUsername(identity);
}

if (this.emailField) {
identity.email = this.getEmail(identity);
}

if (this.avatarField) {
identity.avatarUrl = this.getAvatarUrl(identity);
}
Expand All @@ -344,50 +249,64 @@ export class CustomOAuth {
identity.name = this.getName(identity);
}

return identity;
return renameInvalidProperties(identity);
}

retrieveCredential(credentialToken, credentialSecret) {
return OAuth.retrieveCredential(credentialToken, credentialSecret);
}

getUsername(data) {
let username = '';
try {
const value = fromTemplate(this.usernameField, data);

if (!value) {
throw new Meteor.Error('field_not_found', `Username field "${ this.usernameField }" not found in data`, data);
}
return value;
} catch (error) {
throw new Error('CustomOAuth: Failed to extract username', error.message);
}
}

username = this.usernameField.split('.').reduce(function(prev, curr) {
return prev ? prev[curr] : undefined;
}, data);
getEmail(data) {
try {
const value = fromTemplate(this.emailField, data);

if (!username) {
throw new Meteor.Error('field_not_found', `Username field "${ this.usernameField }" not found in data`, data);
if (!value) {
throw new Meteor.Error('field_not_found', `Email field "${ this.emailField }" not found in data`, data);
}
return value;
} catch (error) {
throw new Error('CustomOAuth: Failed to extract email', error.message);
}
return username;
}

getCustomName(data) {
let customName = '';
try {
const value = fromTemplate(this.nameField, data);

customName = this.nameField.split('.').reduce(function(prev, curr) {
return prev ? prev[curr] : undefined;
}, data);
if (!value) {
return this.getName(data);
}

if (!customName) {
return this.getName(data);
return value;
} catch (error) {
throw new Error('CustomOAuth: Failed to extract custom name', error.message);
}

return customName;
}

getAvatarUrl(data) {
const avatarUrl = this.avatarField.split('.').reduce(function(prev, curr) {
return prev ? prev[curr] : undefined;
}, data);
try {
const value = fromTemplate(this.avatarField, data);

if (!avatarUrl) {
logger.debug(`Avatar field "${ this.avatarField }" not found in data`, data);
if (!value) {
logger.debug(`Avatar field "${ this.avatarField }" not found in data`, data);
}
return value;
} catch (error) {
throw new Error('CustomOAuth: Failed to extract avatar url', error.message);
}

return avatarUrl;
}

getName(identity) {
Expand Down Expand Up @@ -438,11 +357,15 @@ export class CustomOAuth {
}

if (this.usernameField) {
user.username = this.getUsername(user.services[this.name]);
user.username = user.services[this.name].username;
}

if (this.emailField) {
user.email = user.services[this.name].email;
}

if (this.nameField) {
user.name = this.getCustomName(user.services[this.name]);
user.name = user.services[this.name].name;
}

if (this.mergeRoles) {
Expand Down
Loading

0 comments on commit 960d7dd

Please sign in to comment.