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

chore(shorebird_code_push_protocol): add CreateUserRequest message #321

Merged
merged 3 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'create_user_request.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart';

part 'create_user_request.g.dart';

/// {@template create_user_request}
/// The request body for POST /api/v1/users, which creates a new User.
///
/// Email is retrieved from the user's auth token.
Copy link
Contributor

@felangel felangel Apr 19, 2023

Choose a reason for hiding this comment

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

Seems a bit weird to require an access token for user creation imo. I would have expected the endpoint would be open and we'd provide email and display name explicitly in the request body.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I originally had designed it that way and then realized I could (potentially maliciously) create accounts for anyone I wanted to. This approach adds some level of verification that the person creating the user is who they say they are, although it will probably need to be tweaked a bit if/when we expand our auth offerings.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I see makes sense to do that for now since that's simpler/safer. We can change it in the future 👍

/// {@endtemplate}
@JsonSerializable()
class CreateUserRequest {
/// {@macro create_user_request}
const CreateUserRequest({
required this.name,
});

/// Converts a JSON object to a [CreateUserRequest].
factory CreateUserRequest.fromJson(Json json) =>
_$CreateUserRequestFromJson(json);

/// Converts a [CreateUserRequest] to a JSON object.
Json toJson() => _$CreateUserRequestToJson(this);

/// The new user's display name.
final String name;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export 'create_patch/create_patch.dart';
export 'create_payment_link/create_payment_link.dart';
export 'create_release/create_release.dart';
export 'create_release_artifact/create_release_artifact.dart';
export 'create_user/create_user.dart';
export 'promote_patch/promote_patch.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class User {
required this.id,
required this.email,
this.hasActiveSubscription = false,
this.displayName,
});

/// Converts a Map<String, dynamic> to a [User]
Expand All @@ -26,6 +27,9 @@ class User {
/// The user's email address, as provided by the user during signup.
final String email;

/// The user's name, as provided by the user during signup.
final String? displayName;

/// Whether the user is currently a paying customer.
final bool hasActiveSubscription;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart';
import 'package:test/test.dart';

void main() {
group(CreateUserRequest, () {
test('can be (de)serialized', () {
const request = CreateUserRequest(name: 'Joe Tester');
expect(
CreateUserRequest.fromJson(request.toJson()).toJson(),
equals(request.toJson()),
);
});
});
}