Merge pull request #3695 from FinnStutzenstein/fixRemarks

fixed remarks from #3525 (closes #3681)
This commit is contained in:
Emanuel Schütze 2018-04-13 15:07:05 +02:00 committed by GitHub
commit a6537fb919
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 90 additions and 74 deletions

View File

@ -88,7 +88,7 @@ Users:
default is now disabled [#3400]. default is now disabled [#3400].
- Hide password in change password view [#3417]. - Hide password in change password view [#3417].
- Added a change presence view [#3496]. - Added a change presence view [#3496].
- New feature to send invitation emails with OpenSlides login [#3503]. - New feature to send invitation emails with OpenSlides login [#3503, #3525].
- New admin user group [#3621]. - New admin user group [#3621].
Core: Core:

View File

@ -536,9 +536,7 @@ angular.module('OpenSlidesApp.users.site', [
.controller('UserListCtrl', [ .controller('UserListCtrl', [
'$scope', '$scope',
'$state',
'$http', '$http',
'$q',
'ngDialog', 'ngDialog',
'UserForm', 'UserForm',
'User', 'User',
@ -547,17 +545,17 @@ angular.module('OpenSlidesApp.users.site', [
'Projector', 'Projector',
'ProjectionDefault', 'ProjectionDefault',
'Config', 'Config',
'gettextCatalog',
'UserCsvExport', 'UserCsvExport',
'osTableFilter', 'osTableFilter',
'osTableSort', 'osTableSort',
'osTablePagination', 'osTablePagination',
'gettext', 'gettext',
'UserPdfExport', 'UserPdfExport',
'InvitationEmails',
'ErrorMessage', 'ErrorMessage',
function($scope, $state, $http, $q, ngDialog, UserForm, User, Group, PasswordGenerator, function($scope, $http, ngDialog, UserForm, User, Group, PasswordGenerator,
Projector, ProjectionDefault, Config, gettextCatalog, UserCsvExport, osTableFilter, Projector, ProjectionDefault, Config, UserCsvExport, osTableFilter, osTableSort,
osTableSort, osTablePagination, gettext, UserPdfExport, ErrorMessage) { osTablePagination, gettext, UserPdfExport, InvitationEmails, ErrorMessage) {
$scope.$watch(function () { $scope.$watch(function () {
return User.lastModified(); return User.lastModified();
}, function () { }, function () {
@ -757,73 +755,8 @@ angular.module('OpenSlidesApp.users.site', [
}; };
// Send invitation emails // Send invitation emails
$scope.sendInvitationEmails = function () { $scope.sendInvitationEmails = function () {
var user_ids = _ InvitationEmails.send($scope.usersFiltered).then(function (success) {
.chain($scope.usersFiltered) $scope.alert = success;
.filter(function (user) {
return user.selected;
})
.map(function (user) {
return user.id;
})
.value();
var subject = gettextCatalog.getString(Config.get('users_email_subject').value);
var message = gettextCatalog.getString(Config.get('users_email_body').value);
$http.post('/rest/users/user/mass_invite_email/', {
user_ids: user_ids,
subject: subject,
message: message,
}).then(function (success) {
var numEmails = success.data.count;
var noEmailIds = success.data.no_email_ids;
var type = 'success', msg;
if (numEmails === 0) {
type = 'danger';
msg = gettextCatalog.getString('No emails were send.');
} else if (numEmails === 1) {
msg = gettextCatalog.getString('One email was send sucessfully.');
} else {
msg = gettextCatalog.getString('%num% emails were send sucessfully.').replace('%num%', numEmails);
}
if (noEmailIds.length) {
type = 'warning';
msg += ' ';
if (noEmailIds.length === 1) {
msg += gettextCatalog.getString('The user %user% has no email, so the invitation email could not be send.');
} else {
msg += gettextCatalog.getString('The users %user% have no email, so the invitation emails could not be send.');
}
// This one builds a username string like "user1, user2 and user3" with the full names.
var lastUsername, userString = _
.chain(noEmailIds)
.map(function (id) {
var user = User.get(id);
return user ? user.get_full_name() : '';
})
.filter(function (username) {
return username;
})
.tap(function (names) {
if (names.length !== 1) {
lastUsername = names.pop();
}
})
.join(', ')
.thru(function (names) {
return lastUsername ? names + ' ' + gettextCatalog.getString('and') + ' ' + lastUsername : names;
})
.value();
msg = msg.replace('%user%', userString);
}
$scope.alert = {
msg: msg,
type: type,
show: true,
};
$scope.isSelectMode = false; $scope.isSelectMode = false;
$scope.uncheckAll(); $scope.uncheckAll();
}, function (error) { }, function (error) {
@ -847,6 +780,89 @@ angular.module('OpenSlidesApp.users.site', [
} }
]) ])
.factory('InvitationEmails', [
'$http',
'User',
'Config',
'gettextCatalog',
function ($http, User, Config, gettextCatalog) {
return {
// Returns the request promise. If it was successfull, a nice message for
// an alert is generated and the alert-object is returned.
send: function (users) {
var user_ids = _
.chain(users)
.filter(function (user) {
return user.selected;
})
.map(function (user) {
return user.id;
})
.value();
var subject = gettextCatalog.getString(Config.get('users_email_subject').value);
var message = gettextCatalog.getString(Config.get('users_email_body').value);
return $http.post('/rest/users/user/mass_invite_email/', {
user_ids: user_ids,
subject: subject,
message: message,
}).then(function (success) {
var numEmails = success.data.count;
var noEmailIds = success.data.no_email_ids;
var type = 'success', msg;
if (numEmails === 0) {
type = 'danger';
msg = gettextCatalog.getString('No emails were send.');
} else if (numEmails === 1) {
msg = gettextCatalog.getString('One email was send sucessfully.');
} else {
msg = gettextCatalog.getString('%num% emails were send sucessfully.').replace('%num%', numEmails);
}
if (noEmailIds.length) {
type = 'warning';
msg += ' ';
if (noEmailIds.length === 1) {
msg += gettextCatalog.getString('The user %user% has no email, so the invitation email could not be send.');
} else {
msg += gettextCatalog.getString('The users %user% have no email, so the invitation emails could not be send.');
}
// This one builds a username string like "user1, user2 and user3" with the full names.
var lastUsername, userString = _
.chain(noEmailIds)
.map(function (id) {
var user = User.get(id);
return user ? user.get_full_name() : '';
})
.filter(function (username) {
return username;
})
.tap(function (names) {
if (names.length !== 1) {
lastUsername = names.pop();
}
})
.join(', ')
.thru(function (names) {
return lastUsername ? names + ' ' + gettextCatalog.getString('and') + ' ' + lastUsername : names;
})
.value();
msg = msg.replace('%user%', userString);
}
return {
msg: msg,
type: type,
show: true,
};
});
},
};
}
])
.controller('UserDetailCtrl', [ .controller('UserDetailCtrl', [
'$scope', '$scope',
'ngDialog', 'ngDialog',