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

feat(mgmt): refactor APIs for Get and Patch authenticated user #261

Merged
merged 4 commits into from
Feb 5, 2024
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
81 changes: 69 additions & 12 deletions core/mgmt/v1beta/mgmt.proto
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,22 @@ enum MembershipState {
MEMBERSHIP_STATE_PENDING = 2;
}

// User describes an individual that interacts with Instill AI.
message User {
option (google.api.resource) = {
type: "api.instill.tech/User"
pattern: "users/{user.id}"
pattern: "users/{user.uid}"
};
// OnboardingStatus describes the status of the user onboarding process.
enum OnboardingStatus {
// Unspecified.
ONBOARDING_STATUS_UNSPECIFIED = 0;
// In progress, i.e., the user has initiated the onboarding process
// but has not yet completed it.
ONBOARDING_STATUS_IN_PROGRESS = 1;
// Completed.
ONBOARDING_STATUS_COMPLETED = 2;
}

// AuthenticatedUser contains the information of an authenticated user, i.e.,
// the public user information plus some fields that should only be accessed by
// the user themselves.
message AuthenticatedUser {
option (google.api.resource) = {type: "api.instill.tech/AuthenticatedUser"};

// The name of the user, defined by its ID.
// - Format: `users/{user.id}`.
Expand Down Expand Up @@ -105,7 +114,7 @@ message User {
// Last name.
optional string last_name = 10 [(google.api.field_behavior) = OPTIONAL];
// Company or institution name.
optional string org_name = 11 [(google.api.field_behavior) = OPTIONAL];
optional string company_name = 11 [(google.api.field_behavior) = OPTIONAL];
// Role.
//
// It must be one of the following allowed roles:
Expand All @@ -119,12 +128,50 @@ message User {
optional string role = 12 [(google.api.field_behavior) = OPTIONAL];
// This defines whether the user is subscribed to Instill AI's newsletter.
bool newsletter_subscription = 13 [(google.api.field_behavior) = REQUIRED];
// Console cookie token.
optional string cookie_token = 14 [(google.api.field_behavior) = OPTIONAL];
// Profile Avatar in base64.
optional string profile_avatar = 15 [(google.api.field_behavior) = OPTIONAL];
// Profile Data.
optional google.protobuf.Struct profile_data = 16 [(google.api.field_behavior) = OPTIONAL];
// Onboarding Status.
OnboardingStatus onboarding_status = 17 [(google.api.field_behavior) = OPTIONAL];
}

// User describes an individual that interacts with Instill AI. It doesn't
// contain any private information about the user.
message User {
jvallesm marked this conversation as resolved.
Show resolved Hide resolved
option (google.api.resource) = {
type: "api.instill.tech/User"
pattern: "users/{user.id}"
pattern: "users/{user.uid}"
};

// The name of the user, defined by its ID.
// - Format: `users/{user.id}`.
string name = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
// User UUID. This field is optionally set by users on creation (it will be
// server-generated if unspecified).
optional string uid = 2 [(google.api.field_behavior) = IMMUTABLE];
// Resource ID (used in `name` as the last segment). This conforms to
// RFC-1034, which restricts to letters, numbers, and hyphen, with the first
// character a letter, the last a letter or a number, and a 63 character
// maximum.
//
// Note that the ID can be updated.
string id = 3 [(google.api.field_behavior) = REQUIRED];
// Creation time.
google.protobuf.Timestamp create_time = 4 [(google.api.field_behavior) = OUTPUT_ONLY];
// Update time.
google.protobuf.Timestamp update_time = 5 [(google.api.field_behavior) = OUTPUT_ONLY];
// Stripe customer ID. This field is used in Instill Cloud.
string customer_id = 6 [(google.api.field_behavior) = OUTPUT_ONLY];
jvallesm marked this conversation as resolved.
Show resolved Hide resolved
// First name.
optional string first_name = 7 [(google.api.field_behavior) = OPTIONAL];
// Last name.
optional string last_name = 8 [(google.api.field_behavior) = OPTIONAL];
// Profile Avatar in base64.
optional string profile_avatar = 9 [(google.api.field_behavior) = OPTIONAL];
// Profile Data.
optional google.protobuf.Struct profile_data = 10 [(google.api.field_behavior) = OPTIONAL];
}

// ListUsersAdminRequest represents a request to list all users by admin
Expand Down Expand Up @@ -300,11 +347,21 @@ message GetUserResponse {
User user = 1;
}

// GetAuthenticatedUserRequest represents a request to get the
// authenticated user.
message GetAuthenticatedUserRequest {}

// GetAuthenticatedUserResponse contains the requested authenticated user.
message GetAuthenticatedUserResponse {
// The authenticated user resource.
AuthenticatedUser user = 1;
}

// PatchAuthenticatedUserRequest represents a request to update the
// authenticated user.
message PatchAuthenticatedUserRequest {
// The user fields that will replace the existing ones.
User user = 1;
AuthenticatedUser user = 1;
// The update mask specifies the subset of fields that should be modified.
//
// For more information about this field, see
Expand All @@ -316,7 +373,7 @@ message PatchAuthenticatedUserRequest {
// the authenticated user resource
message PatchAuthenticatedUserResponse {
// The updated user resource.
User user = 1;
AuthenticatedUser user = 1;
}

// CheckNamespaceRequest represents a request to verify if a namespace is
Expand Down
37 changes: 22 additions & 15 deletions core/mgmt/v1beta/mgmt_public_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,28 @@ service MgmtPublicService {
option (google.api.method_visibility).restriction = "INTERNAL";
}

// Get the authenticated user
//
// Returns the details of the authenticated user.
rpc GetAuthenticatedUser(GetAuthenticatedUserRequest) returns (GetAuthenticatedUserResponse) {
option (google.api.http) = {get: "/v1beta/user"};
jvallesm marked this conversation as resolved.
Show resolved Hide resolved
option (google.api.method_signature) = "user,update_mask";
}

// Update the authenticated user
//
// Updates the information of the authenticated user.
//
// In REST requests, only the supplied user fields will be taken into account
// when updating the resource.
rpc PatchAuthenticatedUser(PatchAuthenticatedUserRequest) returns (PatchAuthenticatedUserResponse) {
option (google.api.http) = {
patch: "/v1beta/user"
jvallesm marked this conversation as resolved.
Show resolved Hide resolved
body: "user"
};
option (google.api.method_signature) = "user,update_mask";
}

// List users
//
// Returns a paginated list of users.
Expand All @@ -80,21 +102,6 @@ service MgmtPublicService {
option (google.api.method_visibility).restriction = "INTERNAL";
}

// Update a user
//
// Accesses and updates a user by ID. The authenticated user must match the
// target in order to modify it.
//
// In REST requests, only the supplied user fields will be taken into account
// when updating the resource.
rpc PatchAuthenticatedUser(PatchAuthenticatedUserRequest) returns (PatchAuthenticatedUserResponse) {
option (google.api.http) = {
patch: "/v1beta/users/me"
body: "user"
};
option (google.api.method_signature) = "user,update_mask";
}

// List user memberships
//
// Returns the memberships of a user.
Expand Down
Loading