Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api types: Sync User and CrossRealmBot types with the doc, as of FL 121 #5351

Merged
merged 14 commits into from
Apr 27, 2022

Conversation

chrisbobbe
Copy link
Contributor

@chrisbobbe chrisbobbe commented Apr 20, 2022

After #5349, on the path to fixing #5250.

Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Comments below.

Comment on lines 93 to -128
// For background on the "*bot*" fields, see user docs on bots:
// https://zulip.com/help/add-a-bot-or-integration
// Note that certain bots are represented by a different type entirely,
// namely `CrossRealmBot`.
is_bot: boolean,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Let's keep this comment next to one of the fields it's about, to increase the chance that it's noticed when it's relevant. Perhaps is_bot -- that seems like the one where you're most likely to be looking and be in need of the context that CrossRealmBot is over there.

Comment on lines -128 to -130
is_bot: boolean,
bot_type?: number,
bot_owner?: string,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sure is awkward that these three get scattered from each other. :-/ Also that user_id is in a random place in the middle instead of at the top, and that is_guest is nowhere near is_admin and is_owner.

I think the reordering is worth the trade-off in order to make it more tractable to bring the type up to date, but it's a shame that it actually gets harder to read.

Perhaps first reorder the API docs to match the more logical order that's in models.py and in this type? Then we don't have to regress on that.

Copy link
Contributor Author

@chrisbobbe chrisbobbe Apr 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replied with a proposed ordering in chat.

Copy link
Contributor Author

@chrisbobbe chrisbobbe Apr 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sent zulip/zulip#21883; I guess I'll await that and apply the result to my next revision.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my next revision, I'd appreciate the time saved by applying the new order on top of the existing commits in the branch, rather than having an early commit that takes the new ordering then resolve all the merge conflicts that'd create.

Copy link
Contributor Author

@chrisbobbe chrisbobbe Apr 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I've actually gone ahead and done it the proper way for my next revision. 🙂)

// (This one doesn't appear in `/users` responses.)
profile_data?: empty, // When we need this, describe its actual type.
// If we use this, avoid `avatar_url` falling out of sync with it.
-avatar_version: number,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

api types: Add write-only `avatar_version` to User type

This doesn't end up having that effect, because the object type is wrapped in $ReadOnly<…>.

In order to make it possible to start marking properties as write-only, you can have a prep commit replace the $ReadOnly with a + on each individual property. For an example: f551158

// TODO(server-3.0): Replaced in FL 1 by bot_owner_id
bot_owner?: string,

is_active: boolean,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

api types: Add `is_active` to User type

The doc says it is present in `realm_users` and
`realm_non_active_users`; trust that.

Huh. It seems to actually contradict itself on that:

realm_non_active_users: (object)[]

Present if realm_user is present in fetch_event_types.

A array of dictionaries where each entry describes a user whose account has been deactivated. Note that unlike the usual User dictionary this does not contain the is_active key as all the users present in this array have deactivated accounts.

even though it then goes on to list is_active in the actual list of properties for those objects.

Same for realm_users.

Copy link
Contributor Author

@chrisbobbe chrisbobbe Apr 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I'll bring it up in #api documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 132 to 137
// `null` if the user isn't a bot.
// `1` for a `Generic` bot.
// `2` for an `Incoming webhook` bot.
// `3` for an `Outgoing webhook` bot.
// `4` for an `Embedded` bot.
bot_type: number | null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to leave this comment out, I think, in favor of deferring to the API docs.

Comment on lines 124 to 130
// Possible values are:
// Organization owner => 100
// Organization administrator => 200
// Organization moderator => 300
// Member => 400
// Guest => 600
role?: number,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In principle I'd say the same thing about this as about bot_type: leave these details to just be in the API docs. But maybe the role is an important enough property to make an exception.

Copy link
Contributor Author

@chrisbobbe chrisbobbe Apr 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably fine to leave these details out. The comment doesn't reveal anything surprising or counterintuitive, and it seems like the kind of thing where the API doc might change. (For example, to add new roles, or to stop using => where : would do fine and not get confused with .) And then if it changes, we don't have to go and make a change in our code comment.

@chrisbobbe chrisbobbe force-pushed the pr-user-cross-realm-bot-sync branch from 8209de1 to 7b56564 Compare April 27, 2022 01:09
@chrisbobbe
Copy link
Contributor Author

Thanks for the review! Revision pushed.

@chrisbobbe chrisbobbe force-pushed the pr-user-cross-realm-bot-sync branch from 7b56564 to a1cc583 Compare April 27, 2022 01:16
…n doc

Following the recent reordering applied to the doc in
  zulip/zulip#21918 .
This makes it easy to mark deprecated properties write-only.
The other two properties in the comment don't appear in `realm_user`
items in the /register response, according to the doc. So, stop
mentioning them. (They do appear at toplevel in the /register
response, if `realm_user` is present in `fetch_event_types`; there,
they presumably apply to the logged-in user.)
As the comment says, some ancient servers don't send this. But we
don't support those ancient servers; so, no need to make the
property optional.
This makes it easy to mark deprecated properties write-only.
These tighter types aren't made explicit in the doc (perhaps they
should be), but they're inferrable from how cross-realm bots work.
@gnprice
Copy link
Member

gnprice commented Apr 27, 2022

Thanks for the revision! Looks good -- merging.

@gnprice gnprice force-pushed the pr-user-cross-realm-bot-sync branch from a1cc583 to 900a007 Compare April 27, 2022 21:44
@gnprice gnprice merged commit 900a007 into zulip:main Apr 27, 2022
@chrisbobbe chrisbobbe deleted the pr-user-cross-realm-bot-sync branch April 27, 2022 21:45
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this pull request May 11, 2022
As Greg pointed out in zulip#5351, at
  zulip#5351 (comment) :

> [The write-only marker] doesn't end up having that effect, because
> the object type is wrapped in $ReadOnly<…>.
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this pull request May 13, 2022
As Greg pointed out in zulip#5351, at
  zulip#5351 (comment) :

> [The write-only marker] doesn't end up having that effect, because
> the object type is wrapped in $ReadOnly<…>.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants