Merge pull request #4317 from samhax/delete-user-invites

Delete user invites from APM
v1.18.x
Barış Soner Uşaklı 9 years ago
commit 3d55eec885

@ -8,7 +8,6 @@ define('admin/manage/registration', function() {
Registration.init = function() { Registration.init = function() {
$('.users-list').on('click', '[data-action]', function(ev) { $('.users-list').on('click', '[data-action]', function(ev) {
var $this = this;
var parent = $(this).parents('[data-username]'); var parent = $(this).parents('[data-username]');
var action = $(this).attr('data-action'); var action = $(this).attr('data-action');
var username = parent.attr('data-username'); var username = parent.attr('data-username');
@ -22,6 +21,37 @@ define('admin/manage/registration', function() {
}); });
return false; return false;
}); });
$('.invites-list').on('click', '[data-action]', function(ev) {
var parent = $(this).parents('[data-invitation-mail][data-invited-by]');
var email = parent.attr('data-invitation-mail');
var invitedBy = parent.attr('data-invited-by');
var action = $(this).attr('data-action');
var method = 'admin.user.deleteInvitation';
var removeRow = function () {
var nextRow = parent.next(),
thisRowinvitedBy = parent.find('.invited-by'),
nextRowInvitedBy = nextRow.find('.invited-by');
if (nextRowInvitedBy.html() !== undefined && nextRowInvitedBy.html().length < 2) {
nextRowInvitedBy.html(thisRowinvitedBy.html());
}
parent.remove();
};
if (action === 'delete') {
bootbox.confirm('Are you sure you wish to delete this invitation?', function(confirm) {
if (confirm) {
socket.emit(method, {email: email, invitedBy: invitedBy}, function(err) {
if (err) {
return app.alertError(err.message);
}
removeRow();
});
}
});
}
return false;
});
}; };
return Registration; return Registration;

@ -93,7 +93,7 @@ function registerAndLoginUser(req, res, userData, callback) {
} }
}, },
function(next) { function(next) {
user.deleteInvitation(userData.email); user.deleteInvitationKey(userData.email);
plugins.fireHook('filter:register.complete', {uid: uid, referrer: req.body.referrer || nconf.get('relative_path') + '/'}, next); plugins.fireHook('filter:register.complete', {uid: uid, referrer: req.body.referrer || nconf.get('relative_path') + '/'}, next);
} }
], callback); ], callback);

@ -212,6 +212,10 @@ User.search = function(socket, data, callback) {
}); });
}; };
User.deleteInvitation = function(socket, data, callback) {
user.deleteInvitation(data.invitedBy, data.email, callback);
};
User.acceptRegistration = function(socket, data, callback) { User.acceptRegistration = function(socket, data, callback) {
user.acceptRegistration(data.username, callback); user.acceptRegistration(data.username, callback);
}; };

@ -39,7 +39,6 @@ var async = require('async'),
if (err || userData.status === 'offline' || now - parseInt(userData.lastonline, 10) < 300000) { if (err || userData.status === 'offline' || now - parseInt(userData.lastonline, 10) < 300000) {
return callback(err); return callback(err);
} }
User.setUserField(uid, 'lastonline', now, callback); User.setUserField(uid, 'lastonline', now, callback);
}); });
}; };
@ -257,4 +256,3 @@ var async = require('async'),
}(exports)); }(exports));

@ -120,7 +120,31 @@ module.exports = function(User) {
], callback); ], callback);
}; };
User.deleteInvitation = function(email, callback) { User.deleteInvitation = function(invitedBy, email, callback) {
callback = callback || function() {};
async.waterfall([
function getInvitedByUid(next) {
User.getUidByUsername(invitedBy, next);
},
function deleteRegistries(invitedByUid, next) {
if (!invitedByUid) {
return next(new Error('[[error:invalid-username]]'));
}
async.parallel([
function deleteFromReferenceList(next) {
db.setRemove('invitation:uid:' + invitedByUid, email, next);
},
function deleteInviteKey(next) {
db.delete('invitation:email:' + email, callback);
}
], function(err) {
next(err)
});
}
], callback);
};
User.deleteInvitationKey = function(email, callback) {
callback = callback || function() {}; callback = callback || function() {};
db.delete('invitation:email:' + email, callback); db.delete('invitation:email:' + email, callback);
}; };

@ -66,18 +66,23 @@
<br><br> <br><br>
The username will be displayed to the right of the emails for users who have redeemed their invitations. The username will be displayed to the right of the emails for users who have redeemed their invitations.
</p> </p>
<table class="table table-striped users-list"> <table class="table table-striped invites-list">
<tr> <tr>
<th>Inviter Username</th> <th>Inviter Username</th>
<th>Invitee Email</th> <th>Invitee Email</th>
<th>Invitee Username (if registered)</th> <th>Invitee Username (if registered)</th>
</tr> </tr>
<!-- BEGIN invites --> <!-- BEGIN invites -->
<tr> <!-- BEGIN invites.invitations -->
<!-- BEGIN invites.invitations --> <tr data-invitation-mail="{invites.invitations.email}"
<td><!-- IF @first -->{invites.username}<!-- ENDIF @first --></td> data-invited-by="{invites.username}">
<td class ="invited-by"><!-- IF @first -->{invites.username}<!-- ENDIF @first --></td>
<td>{invites.invitations.email}</td> <td>{invites.invitations.email}</td>
<td>{invites.invitations.username}</td> <td>{invites.invitations.username}
<div class="btn-group pull-right">
<button class="btn btn-danger btn-xs" data-action="delete"><i class="fa fa-times"></i></button>
</div>
</td>
</tr> </tr>
<!-- END invites.invitations --> <!-- END invites.invitations -->
<!-- END invites --> <!-- END invites -->

Loading…
Cancel
Save