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); assert_same(args.person, event.person);
event = event_fixtures.realm_user__remove; event = event_fixtures.realm_user__remove;
override('people', 'remove', capture(['person'])); override('people', 'deactivate', capture(['person']));
dispatch(event); dispatch(event);
assert_same(args.person, event.person); assert_same(args.person, event.person);

View File

@ -77,11 +77,15 @@ var _ = global._;
people.update({email: email, full_name: 'The Godfather of Calculus'}); people.update({email: email, full_name: 'The Godfather of Calculus'});
assert.equal(global.page_params.fullname, 'The Godfather of Calculus'); assert.equal(global.page_params.fullname, 'The Godfather of Calculus');
// Now remove isaac // Now deactivate isaac
people.remove(isaac); people.deactivate(isaac);
person = people.get_by_email(email); person = people.realm_get(email);
assert(!person); 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 // The original person should still be there
person = people.get_by_email('orig@example.com'); person = people.get_by_email('orig@example.com');
assert.equal(person.full_name, 'Original'); assert.equal(person.full_name, 'Original');
@ -113,13 +117,14 @@ var _ = global._;
person = people.get_person_from_user_id(42); person = people.get_person_from_user_id(42);
assert.equal(person.full_name, 'Mary New'); assert.equal(person.full_name, 'Mary New');
// remove() should eventually just take a user_id, but // deactivate() should eventually just take a user_id, but
// now it takes a full person object // now it takes a full person object. Note that deactivate()
people.remove(person); // won't actually make the user disappear completely.
person = people.get_by_email('mary@example.com'); people.deactivate(person);
person = people.realm_get('mary@example.com');
assert.equal(person, undefined); assert.equal(person, undefined);
person = people.get_person_from_user_id(42); person = people.get_person_from_user_id(42);
assert.equal(person, undefined); assert.equal(person.user_id, 42);
}()); }());
(function test_get_rest_of_realm() { (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.add(person);
}; };
exports.remove = function remove(person) { exports.deactivate = function (person) {
people_dict.del(person.email); // We don't fully remove a person from all of our data
people_by_user_id_dict.del(person.user_id); // structures, because deactivated users can be part
people_by_name_dict.del(person.full_name); // of somebody's PM list.
realm_people_dict.del(person.email); realm_people_dict.del(person.email);
}; };

View File

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