Change people.remove() to people.deactivate() and fix bug.

This commit changes people.remove() to be people.deactivate(),
and it fixes a bug where deactivating users was causing tracebacks
in the PM list if somebody had PM'ed the deactivated user
recently.
This commit is contained in:
Steve Howell 2016-12-15 13:44:42 -08:00 committed by Tim Abbott
parent b2bb2f8ea0
commit b46d7654f8
4 changed files with 19 additions and 14 deletions

View File

@ -583,7 +583,7 @@ run(function (override, capture, args) {
assert_same(args.person, event.person);
event = event_fixtures.realm_user__remove;
override('people', 'remove', capture(['person']));
override('people', 'deactivate', capture(['person']));
dispatch(event);
assert_same(args.person, event.person);

View File

@ -77,11 +77,15 @@ var _ = global._;
people.update({email: email, full_name: 'The Godfather of Calculus'});
assert.equal(global.page_params.fullname, 'The Godfather of Calculus');
// Now remove isaac
people.remove(isaac);
person = people.get_by_email(email);
// Now deactivate isaac
people.deactivate(isaac);
person = people.realm_get(email);
assert(!person);
// We can still get their info for non-realm needs.
person = people.get_by_email(email);
assert.equal(person.email, email);
// The original person should still be there
person = people.get_by_email('orig@example.com');
assert.equal(person.full_name, 'Original');
@ -113,13 +117,14 @@ var _ = global._;
person = people.get_person_from_user_id(42);
assert.equal(person.full_name, 'Mary New');
// remove() should eventually just take a user_id, but
// now it takes a full person object
people.remove(person);
person = people.get_by_email('mary@example.com');
// deactivate() should eventually just take a user_id, but
// now it takes a full person object. Note that deactivate()
// won't actually make the user disappear completely.
people.deactivate(person);
person = people.realm_get('mary@example.com');
assert.equal(person, undefined);
person = people.get_person_from_user_id(42);
assert.equal(person, undefined);
assert.equal(person.user_id, 42);
}());
(function test_get_rest_of_realm() {

View File

@ -226,10 +226,10 @@ exports.add_in_realm = function add_in_realm(person) {
exports.add(person);
};
exports.remove = function remove(person) {
people_dict.del(person.email);
people_by_user_id_dict.del(person.user_id);
people_by_name_dict.del(person.full_name);
exports.deactivate = function (person) {
// We don't fully remove a person from all of our data
// structures, because deactivated users can be part
// of somebody's PM list.
realm_people_dict.del(person.email);
};

View File

@ -101,7 +101,7 @@ function dispatch_normal_event(event) {
if (event.op === 'add') {
people.add_in_realm(event.person);
} else if (event.op === 'remove') {
people.remove(event.person);
people.deactivate(event.person);
} else if (event.op === 'update') {
people.update(event.person);
admin.update_user_full_name(event.person.email, event.person.full_name);