-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api, cloud): send a registration email to member if not found
In cloud instances, when adding a user to a namespace, if the target user does not exist, a "placeholder" with only the email address will be created. This placeholder will have a status of `not-registered` and will be added as a `pending` member in the namespace. The service will send a registration email, and once the user completes the registration, they can accept the invitation.
- Loading branch information
Showing
3 changed files
with
138 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1297,7 +1297,7 @@ func TestAddNamespaceMember(t *testing.T) { | |
}, | ||
}, | ||
{ | ||
description: "fails when passive member was not found", | ||
description: "fails when cannot retrieve the member", | ||
req: &requests.NamespaceAddMember{ | ||
FowardedHost: "localhost", | ||
UserID: "000000000000000000000000", | ||
|
@@ -1338,6 +1338,52 @@ func TestAddNamespaceMember(t *testing.T) { | |
err: NewErrUserNotFound("[email protected]", errors.New("error")), | ||
}, | ||
}, | ||
{ | ||
description: "fails when passive member was not found and is not cloud", | ||
req: &requests.NamespaceAddMember{ | ||
FowardedHost: "localhost", | ||
UserID: "000000000000000000000000", | ||
TenantID: "00000000-0000-4000-0000-000000000000", | ||
MemberEmail: "[email protected]", | ||
MemberRole: authorizer.RoleObserver, | ||
}, | ||
requiredMocks: func(ctx context.Context) { | ||
storeMock. | ||
On("NamespaceGet", ctx, "00000000-0000-4000-0000-000000000000", true). | ||
Return(&models.Namespace{ | ||
TenantID: "00000000-0000-4000-0000-000000000000", | ||
Name: "namespace", | ||
Owner: "000000000000000000000000", | ||
Members: []models.Member{ | ||
{ | ||
ID: "000000000000000000000000", | ||
Role: authorizer.RoleOwner, | ||
Status: models.MemberStatusAccepted, | ||
}, | ||
}, | ||
}, nil). | ||
Once() | ||
storeMock. | ||
On("UserGetByID", ctx, "000000000000000000000000", false). | ||
Return(&models.User{ | ||
ID: "000000000000000000000000", | ||
UserData: models.UserData{Username: "jane_doe"}, | ||
}, 0, nil). | ||
Once() | ||
storeMock. | ||
On("UserGetByEmail", ctx, "[email protected]"). | ||
Return(nil, store.ErrNoDocuments). | ||
Once() | ||
envMock. | ||
On("Get", "SHELLHUB_CLOUD"). | ||
Return("false"). | ||
Once() | ||
}, | ||
expected: Expected{ | ||
namespace: nil, | ||
err: NewErrUserNotFound("[email protected]", store.ErrNoDocuments), | ||
}, | ||
}, | ||
{ | ||
description: "fails when cannot add the member", | ||
req: &requests.NamespaceAddMember{ | ||
|
@@ -1530,6 +1576,64 @@ func TestAddNamespaceMember(t *testing.T) { | |
err: errors.New("error"), | ||
}, | ||
}, | ||
{ | ||
description: "succeeds to create the member when not found", | ||
req: &requests.NamespaceAddMember{ | ||
FowardedHost: "localhost", | ||
UserID: "000000000000000000000000", | ||
TenantID: "00000000-0000-4000-0000-000000000000", | ||
MemberEmail: "[email protected]", | ||
MemberRole: authorizer.RoleObserver, | ||
}, | ||
requiredMocks: func(ctx context.Context) { | ||
storeMock. | ||
On("NamespaceGet", ctx, "00000000-0000-4000-0000-000000000000", true). | ||
Return(&models.Namespace{ | ||
TenantID: "00000000-0000-4000-0000-000000000000", | ||
Name: "namespace", | ||
Owner: "000000000000000000000000", | ||
Members: []models.Member{ | ||
{ | ||
ID: "000000000000000000000000", | ||
Role: authorizer.RoleOwner, | ||
Status: models.MemberStatusAccepted, | ||
}, | ||
}, | ||
}, nil). | ||
Once() | ||
storeMock. | ||
On("UserGetByID", ctx, "000000000000000000000000", false). | ||
Return(&models.User{ | ||
ID: "000000000000000000000000", | ||
UserData: models.UserData{Username: "jane_doe"}, | ||
}, 0, nil). | ||
Once() | ||
storeMock. | ||
On("UserGetByEmail", ctx, "[email protected]"). | ||
Return(&models.User{ID: "000000000000000000000001"}, store.ErrNoDocuments). | ||
Once() | ||
envMock. | ||
On("Get", "SHELLHUB_CLOUD"). | ||
Return("true"). | ||
Once() | ||
storeMock. | ||
On("UserCreate", ctx, &models.User{Status: models.UserStatusNotRegistered, UserData: models.UserData{Email: "[email protected]"}}). | ||
Return("000000000000000000000001", nil). | ||
Once() | ||
envMock. | ||
On("Get", "SHELLHUB_CLOUD"). | ||
Return("true"). | ||
Once() | ||
clientMock. | ||
On("InviteMember", ctx, "00000000-0000-4000-0000-000000000000", "000000000000000000000001", "localhost"). | ||
Return(errors.New("error")). | ||
Once() | ||
}, | ||
expected: Expected{ | ||
namespace: nil, | ||
err: errors.New("error"), | ||
}, | ||
}, | ||
{ | ||
description: "succeeds when the instance is cloud", | ||
req: &requests.NamespaceAddMember{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters