(js) Never query Gravatar.com when disabled

pull/217/head
Francis Lachapelle 2016-06-21 21:29:44 -04:00
parent 9dbb360ef7
commit dfc904f4f3
10 changed files with 75 additions and 28 deletions

1
NEWS
View File

@ -30,6 +30,7 @@ Bug fixes
- [web] fixed handling of attendees when updating an event - [web] fixed handling of attendees when updating an event
- [web] show tooltips over long calendar/ab names (#232) - [web] show tooltips over long calendar/ab names (#232)
- [web] one-click option to give all permissions for user (#1637) - [web] one-click option to give all permissions for user (#1637)
- [web] never query gravatar.com when disabled
3.1.2 (2016-06-06) 3.1.2 (2016-06-06)
------------------ ------------------

View File

@ -445,12 +445,14 @@
</label> </label>
<md-contact-chips <md-contact-chips
flex="100" flex="100"
class="sg-chips-autocomplete"
ng-model="app.preferences.settings.Calendar.PreventInvitationsWhitelist" ng-model="app.preferences.settings.Calendar.PreventInvitationsWhitelist"
md-contacts="app.userFilter($query, app.preferences.settings.Calendar.PreventInvitationsWhitelist)" md-contacts="app.userFilter($query, app.preferences.settings.Calendar.PreventInvitationsWhitelist)"
md-contact-name="cn" md-contact-name="cn"
md-contact-image="$$image" md-contact-image="$$image"
md-contact-email="c_email" md-contact-email="c_email"
md-require-match="true" md-require-match="true"
md-highlight-flags="i"
filter-selected="false" filter-selected="false"
label:placeholder="Add"><!-- users --></md-contact-chips> label:placeholder="Add"><!-- users --></md-contact-chips>
</div> </div>

View File

@ -0,0 +1,4 @@
<svg fill="#000000" fill-opacity="0.25" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z"/>
<path d="M0 0h24v24H0z" fill="none"/>
</svg>

After

Width:  |  Height:  |  Size: 294 B

View File

@ -9,6 +9,9 @@
baseURL: function() { baseURL: function() {
return ApplicationBaseURL || null; return ApplicationBaseURL || null;
}, },
resourcesURL: function() {
return ResourcesURL || null;
},
activeUser: function(param) { activeUser: function(param) {
var settings = { var settings = {
login: UserLogin || null, login: UserLogin || null,

View File

@ -17,12 +17,11 @@
* @desc The factory we'll use to register with Angular. * @desc The factory we'll use to register with Angular.
* @return the User constructor * @return the User constructor
*/ */
User.factory = ['$q', '$log', 'sgSettings', 'Resource', 'Gravatar', function($q, $log, Settings, Resource, Gravatar) { User.factory = ['$q', '$log', 'sgSettings', 'Resource', function($q, $log, Settings, Resource) {
angular.extend(User, { angular.extend(User, {
$q: $q, $q: $q,
$log: $log, $log: $log,
$$resource: new Resource(Settings.activeUser('folderURL'), Settings.activeUser()), $$resource: new Resource(Settings.activeUser('folderURL'), Settings.activeUser()),
$gravatar: Gravatar,
$query: '', $query: '',
$users: [] $users: []
}); });
@ -114,7 +113,9 @@
if (!this.$$shortFormat) if (!this.$$shortFormat)
this.$$shortFormat = this.$shortFormat(); this.$$shortFormat = this.$shortFormat();
if (!this.$$image) if (!this.$$image)
this.$$image = this.image || User.$gravatar(this.c_email, 32, User.$alternateAvatar, {no_404: true}); this.$$image = this.image;
// NOTE: We can't assign a Gravatar at this stage since we would need the Preferences module
// which already depend on the User module.
// An empty attribute to trick md-autocomplete when adding users from the ACLs editor // An empty attribute to trick md-autocomplete when adding users from the ACLs editor
this.empty = ' '; this.empty = ' ';

View File

@ -38,12 +38,11 @@
* @desc The factory we'll use to register with Angular. * @desc The factory we'll use to register with Angular.
* @returns the Card constructor * @returns the Card constructor
*/ */
Card.$factory = ['$timeout', 'sgSettings', 'sgCard_STATUS', 'Resource', 'Preferences', 'Gravatar', function($timeout, Settings, Card_STATUS, Resource, Preferences, Gravatar) { Card.$factory = ['$timeout', 'sgSettings', 'sgCard_STATUS', 'Resource', 'Preferences', function($timeout, Settings, Card_STATUS, Resource, Preferences) {
angular.extend(Card, { angular.extend(Card, {
STATUS: Card_STATUS, STATUS: Card_STATUS,
$$resource: new Resource(Settings.activeUser('folderURL') + 'Contacts', Settings.activeUser()), $$resource: new Resource(Settings.activeUser('folderURL') + 'Contacts', Settings.activeUser()),
$timeout: $timeout, $timeout: $timeout,
$gravatar: Gravatar,
$Preferences: Preferences $Preferences: Preferences
}); });
// Initialize categories from user's defaults // Initialize categories from user's defaults
@ -146,7 +145,7 @@
if (!this.$$email) if (!this.$$email)
this.$$email = this.$preferredEmail(partial); this.$$email = this.$preferredEmail(partial);
if (!this.$$image) if (!this.$$image)
this.$$image = this.image || Card.$gravatar(this.$preferredEmail(partial), 32, Card.$alternateAvatar, {no_404: true}); this.$$image = this.image || Card.$Preferences.avatar(this.$$email, 32, {no_404: true});
if (this.isgroup) if (this.isgroup)
this.c_component = 'vlist'; this.c_component = 'vlist';
this.$loaded = angular.isDefined(this.c_name)? Card.STATUS.LOADED : Card.STATUS.NOT_LOADED; this.$loaded = angular.isDefined(this.c_name)? Card.STATUS.LOADED : Card.STATUS.NOT_LOADED;

View File

@ -39,14 +39,14 @@
* @desc The factory we'll use to register with Angular * @desc The factory we'll use to register with Angular
* @returns the Message constructor * @returns the Message constructor
*/ */
Message.$factory = ['$q', '$timeout', '$log', 'sgSettings', 'sgMessage_STATUS', 'Gravatar', 'Resource', 'Preferences', function($q, $timeout, $log, Settings, Message_STATUS, Gravatar, Resource, Preferences) { Message.$factory = ['$q', '$timeout', '$log', 'sgSettings', 'sgMessage_STATUS', 'Resource', 'Preferences', function($q, $timeout, $log, Settings, Message_STATUS, Resource, Preferences) {
angular.extend(Message, { angular.extend(Message, {
STATUS: Message_STATUS, STATUS: Message_STATUS,
$q: $q, $q: $q,
$timeout: $timeout, $timeout: $timeout,
$log: $log, $log: $log,
$gravatar: Gravatar, $$resource: new Resource(Settings.activeUser('folderURL') + 'Mail', Settings.activeUser()),
$$resource: new Resource(Settings.activeUser('folderURL') + 'Mail', Settings.activeUser()) $avatar: angular.bind(Preferences, Preferences.avatar)
}); });
// Initialize tags form user's defaults // Initialize tags form user's defaults
Preferences.ready().then(function() { Preferences.ready().then(function() {
@ -172,7 +172,7 @@
* @function $formatFullAddresses * @function $formatFullAddresses
* @memberof Message.prototype * @memberof Message.prototype
* @desc Format all sender and recipients addresses with a complete description (name <email>). * @desc Format all sender and recipients addresses with a complete description (name <email>).
* This function also generates a gravatar for each email address, and a short name * This function also generates the avatar URL for each email address and a short name
*/ */
Message.prototype.$formatFullAddresses = function() { Message.prototype.$formatFullAddresses = function() {
var _this = this; var _this = this;
@ -188,16 +188,15 @@
// Name is already short // Name is already short
data.shortname = data.name; data.shortname = data.name;
else if (data.name.split(' ').length) else if (data.name.split(' ').length)
// If we have "Alice Foo" as name, we grab "Alice" // If we have "Alice Foo" or "Foo, Alice" as name, we grab "Alice"
data.shortname = data.name.split(' ')[0].replace('\'',''); data.shortname = _.first(_.last(data.name.split(/, */)).split(/ +/)).replace('\'','');
} }
else if (data.email) { else if (data.email) {
data.full = '<' + data.email + '>'; data.full = '<' + data.email + '>';
data.shortname = data.email.split('@')[0]; data.shortname = data.email.split('@')[0];
} }
// Generate the gravatar data.image = Message.$avatar(data.email, 32);
data.image = Message.$gravatar(data.email, 32);
// If the current user is the recepient, overwrite // If the current user is the recepient, overwrite
// the short name with 'me' // the short name with 'me'
@ -342,13 +341,6 @@
part.type == 'UIxMailPartImageViewer' || part.type == 'UIxMailPartImageViewer' ||
part.type == 'UIxMailPartLinkViewer') { part.type == 'UIxMailPartLinkViewer') {
// UIxMailPartICalViewer injects 'participants'
if (part.participants) {
_.forEach(part.participants, function(participant) {
participant.image = Message.$gravatar(participant.email, 32);
});
}
if (part.type == 'UIxMailPartImageViewer') if (part.type == 'UIxMailPartImageViewer')
part.msgclass = 'msg-attachment-image'; part.msgclass = 'msg-attachment-image';
else if (part.type == 'UIxMailPartLinkViewer') else if (part.type == 'UIxMailPartLinkViewer')

View File

@ -116,11 +116,17 @@
this.settingsPromise = Preferences.$$resource.fetch("jsonSettings").then(function(data) { this.settingsPromise = Preferences.$$resource.fetch("jsonSettings").then(function(data) {
// We convert our PreventInvitationsWhitelist hash into a array of user // We convert our PreventInvitationsWhitelist hash into a array of user
if (data.Calendar) { if (data.Calendar) {
if (data.Calendar.PreventInvitationsWhitelist) if (data.Calendar.PreventInvitationsWhitelist) {
data.Calendar.PreventInvitationsWhitelist = _.map(data.Calendar.PreventInvitationsWhitelist, function(value, key) { data.Calendar.PreventInvitationsWhitelist = _.map(data.Calendar.PreventInvitationsWhitelist, function(value, key) {
var match = /^(.+)\s<(\S+)>$/.exec(value); var match = /^(.+)\s<(\S+)>$/.exec(value),
return new Preferences.$User({uid: key, cn: match[1], c_email: match[2]}); user = new Preferences.$User({uid: key, cn: match[1], c_email: match[2]});
if (!user.$$image)
_this.avatar(user.c_email, 32, {no_404: true}).then(function(url) {
user.$$image = url;
});
return user;
}); });
}
else else
data.Calendar.PreventInvitationsWhitelist = []; data.Calendar.PreventInvitationsWhitelist = [];
} }
@ -136,14 +142,15 @@
* @desc The factory we'll use to register with Angular * @desc The factory we'll use to register with Angular
* @returns the Preferences constructor * @returns the Preferences constructor
*/ */
Preferences.$factory = ['$q', '$timeout', '$log', '$mdDateLocale', 'sgSettings', 'Resource', 'User', function($q, $timeout, $log, $mdDateLocaleProvider, Settings, Resource, User) { Preferences.$factory = ['$q', '$timeout', '$log', '$mdDateLocale', 'sgSettings', 'Gravatar', 'Resource', 'User', function($q, $timeout, $log, $mdDateLocaleProvider, Settings, Gravatar, Resource, User) {
angular.extend(Preferences, { angular.extend(Preferences, {
$q: $q, $q: $q,
$timeout: $timeout, $timeout: $timeout,
$log: $log, $log: $log,
$mdDateLocaleProvider: $mdDateLocaleProvider, $mdDateLocaleProvider: $mdDateLocaleProvider,
$gravatar: Gravatar,
$$resource: new Resource(Settings.activeUser('folderURL'), Settings.activeUser()), $$resource: new Resource(Settings.activeUser('folderURL'), Settings.activeUser()),
activeUser: Settings.activeUser(), $resourcesURL: Settings.resourcesURL(),
$User: User $User: User
}); });
@ -172,6 +179,26 @@
return Preferences.$q.all([this.defaultsPromise, this.settingsPromise]); return Preferences.$q.all([this.defaultsPromise, this.settingsPromise]);
}; };
/**
* @function avatar
* @memberof Preferences.prototype
* @desc Get the avatar URL associated to an email address
* @return a combined promise
*/
Preferences.prototype.avatar = function(email, size, options) {
var _this = this;
return this.ready().then(function() {
var alternate_avatar = _this.defaults.SOGoAlternateAvatar, url;
if (_this.defaults.SOGoGravatarEnabled)
url = Preferences.$gravatar(email, size, alternate_avatar, options);
else
url = [Preferences.$resourcesURL, 'img', 'ic_person_grey_24px.svg'].join('/');
if (options && options.dstObject && options.dstAttr)
options.dstObject[options.dstAttr] = url;
return url;
});
};
/** /**
* @function $save * @function $save
* @memberof Preferences.prototype * @memberof Preferences.prototype

View File

@ -29,7 +29,7 @@
vm.editMailFilter = editMailFilter; vm.editMailFilter = editMailFilter;
vm.removeMailFilter = removeMailFilter; vm.removeMailFilter = removeMailFilter;
vm.addDefaultEmailAddresses = addDefaultEmailAddresses; vm.addDefaultEmailAddresses = addDefaultEmailAddresses;
vm.userFilter = User.$filter; vm.userFilter = userFilter;
vm.confirmChanges = confirmChanges; vm.confirmChanges = confirmChanges;
vm.save = save; vm.save = save;
vm.canChangePassword = canChangePassword; vm.canChangePassword = canChangePassword;
@ -230,6 +230,23 @@
form.$setDirty(); form.$setDirty();
} }
function userFilter(search, excludedUsers) {
return User.$filter(search, excludedUsers).then(function(users) {
// Set users avatars
_.forEach(users, function(user) {
if (!user.$$image) {
if (user.image)
user.$$image = user.image;
else
vm.preferences.avatar(user.c_email, 32, {no_404: true}).then(function(url) {
user.$$image = url;
});
}
});
return users;
});
}
function confirmChanges($event, form) { function confirmChanges($event, form) {
var target; var target;

View File

@ -56,7 +56,8 @@ md-chips {
} }
// Enlarge the default autocompletion menu // Enlarge the default autocompletion menu
.sg-chips-autocomplete { .sg-chips-autocomplete,
.sg-chips-autocomplete input {
width: (3 * $contact-chip-name-width); width: (3 * $contact-chip-name-width);
@media (max-width: $layout-breakpoint-xs) { @media (max-width: $layout-breakpoint-xs) {
// Enlarge the autocompletion menu on small devices to fit the entire screen // Enlarge the autocompletion menu on small devices to fit the entire screen