Merge pull request #3525 from FinnStutzenstein/emailfix

Filter for email and more dialog to the user, if some users have no emails
This commit is contained in:
Emanuel Schütze 2018-01-12 15:33:37 +01:00 committed by GitHub
commit c6f4a6f162
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 66 additions and 5 deletions

View File

@ -561,6 +561,9 @@ angular.module('OpenSlidesApp.users.site', [
return User.lastModified(); return User.lastModified();
}, function () { }, function () {
$scope.users = _.orderBy(User.getAll(), ['first_name']); $scope.users = _.orderBy(User.getAll(), ['first_name']);
_.forEach($scope.users, function (user) {
user.has_last_email_send = !!user.last_email_send;
});
}); });
Group.bindAll({where: {id: {'>': 1}}}, $scope, 'groups'); Group.bindAll({where: {id: {'>': 1}}}, $scope, 'groups');
$scope.$watch(function () { $scope.$watch(function () {
@ -601,6 +604,12 @@ angular.module('OpenSlidesApp.users.site', [
choiceYes: gettext('Is a committee'), choiceYes: gettext('Is a committee'),
choiceNo: gettext('Is not a committee'), choiceNo: gettext('Is not a committee'),
}, },
hasLastEmailSend: {
value: undefined,
displayName: gettext('Last email send'),
choiceYes: gettext('Got an email'),
choiceNo: gettext("Didn't get an email"),
},
}; };
} }
$scope.filter.propertyList = ['first_name', 'last_name', 'username', 'title', $scope.filter.propertyList = ['first_name', 'last_name', 'username', 'title',
@ -765,9 +774,54 @@ angular.module('OpenSlidesApp.users.site', [
$http.post('/rest/users/user/mass_invite_email/', { $http.post('/rest/users/user/mass_invite_email/', {
user_ids: user_ids, user_ids: user_ids,
}).then(function (success) { }).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 = { $scope.alert = {
msg: gettextCatalog.getString('Send %num% emails sucessfully.').replace('%num%', success.data.count), msg: msg,
type: 'success', type: type,
show: true, show: true,
}; };
$scope.isSelectMode = false; $scope.isSelectMode = false;

View File

@ -161,6 +161,7 @@
| filter: {is_present: filter.booleanFilters.isPresent.value} | filter: {is_present: filter.booleanFilters.isPresent.value}
| filter: {is_active: filter.booleanFilters.isActive.value} | filter: {is_active: filter.booleanFilters.isActive.value}
| filter: {is_committee: filter.booleanFilters.isCommittee.value} | filter: {is_committee: filter.booleanFilters.isCommittee.value}
| filter: {has_last_email_send: filter.booleanFilters.hasLastEmailSend.value}
| MultiselectFilter: filter.multiselectFilters.group : getItemId.group | MultiselectFilter: filter.multiselectFilters.group : getItemId.group
| orderByEmptyLast: sort.column: sort.reverse)"></span> | orderByEmptyLast: sort.column: sort.reverse)"></span>
</div> </div>

View File

@ -195,16 +195,22 @@ class UserViewSet(ModelViewSet):
raise ValidationError({'detail': '{}: {}'.format(e.errno, e.strerror)}) raise ValidationError({'detail': '{}: {}'.format(e.errno, e.strerror)})
success_users = [] success_users = []
user_pks_without_email = []
try: try:
for user in users: for user in users:
if user.email:
if user.send_invitation_email(connection, skip_autoupdate=True): if user.send_invitation_email(connection, skip_autoupdate=True):
success_users.append(user) success_users.append(user)
else:
user_pks_without_email.append(user.pk)
except DjangoValidationError as e: except DjangoValidationError as e:
raise ValidationError(e.message_dict) raise ValidationError(e.message_dict)
connection.close() connection.close()
inform_changed_data(success_users) inform_changed_data(success_users)
return Response({'count': len(success_users)}) return Response({
'count': len(success_users),
'no_email_ids': user_pks_without_email})
class GroupViewSetMetadata(SimpleMetadata): class GroupViewSetMetadata(SimpleMetadata):