Skip to content

Commit

Permalink
api [nfc]: Mark all never-updated User fields final
Browse files Browse the repository at this point in the history
This was prompted by noticing recently that we weren't updating
[User.isActive]:
  #816 (comment)

After fixing that, I looked and found there were actually three
other fields on User which we weren't updating -- a latent bug,
since we never looked at those fields, but a bug.  Fixed that in
the preceding commit.

Now the remaining fields that don't get updated are fields that
really are immutable on a Zulip user.  Mark those as final, and
add a comment to help maintain the pattern.
  • Loading branch information
gnprice committed Aug 11, 2024
1 parent 241f6d7 commit 429fa9e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/api/model/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,25 @@ enum Emojiset {
/// in <https://zulip.com/api/register-queue>.
@JsonSerializable(fieldRename: FieldRename.snake)
class User {
// When adding a field to this class:
// * If a [RealmUserUpdateEvent] can update it, be sure to add
// that case to [RealmUserUpdateEvent] and its handler.
// * If the field can never change for a given Zulip user, mark it final.
// * (If it can change but [RealmUserUpdateEvent] doesn't cover that,
// then that's a bug in the API; raise it in `#api design`.)

final int userId;
String? deliveryEmail;
String email;
String fullName;
String dateJoined;
final String dateJoined;
bool isActive; // Really sometimes absent in /register, but we normalize that away; see [InitialSnapshot.realmUsers].
// bool isOwner; // obsoleted by [role]; ignore
// bool isAdmin; // obsoleted by [role]; ignore
// bool isGuest; // obsoleted by [role]; ignore
bool? isBillingAdmin; // TODO(server-5)
bool isBot;
int? botType; // TODO enum
final bool isBot;
final int? botType; // TODO enum
int? botOwnerId;
@JsonKey(unknownEnumValue: UserRole.unknown)
UserRole role;
Expand All @@ -214,7 +221,7 @@ class User {
Map<int, ProfileFieldUserData>? profileData;

@JsonKey(readValue: _readIsSystemBot)
bool isSystemBot;
final bool isSystemBot;

static Map<String, dynamic>? _readProfileData(Map<dynamic, dynamic> json, String key) {
final value = (json[key] as Map<String, dynamic>?);
Expand Down

0 comments on commit 429fa9e

Please sign in to comment.