Skip to content

Commit

Permalink
[NEW] User avatars from external source (#7929)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjovanovic0 authored and sampaiodiego committed Feb 8, 2019
1 parent 96ad0f4 commit e8fe2ff
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
"Accounts_AvatarCacheTime_description": "Number of seconds the http protocol is told to cache the avatar images.",
"Accounts_AvatarResize": "Resize Avatars",
"Accounts_AvatarSize": "Avatar Size",
"Accounts_AvatarExternalProviderUrl": "Avatar External Provider URL",
"Accounts_AvatarExternalProviderUrl_Description": "Example: `https://acme.com/api/v1/{username}`",
"Accounts_BlockedDomainsList": "Blocked Domains List",
"Accounts_BlockedDomainsList_Description": "Comma-separated list of blocked domains",
"Accounts_BlockedUsernameList": "Blocked Username List",
Expand Down
6 changes: 6 additions & 0 deletions packages/rocketchat-lib/server/startup/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,12 @@ RocketChat.settings.addGroup('Accounts', function() {
value: true,
},
});

this.add('Accounts_AvatarExternalProviderUrl', '', {
type: 'string',
public: true,
});

this.add('Accounts_AvatarCacheTime', 3600, {
type: 'int',
i18nDescription: 'Accounts_AvatarCacheTime_description',
Expand Down
4 changes: 4 additions & 0 deletions packages/rocketchat-utils/lib/getAvatarUrlFromUsername.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { Session } from 'meteor/session';
import { settings } from 'meteor/rocketchat:settings';

export const getAvatarUrlFromUsername = function(username) {
const externalSource = (settings.get('Accounts_AvatarExternalProviderUrl') || '').trim().replace(/\/$/, '');
if (externalSource !== '') {
return externalSource.replace('{username}', username);
}
const key = `avatar_random_${ username }`;
const random = typeof Session !== 'undefined' && typeof Session.keys[key] !== 'undefined' ? Session.keys[key] : 0;
if (username == null) {
Expand Down

0 comments on commit e8fe2ff

Please sign in to comment.