Rename people.add_in_realm to people.add().

We had this API:

    people.add_in_realm = full-fledged user
    people.add = not necessarily in realm

Now the API is this:

    people.add = full-fledged user
    people._add_user = internal API for cross-realm bots
        and deactivated users

I think in most of our tests the distinction between
people.add() and people.add_in_realm() was just an
accident of history and didn't reflect any real intention.

And if I had to guess the intention in 99% of the cases,
folks probably thought they were just creating ordinary,
active users in the current realm.

In places where the distinction was obviously important
(because a test failed), I deactivated the user via
`people.deactivate`.

For the 'basics' test in the people test suite, I clean
up the test setup for Isaac.  Before this commit I was
adding him first as a non-realm user then as a full-fledged
user, but this was contrived and confusing, and we
didn't really need it for test coverage purposes.
This commit is contained in:
Steve Howell
2020-03-21 19:19:30 +00:00
committed by Tim Abbott
parent 25d2e2e122
commit f0c99b42ec
23 changed files with 110 additions and 102 deletions

View File

@@ -981,7 +981,12 @@ exports.get_mention_syntax = function (full_name, user_id, silent) {
return mention;
};
exports.add = function add(person) {
exports._add_user = function add(person) {
/*
This is common code to add any user, even
users who may be deactivated or outside
our realm (like cross-realm bots).
*/
if (person.user_id) {
people_by_user_id_dict.set(person.user_id, person);
} else {
@@ -999,9 +1004,9 @@ exports.add = function add(person) {
people_by_name_dict.set(person.full_name, person);
};
exports.add_in_realm = function (person) {
exports.add = function (person) {
active_user_dict.set(person.user_id, person);
exports.add(person);
exports._add_user(person);
};
exports.deactivate = function (person) {
@@ -1056,7 +1061,7 @@ exports.extract_people_from_message = function (message) {
exports.report_late_add(user_id, person.email);
exports.add({
exports._add_user({
email: person.email,
user_id: user_id,
full_name: person.full_name,
@@ -1190,16 +1195,16 @@ exports.is_my_user_id = function (user_id) {
exports.initialize = function (my_user_id, params) {
for (const person of params.realm_users) {
exports.add_in_realm(person);
exports.add(person);
}
for (const person of params.realm_non_active_users) {
exports.add(person);
exports._add_user(person);
}
for (const person of params.cross_realm_bots) {
if (!people_dict.has(person.email)) {
exports.add(person);
exports._add_user(person);
}
cross_realm_dict.set(person.user_id, person);
}

View File

@@ -250,7 +250,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
case 'realm_user':
if (event.op === 'add') {
people.add_in_realm(event.person);
people.add(event.person);
} else if (event.op === 'remove') {
people.deactivate(event.person);
stream_events.remove_deactivated_user_from_all_streams(event.person.user_id);